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

Log warning if Community License is used with non-demo namespace #1383

Merged
merged 1 commit into from
Sep 21, 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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
29 changes: 27 additions & 2 deletions vendor/kmodules.xyz/client-go/tools/exec/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package exec
import (
"bytes"
"context"
"errors"
"fmt"
"net/http"
"strings"
Expand All @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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).
Expand All @@ -115,14 +142,12 @@ 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)
}

if execErr.Len() > 0 {
return "", fmt.Errorf("stderr: %v", execErr.String())
}

return execOut.String(), nil
}
31 changes: 19 additions & 12 deletions vendor/kmodules.xyz/client-go/tools/queue/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down