Skip to content

Commit c7fb370

Browse files
authored
Log warning if Community License is used with non-demo namespace (#136)
/cherry-pick Signed-off-by: 1gtm <1gtm@appscode.com>
1 parent 11397c0 commit c7fb370

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
k8s.io/client-go v0.21.1
1919
k8s.io/klog/v2 v2.8.0
2020
k8s.io/kubectl v0.21.1
21-
kmodules.xyz/client-go v0.0.0-20210909114628-15cac6c74063
21+
kmodules.xyz/client-go v0.0.0-20210921150324-f005c6dfcb32
2222
kmodules.xyz/custom-resources v0.0.0-20210829135624-c63be82e13c0 // indirect
2323
kmodules.xyz/objectstore-api v0.0.0-20210829122106-d39859fc2d56
2424
kmodules.xyz/offshoot-api v0.0.0-20210804100837-d0388be3e60d

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,8 +1144,8 @@ kmodules.xyz/client-go v0.0.0-20210715065708-d4f0cc74ead1/go.mod h1:E/vGngai00Ut
11441144
kmodules.xyz/client-go v0.0.0-20210719120358-dd0503cf99cf/go.mod h1:E/vGngai00UtVwP8R4PWpPUBF/EZa6Ub9WS5+tVcs4M=
11451145
kmodules.xyz/client-go v0.0.0-20210822203828-5e9cebbf1dfa/go.mod h1:0gkPeALtYjB27OHt4rd6+ZmMgoVTHVLtEJQeU23/gtA=
11461146
kmodules.xyz/client-go v0.0.0-20210827153326-54ead9c6225f/go.mod h1:0gkPeALtYjB27OHt4rd6+ZmMgoVTHVLtEJQeU23/gtA=
1147-
kmodules.xyz/client-go v0.0.0-20210909114628-15cac6c74063 h1:u+/fmk4N1LsxeCU7q7vnNgaADK73UeyNWKzNtjFe3Bs=
1148-
kmodules.xyz/client-go v0.0.0-20210909114628-15cac6c74063/go.mod h1:0gkPeALtYjB27OHt4rd6+ZmMgoVTHVLtEJQeU23/gtA=
1147+
kmodules.xyz/client-go v0.0.0-20210921150324-f005c6dfcb32 h1:ZXVJStHHjppRoaUw5JQ5KzMjK+EiY1GkcPigPHfkvSg=
1148+
kmodules.xyz/client-go v0.0.0-20210921150324-f005c6dfcb32/go.mod h1:0gkPeALtYjB27OHt4rd6+ZmMgoVTHVLtEJQeU23/gtA=
11491149
kmodules.xyz/constants v0.0.0-20210218100002-2c304bfda278/go.mod h1:DbiFk1bJ1KEO94t1SlAn7tzc+Zz95rSXgyUKa2nzPmY=
11501150
kmodules.xyz/crd-schema-fuzz v0.0.0-20210618002152-fae23aef5fb4/go.mod h1:IIkUctlfoptoci0BOrsUf8ya+MOG5uaeh1PE4uzaIbA=
11511151
kmodules.xyz/custom-resources v0.0.0-20210618003440-c6bb400da153/go.mod h1:/NLuNSf299U0XVuNEh2swtw3EczWFRL3Sx24WhNoWCM=

vendor/kmodules.xyz/client-go/tools/exec/lib.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package exec
1919
import (
2020
"bytes"
2121
"context"
22+
"errors"
2223
"fmt"
2324
"net/http"
2425
"strings"
@@ -32,9 +33,12 @@ import (
3233
"k8s.io/client-go/tools/remotecommand"
3334
)
3435

36+
var NotRunning = errors.New("container not running")
37+
3538
type Options struct {
3639
core.PodExecOptions
3740
remotecommand.StreamOptions
41+
CheckForRunningContainer bool
3842
}
3943

4044
func Container(container string) func(*Options) {
@@ -49,6 +53,12 @@ func Command(cmd ...string) func(*Options) {
4953
}
5054
}
5155

56+
func CheckForRunningContainer(check bool) func(*Options) {
57+
return func(opts *Options) {
58+
opts.CheckForRunningContainer = check
59+
}
60+
}
61+
5262
func Input(in string) func(*Options) {
5363
return func(opts *Options) {
5464
opts.PodExecOptions.Stdin = true
@@ -102,6 +112,23 @@ func execIntoPod(config *rest.Config, kc kubernetes.Interface, pod *core.Pod, op
102112
option(opts)
103113
}
104114

115+
if opts.CheckForRunningContainer {
116+
for _, status := range pod.Status.ContainerStatuses {
117+
if status.Name == opts.PodExecOptions.Container {
118+
if status.State.Running == nil {
119+
return "", NotRunning
120+
}
121+
}
122+
}
123+
for _, status := range pod.Status.InitContainerStatuses {
124+
if status.Name == opts.PodExecOptions.Container {
125+
if status.State.Running == nil {
126+
return "", NotRunning
127+
}
128+
}
129+
}
130+
}
131+
105132
req := kc.CoreV1().RESTClient().Post().
106133
Resource("pods").
107134
Name(pod.Name).
@@ -115,14 +142,12 @@ func execIntoPod(config *rest.Config, kc kubernetes.Interface, pod *core.Pod, op
115142
}
116143

117144
err = exec.Stream(opts.StreamOptions)
118-
119145
if err != nil {
120146
return "", fmt.Errorf("could not execute: %v", err)
121147
}
122148

123149
if execErr.Len() > 0 {
124150
return "", fmt.Errorf("stderr: %v", execErr.String())
125151
}
126-
127152
return execOut.String(), nil
128153
}

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ k8s.io/utils/integer
659659
k8s.io/utils/io
660660
k8s.io/utils/pointer
661661
k8s.io/utils/trace
662-
# kmodules.xyz/client-go v0.0.0-20210909114628-15cac6c74063
662+
# kmodules.xyz/client-go v0.0.0-20210921150324-f005c6dfcb32
663663
## explicit
664664
kmodules.xyz/client-go
665665
kmodules.xyz/client-go/api/v1

0 commit comments

Comments
 (0)