parent
35f67d8e4f
commit
d28cc883a1
|
|
@ -26,10 +26,7 @@ type Generic struct {
|
||||||
// List returns a collection of resources.
|
// List returns a collection of resources.
|
||||||
// BOZO!! no auth check??
|
// BOZO!! no auth check??
|
||||||
func (g *Generic) List(ctx context.Context, ns string) ([]runtime.Object, error) {
|
func (g *Generic) List(ctx context.Context, ns string) ([]runtime.Object, error) {
|
||||||
labelSel, ok := ctx.Value(internal.KeyLabels).(string)
|
labelSel, _ := ctx.Value(internal.KeyLabels).(string)
|
||||||
if !ok {
|
|
||||||
log.Debug().Msgf("No label selector found in context. Listing all resources")
|
|
||||||
}
|
|
||||||
if client.IsAllNamespace(ns) {
|
if client.IsAllNamespace(ns) {
|
||||||
ns = client.AllNamespaces
|
ns = client.AllNamespaces
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/derailed/k9s/internal"
|
||||||
"github.com/derailed/k9s/internal/client"
|
"github.com/derailed/k9s/internal/client"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
batchv1 "k8s.io/api/batch/v1"
|
batchv1 "k8s.io/api/batch/v1"
|
||||||
|
|
@ -24,6 +25,32 @@ type Job struct {
|
||||||
Resource
|
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.
|
// 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, c LogChan, opts LogOptions) error {
|
||||||
o, err := j.Factory.Get(j.gvr.String(), opts.Path, true, labels.Everything())
|
o, err := j.Factory.Get(j.gvr.String(), opts.Path, true, labels.Everything())
|
||||||
|
|
|
||||||
|
|
@ -334,7 +334,9 @@ func (b *Browser) editCmd(evt *tcell.EventKey) *tcell.EventKey {
|
||||||
|
|
||||||
}
|
}
|
||||||
ns, n := client.Namespaced(path)
|
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 {
|
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()))
|
b.App().Flash().Err(fmt.Errorf("Current user can't edit resource %s", b.GVR()))
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -346,7 +348,9 @@ func (b *Browser) editCmd(evt *tcell.EventKey) *tcell.EventKey {
|
||||||
args := make([]string, 0, 10)
|
args := make([]string, 0, 10)
|
||||||
args = append(args, "edit")
|
args = append(args, "edit")
|
||||||
args = append(args, b.meta.SingularName)
|
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)}) {
|
if !runK(b.app, shellOpts{clear: true, args: append(args, n)}) {
|
||||||
b.app.Flash().Err(errors.New("Edit exec failed"))
|
b.app.Flash().Err(errors.New("Edit exec failed"))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -220,6 +220,10 @@ func (c *Container) isForwardable(path string) ([]string, bool) {
|
||||||
}
|
}
|
||||||
pp = append(pp, path+"/"+p)
|
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
|
return pp, true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue