Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

K9S-HF: fix #1384 with feelings... #1388

Merged
merged 1 commit into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ PACKAGE := github.com/derailed/$(NAME)
GIT_REV ?= $(shell git rev-parse --short HEAD)
SOURCE_DATE_EPOCH ?= $(shell date +%s)
DATE ?= $(shell date -u -d @${SOURCE_DATE_EPOCH} +"%Y-%m-%dT%H:%M:%SZ")
VERSION ?= v0.25.14
VERSION ?= v0.25.15
IMG_NAME := derailed/k9s
IMAGE := ${IMG_NAME}:${VERSION}

Expand Down
27 changes: 27 additions & 0 deletions change_logs/release_v0.25.15.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<img src="https://raw.githubusercontent.com/derailed/k9s/master/assets/k9s_small.png" align="right" width="200" height="auto"/>

# Release v0.25.15

## Notes

Thank you to all that contributed with flushing out issues and enhancements for K9s! I'll try to mark some of these issues as fixed. But if you don't mind grab the latest rev and see if we're happier with some of the fixes! If you've filed an issue please help me verify and close. Your support, kindness and awesome suggestions to make K9s better are as ever very much noted and appreciated!

If you feel K9s is helping your Kubernetes journey, please consider joining our [sponsorship program](https://github.com/sponsors/derailed) and/or make some noise on social! [@kitesurfer](https://twitter.com/kitesurfer)

On Slack? Please join us [K9slackers](https://join.slack.com/t/k9sers/shared_invite/enQtOTA5MDEyNzI5MTU0LWQ1ZGI3MzliYzZhZWEyNzYxYzA3NjE0YTk1YmFmNzViZjIyNzhkZGI0MmJjYzhlNjdlMGJhYzE2ZGU1NjkyNTM)

---

## Maintenance Release!

Aye! Hot fix on the way...

---

## Resolved Issues

* [Issue #1384](https://github.com/derailed/k9s/issues/1384) Leaving Logs View Causes Crash: "panic: send on closed channel" - with feelings!

---

<img src="https://raw.githubusercontent.com/derailed/k9s/master/assets/imhotep_logo.png" width="32" height="auto"/> © 2021 Imhotep Software LLC. All materials licensed under [Apache v2.0](http://www.apache.org/licenses/LICENSE-2.0)
4 changes: 2 additions & 2 deletions internal/dao/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ func (c *Container) List(ctx context.Context, _ string) ([]runtime.Object, error
}

// TailLogs tails a given container logs.
func (c *Container) TailLogs(ctx context.Context, logChan LogChan, opts *LogOptions) error {
func (c *Container) TailLogs(ctx context.Context, opts *LogOptions) ([]LogChan, error) {
po := Pod{}
po.Init(c.Factory, client.NewGVR("v1/pods"))

return po.TailLogs(ctx, logChan, opts)
return po.TailLogs(ctx, opts)
}

// ----------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions internal/dao/dp.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,16 @@ func (d *Deployment) Restart(ctx context.Context, path string) error {
}

// TailLogs tail logs for all pods represented by this Deployment.
func (d *Deployment) TailLogs(ctx context.Context, c LogChan, opts *LogOptions) error {
func (d *Deployment) TailLogs(ctx context.Context, opts *LogOptions) ([]LogChan, error) {
dp, err := d.Load(d.Factory, opts.Path)
if err != nil {
return err
return nil, err
}
if dp.Spec.Selector == nil || len(dp.Spec.Selector.MatchLabels) == 0 {
return fmt.Errorf("No valid selector found on Deployment %s", opts.Path)
return nil, fmt.Errorf("No valid selector found on Deployment %s", opts.Path)
}

return podLogs(ctx, c, dp.Spec.Selector.MatchLabels, opts)
return podLogs(ctx, dp.Spec.Selector.MatchLabels, opts)
}

// Pod returns a pod victim by name.
Expand Down
31 changes: 18 additions & 13 deletions internal/dao/ds.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,54 +91,59 @@ func (d *DaemonSet) Restart(ctx context.Context, path string) error {
}

// TailLogs tail logs for all pods represented by this DaemonSet.
func (d *DaemonSet) TailLogs(ctx context.Context, c LogChan, opts *LogOptions) error {
func (d *DaemonSet) TailLogs(ctx context.Context, opts *LogOptions) ([]LogChan, error) {
ds, err := d.GetInstance(opts.Path)
if err != nil {
return err
return nil, err
}

if ds.Spec.Selector == nil || len(ds.Spec.Selector.MatchLabels) == 0 {
return fmt.Errorf("no valid selector found on daemonset %q", opts.Path)
return nil, fmt.Errorf("no valid selector found on daemonset %q", opts.Path)
}

return podLogs(ctx, c, ds.Spec.Selector.MatchLabels, opts)
return podLogs(ctx, ds.Spec.Selector.MatchLabels, opts)
}

func podLogs(ctx context.Context, out LogChan, sel map[string]string, opts *LogOptions) error {
func podLogs(ctx context.Context, sel map[string]string, opts *LogOptions) ([]LogChan, error) {
f, ok := ctx.Value(internal.KeyFactory).(*watch.Factory)
if !ok {
return errors.New("expecting a context factory")
return nil, errors.New("expecting a context factory")
}
ls, err := metav1.ParseToLabelSelector(toSelector(sel))
if err != nil {
return err
return nil, err
}
lsel, err := metav1.LabelSelectorAsSelector(ls)
if err != nil {
return err
return nil, err
}

ns, _ := client.Namespaced(opts.Path)
oo, err := f.List("v1/pods", ns, true, lsel)
if err != nil {
return err
return nil, err
}
opts.MultiPods = true

po := Pod{}
po.Init(f, client.NewGVR("v1/pods"))

outs := make([]LogChan, 0, len(oo))
for _, o := range oo {
u, ok := o.(*unstructured.Unstructured)
if !ok {
return fmt.Errorf("expected unstructured got %t", o)
return nil, fmt.Errorf("expected unstructured got %t", o)
}
opts = opts.Clone()
opts.Path = client.FQN(u.GetNamespace(), u.GetName())
if err := po.TailLogs(ctx, out, opts); err != nil {
return err
cc, err := po.TailLogs(ctx, opts)
if err != nil {
return nil, err
}
outs = append(outs, cc...)
}
return nil

return outs, nil
}

// Pod returns a pod victim by name.
Expand Down
10 changes: 5 additions & 5 deletions internal/dao/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,23 @@ func (j *Job) List(ctx context.Context, ns string) ([]runtime.Object, error) {
}

// TailLogs tail logs for all pods represented by this Job.
func (j *Job) TailLogs(ctx context.Context, c LogChan, opts *LogOptions) error {
func (j *Job) TailLogs(ctx context.Context, opts *LogOptions) ([]LogChan, error) {
o, err := j.Factory.Get(j.gvr.String(), opts.Path, true, labels.Everything())
if err != nil {
return err
return nil, err
}

var job batchv1.Job
err = runtime.DefaultUnstructuredConverter.FromUnstructured(o.(*unstructured.Unstructured).Object, &job)
if err != nil {
return errors.New("expecting a job resource")
return nil, errors.New("expecting a job resource")
}

if job.Spec.Selector == nil || len(job.Spec.Selector.MatchLabels) == 0 {
return fmt.Errorf("No valid selector found on Job %s", opts.Path)
return nil, fmt.Errorf("No valid selector found on Job %s", opts.Path)
}

return podLogs(ctx, c, job.Spec.Selector.MatchLabels, opts)
return podLogs(ctx, job.Spec.Selector.MatchLabels, opts)
}

// ScanSA scans for serviceaccount refs.
Expand Down
8 changes: 2 additions & 6 deletions internal/dao/log_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (o *LogOptions) Clone() *LogOptions {
DefaultContainer: o.DefaultContainer,
Lines: o.Lines,
Previous: o.Previous,
Head: o.Head,
SingleContainer: o.SingleContainer,
MultiPods: o.MultiPods,
ShowTimestamp: o.ShowTimestamp,
Expand Down Expand Up @@ -82,14 +83,9 @@ func (o *LogOptions) ToPodLogOptions() *v1.PodLogOptions {
TailLines: &o.Lines,
}
if o.Head {
var maxBytes int64 = 1000
//var defaultTail int64 = -1
//var defaultSince int64

var maxBytes int64 = 5000
opts.Follow = false
opts.TailLines, opts.SinceSeconds, opts.SinceTime = nil, nil, nil
//opts.TailLines = &defaultTail
//opts.SinceSeconds = &defaultSince
opts.LimitBytes = &maxBytes
return &opts
}
Expand Down
Loading