1
1
package cli
2
2
3
3
import (
4
+ "context"
4
5
"fmt"
5
6
"time"
6
7
7
8
g "github.com/onsi/ginkgo/v2"
8
9
o "github.com/onsi/gomega"
9
10
11
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10
12
"k8s.io/apimachinery/pkg/util/wait"
13
+ "k8s.io/klog/v2"
11
14
admissionapi "k8s.io/pod-security-admission/api"
12
15
13
16
configv1 "github.com/openshift/api/config/v1"
@@ -29,85 +32,102 @@ var _ = g.Describe("[sig-cli] oc debug", func() {
29
32
helloPod := exutil .FixturePath (".." , ".." , "examples" , "hello-openshift" , "hello-pod.json" )
30
33
imageStreamsCentos := exutil .FixturePath (".." , ".." , "examples" , "image-streams" , "image-streams-centos7.json" )
31
34
32
- g .It ("deployment configs from a build [apigroup:image.openshift.io][apigroup:apps.openshift.io]" , func () {
33
- err := oc .Run ("create" ).Args ("-f" , testCLIDebug ).Execute ()
35
+ g .It ("deployment from a build [apigroup:image.openshift.io]" , func () {
36
+ projectName , err := oc .Run ("project" ).Args ("-q" ).Output ()
37
+ o .Expect (err ).NotTo (o .HaveOccurred ())
38
+
39
+ err = oc .Run ("create" ).Args ("-f" , testCLIDebug ).Execute ()
34
40
o .Expect (err ).NotTo (o .HaveOccurred ())
35
41
// wait for image stream to be present which means the build has completed
36
42
err = wait .Poll (cliInterval , buildTimeout , func () (bool , error ) {
37
43
err := oc .Run ("get" ).Args ("imagestreamtags" , "local-busybox:latest" ).Execute ()
38
44
return err == nil , nil
39
45
})
40
46
o .Expect (err ).NotTo (o .HaveOccurred ())
41
- // and for replication controller which means we can kick of debug session
47
+
48
+ // and for replicaset which means we can kick of debug session
49
+ var rsName string
42
50
err = wait .Poll (cliInterval , deployTimeout , func () (bool , error ) {
43
- err := oc .Run ("get" ).Args ("replicationcontrollers" , "local-busybox1-1" ).Execute ()
51
+ rsList , err := oc .AdminKubeClient ().AppsV1 ().ReplicaSets (projectName ).List (context .TODO (), metav1.ListOptions {LabelSelector : "deployment=local-busybox1" })
52
+ o .Expect (err ).NotTo (o .HaveOccurred ())
53
+ for _ , item := range rsList .Items {
54
+ if item .Annotations ["deployment.kubernetes.io/revision" ] == "2" {
55
+ rsName = rsList .Items [0 ].Name
56
+ }
57
+ }
58
+ if rsName == "" {
59
+ klog .Infof ("Waiting for a replicaset with deployment.kubernetes.io/revision=2" )
60
+ return false , nil
61
+ }
62
+ rsName = rsList .Items [0 ].Name
63
+ err = oc .Run ("get" ).Args ("replicasets" , rsName ).Execute ()
44
64
return err == nil , nil
45
65
})
46
66
o .Expect (err ).NotTo (o .HaveOccurred ())
47
67
48
68
g .By ("should print the imagestream-based container entrypoint/command" )
49
69
var out string
50
- out , err = oc .Run ("debug" ).Args ("dc /local-busybox1" ).Output ()
70
+ out , err = oc .Run ("debug" ).Args ("deployment /local-busybox1" ).Output ()
51
71
o .Expect (err ).NotTo (o .HaveOccurred ())
52
- o .Expect (out ).To (o .MatchRegexp ("Starting pod/local-busybox1-debug.*, command was: /usr/bin/bash \n " ))
72
+ o .Expect (out ).To (o .MatchRegexp ("Starting pod/local-busybox1-debug.* ... \n " ))
53
73
54
74
g .By ("should print the overridden imagestream-based container entrypoint/command" )
55
- out , err = oc .Run ("debug" ).Args ("dc /local-busybox2" ).Output ()
75
+ out , err = oc .Run ("debug" ).Args ("deployment /local-busybox2" ).Output ()
56
76
o .Expect (err ).NotTo (o .HaveOccurred ())
57
77
o .Expect (out ).To (o .MatchRegexp ("Starting pod/local-busybox2-debug.*, command was: foo bar baz qux\n " ))
58
78
59
79
g .By ("should print the container image-based container entrypoint/command" )
60
- out , err = oc .Run ("debug" ).Args ("dc /busybox1" ).Output ()
80
+ out , err = oc .Run ("debug" ).Args ("deployment /busybox1" ).Output ()
61
81
o .Expect (err ).NotTo (o .HaveOccurred ())
62
82
o .Expect (out ).To (o .MatchRegexp ("Starting pod/busybox1-debug.* ...\n " ))
63
83
64
84
g .By ("should print the overridden container image-based container entrypoint/command" )
65
- out , err = oc .Run ("debug" ).Args ("dc /busybox2" ).Output ()
85
+ out , err = oc .Run ("debug" ).Args ("deployment /busybox2" ).Output ()
66
86
o .Expect (err ).NotTo (o .HaveOccurred ())
67
87
o .Expect (out ).To (o .MatchRegexp ("Starting pod/busybox2-debug.*, command was: foo bar baz qux\n " ))
68
88
})
69
89
70
- g .It ("dissect deployment config debug [apigroup:apps.openshift.io] " , func () {
90
+ g .It ("dissect deployment debug" , func () {
71
91
err := oc .Run ("create" ).Args ("-f" , testDeploymentConfig ).Execute ()
72
92
o .Expect (err ).NotTo (o .HaveOccurred ())
73
93
74
94
var out string
75
- out , err = oc .Run ("debug" ).Args ("dc /test-deployment-config " , "-oyaml" ).Output ()
95
+ out , err = oc .Run ("debug" ).Args ("deployment /test-deployment" , "-oyaml" ).Output ()
76
96
o .Expect (err ).NotTo (o .HaveOccurred ())
77
97
o .Expect (out ).To (o .ContainSubstring ("- /bin/sh" ))
78
98
79
- out , err = oc .Run ("debug" ).Args ("dc /test-deployment-config " , "--keep-annotations" , "-oyaml" ).Output ()
99
+ out , err = oc .Run ("debug" ).Args ("deployment /test-deployment" , "--keep-annotations" , "-oyaml" ).Output ()
80
100
o .Expect (err ).NotTo (o .HaveOccurred ())
81
101
o .Expect (out ).To (o .ContainSubstring ("annotations:" ))
82
102
83
- out , err = oc .Run ("debug" ).Args ("dc /test-deployment-config " , "--as-root" , "-oyaml" ).Output ()
103
+ out , err = oc .Run ("debug" ).Args ("deployment /test-deployment" , "--as-root" , "-oyaml" ).Output ()
84
104
o .Expect (err ).NotTo (o .HaveOccurred ())
85
105
o .Expect (out ).To (o .ContainSubstring ("runAsUser: 0" ))
86
106
87
- out , err = oc .Run ("debug" ).Args ("dc /test-deployment-config " , "--as-root=false" , "-oyaml" ).Output ()
107
+ out , err = oc .Run ("debug" ).Args ("deployment /test-deployment" , "--as-root=false" , "-oyaml" ).Output ()
88
108
o .Expect (err ).NotTo (o .HaveOccurred ())
89
109
o .Expect (out ).To (o .ContainSubstring ("runAsNonRoot: true" ))
90
110
91
- out , err = oc .Run ("debug" ).Args ("dc /test-deployment-config " , "--as-user=1" , "-oyaml" ).Output ()
111
+ out , err = oc .Run ("debug" ).Args ("deployment /test-deployment" , "--as-user=1" , "-oyaml" ).Output ()
92
112
o .Expect (err ).NotTo (o .HaveOccurred ())
93
113
o .Expect (out ).To (o .ContainSubstring ("runAsUser: 1" ))
94
114
95
- out , err = oc .Run ("debug" ).Args ("dc /test-deployment-config " , "-t" , "-oyaml" ).Output ()
115
+ out , err = oc .Run ("debug" ).Args ("deployment /test-deployment" , "-t" , "-oyaml" ).Output ()
96
116
o .Expect (err ).NotTo (o .HaveOccurred ())
97
117
o .Expect (out ).To (o .ContainSubstring ("stdinOnce" ))
98
118
o .Expect (out ).To (o .ContainSubstring ("tty" ))
99
119
100
- out , err = oc .Run ("debug" ).Args ("dc /test-deployment-config " , "--tty=false" , "-oyaml" ).Output ()
120
+ out , err = oc .Run ("debug" ).Args ("deployment /test-deployment" , "--tty=false" , "-oyaml" ).Output ()
101
121
o .Expect (err ).NotTo (o .HaveOccurred ())
102
122
o .Expect (out ).NotTo (o .ContainSubstring ("tty" ))
103
123
104
- out , err = oc .Run ("debug" ).Args ("dc /test-deployment-config " , "-oyaml" , "--" , "/bin/env" ).Output ()
124
+ out , err = oc .Run ("debug" ).Args ("deployment /test-deployment" , "-oyaml" , "--" , "/bin/env" ).Output ()
105
125
o .Expect (err ).NotTo (o .HaveOccurred ())
106
126
o .Expect (out ).To (o .ContainSubstring ("- /bin/env" ))
107
127
o .Expect (out ).NotTo (o .ContainSubstring ("stdin" ))
108
128
o .Expect (out ).NotTo (o .ContainSubstring ("tty" ))
109
129
110
- out , err = oc .Run ("debug" ).Args ("dc /test-deployment-config " , "--node-name=invalid" , "--" , "/bin/env" ).Output ()
130
+ out , err = oc .Run ("debug" ).Args ("deployment /test-deployment" , "--node-name=invalid" , "--" , "/bin/env" ).Output ()
111
131
o .Expect (err ).To (o .HaveOccurred ())
112
132
o .Expect (out ).To (o .ContainSubstring (`on node "invalid"` ))
113
133
})
@@ -150,8 +170,10 @@ var _ = g.Describe("[sig-cli] oc debug", func() {
150
170
out , err = oc .Run ("debug" ).Args ("--request-timeout=10s" , "-c" , "ruby-helloworld" , "--one-container" , "dc/test-deployment-config" , "-o" , "jsonpath='{.metadata.name}" ).Output ()
151
171
o .Expect (err ).NotTo (o .HaveOccurred ())
152
172
o .Expect (out ).To (o .ContainSubstring ("test-deployment-config" ))
173
+ })
153
174
154
- err = oc .Run ("create" ).Args ("-f" , "-" ).InputString (`
175
+ g .It ("ensure debug does not depend on a container actually existing for the selected resource for deployment" , func () {
176
+ err := oc .Run ("create" ).Args ("-f" , "-" ).InputString (`
155
177
apiVersion: apps/v1
156
178
kind: Deployment
157
179
metadata:
@@ -176,7 +198,7 @@ spec:
176
198
` ).Execute ()
177
199
o .Expect (err ).NotTo (o .HaveOccurred ())
178
200
179
- out , err = oc .Run ("debug" ).Args ("--request-timeout=10s" , "-c" , "ruby-helloworld" , "--one-container" , "deploy/test-deployment" , "-o" , "jsonpath='{.metadata.name}" ).Output ()
201
+ out , err : = oc .Run ("debug" ).Args ("--request-timeout=10s" , "-c" , "ruby-helloworld" , "--one-container" , "deploy/test-deployment" , "-o" , "jsonpath='{.metadata.name}" ).Output ()
180
202
o .Expect (err ).NotTo (o .HaveOccurred ())
181
203
o .Expect (out ).To (o .ContainSubstring ("test-deployment-debug" ))
182
204
})
0 commit comments