diff --git a/go.mod b/go.mod index 07cafefb3..fa39d9896 100644 --- a/go.mod +++ b/go.mod @@ -36,7 +36,7 @@ require ( k8s.io/klog/v2 v2.8.0 k8s.io/kube-aggregator v0.21.1 k8s.io/kubernetes v1.21.1 - kmodules.xyz/client-go v0.0.0-20210909114628-15cac6c74063 + kmodules.xyz/client-go v0.0.0-20210921150324-f005c6dfcb32 kmodules.xyz/constants v0.0.0-20210218100002-2c304bfda278 kmodules.xyz/custom-resources v0.0.0-20210829135624-c63be82e13c0 kmodules.xyz/objectstore-api v0.0.0-20210829122106-d39859fc2d56 diff --git a/go.sum b/go.sum index f1c16bbe8..66b25aef9 100644 --- a/go.sum +++ b/go.sum @@ -1220,8 +1220,9 @@ kmodules.xyz/client-go v0.0.0-20210617233340-13d22e91512b/go.mod h1:A6GAK6xP5zBu kmodules.xyz/client-go v0.0.0-20210715065708-d4f0cc74ead1/go.mod h1:E/vGngai00UtVwP8R4PWpPUBF/EZa6Ub9WS5+tVcs4M= kmodules.xyz/client-go v0.0.0-20210719120358-dd0503cf99cf/go.mod h1:E/vGngai00UtVwP8R4PWpPUBF/EZa6Ub9WS5+tVcs4M= kmodules.xyz/client-go v0.0.0-20210822203828-5e9cebbf1dfa/go.mod h1:0gkPeALtYjB27OHt4rd6+ZmMgoVTHVLtEJQeU23/gtA= -kmodules.xyz/client-go v0.0.0-20210909114628-15cac6c74063 h1:u+/fmk4N1LsxeCU7q7vnNgaADK73UeyNWKzNtjFe3Bs= kmodules.xyz/client-go v0.0.0-20210909114628-15cac6c74063/go.mod h1:0gkPeALtYjB27OHt4rd6+ZmMgoVTHVLtEJQeU23/gtA= +kmodules.xyz/client-go v0.0.0-20210921150324-f005c6dfcb32 h1:ZXVJStHHjppRoaUw5JQ5KzMjK+EiY1GkcPigPHfkvSg= +kmodules.xyz/client-go v0.0.0-20210921150324-f005c6dfcb32/go.mod h1:0gkPeALtYjB27OHt4rd6+ZmMgoVTHVLtEJQeU23/gtA= kmodules.xyz/constants v0.0.0-20210218100002-2c304bfda278 h1:sFmqh4EaiZ4K2FkkGvrDFddstq8GSf6ogH24IAsuKew= kmodules.xyz/constants v0.0.0-20210218100002-2c304bfda278/go.mod h1:DbiFk1bJ1KEO94t1SlAn7tzc+Zz95rSXgyUKa2nzPmY= kmodules.xyz/crd-schema-fuzz v0.0.0-20210618002152-fae23aef5fb4/go.mod h1:IIkUctlfoptoci0BOrsUf8ya+MOG5uaeh1PE4uzaIbA= diff --git a/vendor/kmodules.xyz/client-go/tools/exec/lib.go b/vendor/kmodules.xyz/client-go/tools/exec/lib.go index 740f9acef..c4a44ff75 100644 --- a/vendor/kmodules.xyz/client-go/tools/exec/lib.go +++ b/vendor/kmodules.xyz/client-go/tools/exec/lib.go @@ -19,6 +19,7 @@ package exec import ( "bytes" "context" + "errors" "fmt" "net/http" "strings" @@ -32,9 +33,12 @@ import ( "k8s.io/client-go/tools/remotecommand" ) +var NotRunning = errors.New("container not running") + type Options struct { core.PodExecOptions remotecommand.StreamOptions + CheckForRunningContainer bool } func Container(container string) func(*Options) { @@ -49,6 +53,12 @@ func Command(cmd ...string) func(*Options) { } } +func CheckForRunningContainer(check bool) func(*Options) { + return func(opts *Options) { + opts.CheckForRunningContainer = check + } +} + func Input(in string) func(*Options) { return func(opts *Options) { opts.PodExecOptions.Stdin = true @@ -102,6 +112,23 @@ func execIntoPod(config *rest.Config, kc kubernetes.Interface, pod *core.Pod, op option(opts) } + if opts.CheckForRunningContainer { + for _, status := range pod.Status.ContainerStatuses { + if status.Name == opts.PodExecOptions.Container { + if status.State.Running == nil { + return "", NotRunning + } + } + } + for _, status := range pod.Status.InitContainerStatuses { + if status.Name == opts.PodExecOptions.Container { + if status.State.Running == nil { + return "", NotRunning + } + } + } + } + req := kc.CoreV1().RESTClient().Post(). Resource("pods"). Name(pod.Name). @@ -115,7 +142,6 @@ func execIntoPod(config *rest.Config, kc kubernetes.Interface, pod *core.Pod, op } err = exec.Stream(opts.StreamOptions) - if err != nil { return "", fmt.Errorf("could not execute: %v", err) } @@ -123,6 +149,5 @@ func execIntoPod(config *rest.Config, kc kubernetes.Interface, pod *core.Pod, op if execErr.Len() > 0 { return "", fmt.Errorf("stderr: %v", execErr.String()) } - return execOut.String(), nil } diff --git a/vendor/kmodules.xyz/client-go/tools/queue/handler.go b/vendor/kmodules.xyz/client-go/tools/queue/handler.go index 6d5f05b68..7fb822ab5 100644 --- a/vendor/kmodules.xyz/client-go/tools/queue/handler.go +++ b/vendor/kmodules.xyz/client-go/tools/queue/handler.go @@ -32,6 +32,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/sets" + clientsetscheme "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/tools/cache" "k8s.io/client-go/util/workqueue" "k8s.io/klog/v2" @@ -189,10 +190,12 @@ func (h *QueueingEventHandler) OnAdd(obj interface{}) { return } if o.GetNamespace() != "" && o.GetNamespace() != h.restrictToNamespace { - gvk := o.GetObjectKind().GroupVersionKind() - klog. - V(logLevel(gvk.Group)). - Infof("Skipping %v %s/%s. Only %s namespace is supported for Community Edition. Please upgrade to Enterprise to use any namespace.", gvk, o.GetNamespace(), o.GetName(), h.restrictToNamespace) + // WARNING: o.GetObjectKind().GroupVersionKind() is not set and can't be used to detect GVK + if gvks, _, _ := clientsetscheme.Scheme.ObjectKinds(o); len(gvks) > 0 { + klog. + V(logLevel(gvks[0].Group)). + Infof("Skipping %v %s/%s. Only %s namespace is supported for Community Edition. Please upgrade to Enterprise to use any namespace.", gvks[0], o.GetNamespace(), o.GetName(), h.restrictToNamespace) + } return } } @@ -210,10 +213,12 @@ func (h *QueueingEventHandler) OnUpdate(oldObj, newObj interface{}) { return } if o.GetNamespace() != "" && o.GetNamespace() != h.restrictToNamespace { - gvk := o.GetObjectKind().GroupVersionKind() - klog. - V(logLevel(gvk.Group)). - Infof("Skipping %v %s/%s. Only %s namespace is supported for Community Edition. Please upgrade to Enterprise to use any namespace.", gvk, o.GetNamespace(), o.GetName(), h.restrictToNamespace) + // WARNING: o.GetObjectKind().GroupVersionKind() is not set and can't be used to detect GVK + if gvks, _, _ := clientsetscheme.Scheme.ObjectKinds(o); len(gvks) > 0 { + klog. + V(logLevel(gvks[0].Group)). + Infof("Skipping %v %s/%s. Only %s namespace is supported for Community Edition. Please upgrade to Enterprise to use any namespace.", gvks[0], o.GetNamespace(), o.GetName(), h.restrictToNamespace) + } return } } @@ -242,10 +247,12 @@ func (h *QueueingEventHandler) OnDelete(obj interface{}) { klog.V(5).Infof("Recovered deleted object '%v' from tombstone", tombstone.Obj.(metav1.Object).GetName()) } if o.GetNamespace() != "" && o.GetNamespace() != h.restrictToNamespace { - gvk := o.GetObjectKind().GroupVersionKind() - klog. - V(logLevel(gvk.Group)). - Infof("Skipping %v %s/%s. Only %s namespace is supported for Community Edition. Please upgrade to Enterprise to use any namespace.", gvk, o.GetNamespace(), o.GetName(), h.restrictToNamespace) + // WARNING: o.GetObjectKind().GroupVersionKind() is not set and can't be used to detect GVK + if gvks, _, _ := clientsetscheme.Scheme.ObjectKinds(o); len(gvks) > 0 { + klog. + V(logLevel(gvks[0].Group)). + Infof("Skipping %v %s/%s. Only %s namespace is supported for Community Edition. Please upgrade to Enterprise to use any namespace.", gvks[0], o.GetNamespace(), o.GetName(), h.restrictToNamespace) + } return } } diff --git a/vendor/modules.txt b/vendor/modules.txt index 32bf068ac..0daba6154 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1269,7 +1269,7 @@ k8s.io/utils/pointer k8s.io/utils/trace # kmodules.xyz/apiversion v0.2.0 kmodules.xyz/apiversion -# kmodules.xyz/client-go v0.0.0-20210909114628-15cac6c74063 +# kmodules.xyz/client-go v0.0.0-20210921150324-f005c6dfcb32 ## explicit kmodules.xyz/client-go kmodules.xyz/client-go/admissionregistration