Merge branch 'issue_807'

mine
derailed 2020-07-22 15:51:14 -06:00
commit cbac92e995
4 changed files with 38 additions and 6 deletions

View File

@ -26,10 +26,7 @@ type Generic struct {
// List returns a collection of resources.
// BOZO!! no auth check??
func (g *Generic) List(ctx context.Context, ns string) ([]runtime.Object, error) {
labelSel, ok := ctx.Value(internal.KeyLabels).(string)
if !ok {
log.Debug().Msgf("No label selector found in context. Listing all resources")
}
labelSel, _ := ctx.Value(internal.KeyLabels).(string)
if client.IsAllNamespace(ns) {
ns = client.AllNamespaces
}

View File

@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"github.com/derailed/k9s/internal"
"github.com/derailed/k9s/internal/client"
"github.com/rs/zerolog/log"
batchv1 "k8s.io/api/batch/v1"
@ -24,6 +25,32 @@ type Job struct {
Resource
}
// List returns a collection of resources.
func (j *Job) List(ctx context.Context, ns string) ([]runtime.Object, error) {
oo, err := j.Resource.List(ctx, ns)
if err != nil {
return nil, err
}
ctrl, _ := ctx.Value(internal.KeyPath).(string)
_, n := client.Namespaced(ctrl)
ll := make([]runtime.Object, 0, 10)
for _, o := range oo {
var j batchv1.Job
err = runtime.DefaultUnstructuredConverter.FromUnstructured(o.(*unstructured.Unstructured).Object, &j)
if err != nil {
return nil, errors.New("expecting Job resource")
}
for _, r := range j.ObjectMeta.OwnerReferences {
if r.Name == n {
ll = append(ll, o)
}
}
}
return ll, nil
}
// TailLogs tail logs for all pods represented by this Job.
func (j *Job) TailLogs(ctx context.Context, c LogChan, opts LogOptions) error {
o, err := j.Factory.Get(j.gvr.String(), opts.Path, true, labels.Everything())

View File

@ -336,7 +336,9 @@ func (b *Browser) editCmd(evt *tcell.EventKey) *tcell.EventKey {
}
ns, n := client.Namespaced(path)
if client.IsClusterScoped(ns) {
ns = client.AllNamespaces
}
if ok, err := b.app.Conn().CanI(ns, b.GVR().String(), []string{"patch"}); !ok || err != nil {
b.App().Flash().Err(fmt.Errorf("Current user can't edit resource %s", b.GVR()))
return nil
@ -348,7 +350,9 @@ func (b *Browser) editCmd(evt *tcell.EventKey) *tcell.EventKey {
args := make([]string, 0, 10)
args = append(args, "edit")
args = append(args, b.meta.SingularName)
args = append(args, "-n", ns)
if ns != client.AllNamespaces {
args = append(args, "-n", ns)
}
if !runK(b.app, shellOpts{clear: true, args: append(args, n)}) {
b.app.Flash().Err(errors.New("Edit exec failed"))
}

View File

@ -220,6 +220,10 @@ func (c *Container) isForwardable(path string) ([]string, bool) {
}
pp = append(pp, path+"/"+p)
}
if len(pp) == 0 {
c.App().Flash().Err(errors.New("No TCP port available on container"))
return nil, false
}
return pp, true
}