Skip to content

Commit 6c08ffa

Browse files
committed
[sig-cli] oc ...
1 parent e5d212a commit 6c08ffa

14 files changed

+509
-308
lines changed

test/extended/cli/debug.go

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package cli
22

33
import (
4+
"context"
45
"fmt"
56
"time"
67

78
g "github.com/onsi/ginkgo/v2"
89
o "github.com/onsi/gomega"
910

11+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1012
"k8s.io/apimachinery/pkg/util/wait"
13+
"k8s.io/klog/v2"
1114
admissionapi "k8s.io/pod-security-admission/api"
1215

1316
configv1 "github.com/openshift/api/config/v1"
@@ -29,85 +32,102 @@ var _ = g.Describe("[sig-cli] oc debug", func() {
2932
helloPod := exutil.FixturePath("..", "..", "examples", "hello-openshift", "hello-pod.json")
3033
imageStreamsCentos := exutil.FixturePath("..", "..", "examples", "image-streams", "image-streams-centos7.json")
3134

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()
3440
o.Expect(err).NotTo(o.HaveOccurred())
3541
// wait for image stream to be present which means the build has completed
3642
err = wait.Poll(cliInterval, buildTimeout, func() (bool, error) {
3743
err := oc.Run("get").Args("imagestreamtags", "local-busybox:latest").Execute()
3844
return err == nil, nil
3945
})
4046
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
4250
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()
4464
return err == nil, nil
4565
})
4666
o.Expect(err).NotTo(o.HaveOccurred())
4767

4868
g.By("should print the imagestream-based container entrypoint/command")
4969
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()
5171
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"))
5373

5474
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()
5676
o.Expect(err).NotTo(o.HaveOccurred())
5777
o.Expect(out).To(o.MatchRegexp("Starting pod/local-busybox2-debug.*, command was: foo bar baz qux\n"))
5878

5979
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()
6181
o.Expect(err).NotTo(o.HaveOccurred())
6282
o.Expect(out).To(o.MatchRegexp("Starting pod/busybox1-debug.* ...\n"))
6383

6484
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()
6686
o.Expect(err).NotTo(o.HaveOccurred())
6787
o.Expect(out).To(o.MatchRegexp("Starting pod/busybox2-debug.*, command was: foo bar baz qux\n"))
6888
})
6989

70-
g.It("dissect deployment config debug [apigroup:apps.openshift.io]", func() {
90+
g.It("dissect deployment debug", func() {
7191
err := oc.Run("create").Args("-f", testDeploymentConfig).Execute()
7292
o.Expect(err).NotTo(o.HaveOccurred())
7393

7494
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()
7696
o.Expect(err).NotTo(o.HaveOccurred())
7797
o.Expect(out).To(o.ContainSubstring("- /bin/sh"))
7898

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()
80100
o.Expect(err).NotTo(o.HaveOccurred())
81101
o.Expect(out).To(o.ContainSubstring("annotations:"))
82102

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()
84104
o.Expect(err).NotTo(o.HaveOccurred())
85105
o.Expect(out).To(o.ContainSubstring("runAsUser: 0"))
86106

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()
88108
o.Expect(err).NotTo(o.HaveOccurred())
89109
o.Expect(out).To(o.ContainSubstring("runAsNonRoot: true"))
90110

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()
92112
o.Expect(err).NotTo(o.HaveOccurred())
93113
o.Expect(out).To(o.ContainSubstring("runAsUser: 1"))
94114

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()
96116
o.Expect(err).NotTo(o.HaveOccurred())
97117
o.Expect(out).To(o.ContainSubstring("stdinOnce"))
98118
o.Expect(out).To(o.ContainSubstring("tty"))
99119

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()
101121
o.Expect(err).NotTo(o.HaveOccurred())
102122
o.Expect(out).NotTo(o.ContainSubstring("tty"))
103123

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()
105125
o.Expect(err).NotTo(o.HaveOccurred())
106126
o.Expect(out).To(o.ContainSubstring("- /bin/env"))
107127
o.Expect(out).NotTo(o.ContainSubstring("stdin"))
108128
o.Expect(out).NotTo(o.ContainSubstring("tty"))
109129

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()
111131
o.Expect(err).To(o.HaveOccurred())
112132
o.Expect(out).To(o.ContainSubstring(`on node "invalid"`))
113133
})
@@ -150,8 +170,10 @@ var _ = g.Describe("[sig-cli] oc debug", func() {
150170
out, err = oc.Run("debug").Args("--request-timeout=10s", "-c", "ruby-helloworld", "--one-container", "dc/test-deployment-config", "-o", "jsonpath='{.metadata.name}").Output()
151171
o.Expect(err).NotTo(o.HaveOccurred())
152172
o.Expect(out).To(o.ContainSubstring("test-deployment-config"))
173+
})
153174

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(`
155177
apiVersion: apps/v1
156178
kind: Deployment
157179
metadata:
@@ -176,7 +198,7 @@ spec:
176198
`).Execute()
177199
o.Expect(err).NotTo(o.HaveOccurred())
178200

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()
180202
o.Expect(err).NotTo(o.HaveOccurred())
181203
o.Expect(out).To(o.ContainSubstring("test-deployment-debug"))
182204
})

test/extended/cli/env.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ var _ = g.Describe("[sig-cli] oc env", func() {
1111
defer g.GinkgoRecover()
1212

1313
var (
14-
file = exutil.FixturePath("testdata", "test-deployment-config.yaml")
14+
file = exutil.FixturePath("testdata", "test-deployment.yaml")
1515
buildConfigFile = exutil.FixturePath("testdata", "test-buildcli.json")
1616
oc = exutil.NewCLI("oc-env")
1717
)
1818

19-
g.It("can set environment variables [apigroup:apps.openshift.io][apigroup:image.openshift.io][apigroup:build.openshift.io]", func() {
20-
g.By("creating a test-deployment-config deploymentconfig")
19+
g.It("can set environment variables [apigroup:image.openshift.io][apigroup:build.openshift.io]", func() {
20+
g.By("creating a test-deployment deploymentconfig")
2121
err := oc.Run("create").Args("-f", file).Execute()
2222
o.Expect(err).NotTo(o.HaveOccurred())
2323
defer oc.Run("delete").Args("-f", file).Execute()
@@ -28,51 +28,51 @@ var _ = g.Describe("[sig-cli] oc env", func() {
2828
defer oc.Run("delete").Args("-f", buildConfigFile).Execute()
2929

3030
g.By("setting environment variables for deploymentconfig")
31-
dc := "dc/test-deployment-config"
31+
deploymentName := "deployment/test-deployment"
3232

33-
out, err := oc.Run("set").Args("env", dc, "FOO=1st").Output()
33+
out, err := oc.Run("set").Args("env", deploymentName, "FOO=1st").Output()
3434
o.Expect(err).NotTo(o.HaveOccurred())
3535
o.Expect(out).To(o.ContainSubstring("updated"))
3636

37-
out, err = oc.Run("set").Args("env", dc, "FOO=2nd").Output()
37+
out, err = oc.Run("set").Args("env", deploymentName, "FOO=2nd").Output()
3838
o.Expect(err).NotTo(o.HaveOccurred())
3939
o.Expect(out).To(o.ContainSubstring("updated"))
4040

41-
out, err = oc.Run("set").Args("env", dc, "FOO=bar", "--overwrite").Output()
41+
out, err = oc.Run("set").Args("env", deploymentName, "FOO=bar", "--overwrite").Output()
4242
o.Expect(err).NotTo(o.HaveOccurred())
4343
o.Expect(out).To(o.ContainSubstring("updated"))
4444

45-
out, err = oc.Run("set").Args("env", dc, "FOO=zee", "--overwrite=false").Output()
45+
out, err = oc.Run("set").Args("env", deploymentName, "FOO=zee", "--overwrite=false").Output()
4646
o.Expect(err).To(o.HaveOccurred())
4747
o.Expect(out).To(o.ContainSubstring("already has a value"))
4848

49-
out, err = oc.Run("set").Args("env", dc, "--list").Output()
49+
out, err = oc.Run("set").Args("env", deploymentName, "--list").Output()
5050
o.Expect(err).NotTo(o.HaveOccurred())
5151
o.Expect(out).To(o.ContainSubstring("FOO=bar"))
5252

53-
out, err = oc.Run("set").Args("env", dc, "FOO-").Output()
53+
out, err = oc.Run("set").Args("env", deploymentName, "FOO-").Output()
5454
o.Expect(err).NotTo(o.HaveOccurred())
5555
o.Expect(out).To(o.ContainSubstring("updated"))
5656

5757
err = oc.Run("create").Args("secret", "generic", "mysecret", "--from-literal=foo.bar=secret").Execute()
5858
o.Expect(err).NotTo(o.HaveOccurred())
5959

60-
out, err = oc.Run("set").Args("env", "--from=secret/mysecret", "--prefix=PREFIX_", dc, "FOO-").Output()
60+
out, err = oc.Run("set").Args("env", "--from=secret/mysecret", "--prefix=PREFIX_", deploymentName, "FOO-").Output()
6161
o.Expect(err).NotTo(o.HaveOccurred())
6262
o.Expect(out).To(o.ContainSubstring("updated"))
6363

64-
out, err = oc.Run("set").Args("env", dc, "--list").Output()
64+
out, err = oc.Run("set").Args("env", deploymentName, "--list").Output()
6565
o.Expect(err).NotTo(o.HaveOccurred())
6666
o.Expect(out).To(o.ContainSubstring("PREFIX_FOO_BAR from secret mysecret, key foo.bar"))
6767

68-
out, err = oc.Run("set").Args("env", dc, "--list", "--resolve").Output()
68+
out, err = oc.Run("set").Args("env", deploymentName, "--list", "--resolve").Output()
6969
o.Expect(err).NotTo(o.HaveOccurred())
7070
o.Expect(out).To(o.ContainSubstring("PREFIX_FOO_BAR=secret"))
7171

7272
err = oc.Run("delete").Args("secret", "mysecret").Execute()
7373
o.Expect(err).NotTo(o.HaveOccurred())
7474

75-
out, err = oc.Run("set").Args("env", dc, "--list", "--resolve").Output()
75+
out, err = oc.Run("set").Args("env", deploymentName, "--list", "--resolve").Output()
7676
o.Expect(err).To(o.HaveOccurred())
7777
o.Expect(out).To(o.ContainSubstring("error retrieving reference for PREFIX_FOO_BAR"))
7878

test/extended/cli/idle.go

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1313
"k8s.io/apimachinery/pkg/util/wait"
1414
admissionapi "k8s.io/pod-security-admission/api"
15+
"k8s.io/klog/v2"
1516

1617
exutil "github.com/openshift/origin/test/extended/util"
1718
)
@@ -155,3 +156,131 @@ var _ = g.Describe("[sig-cli] oc idle [apigroup:apps.openshift.io][apigroup:rout
155156
o.Expect(out).To(o.Equal(scaledReplicaCount))
156157
})
157158
})
159+
160+
var _ = g.Describe("[sig-cli] oc idle Deployments [apigroup:route.openshift.io][apigroup:project.openshift.io][apigroup:image.openshift.io]", func() {
161+
defer g.GinkgoRecover()
162+
163+
var (
164+
oc = exutil.NewCLIWithPodSecurityLevel("oc-idle", admissionapi.LevelBaseline)
165+
cmdTestData = exutil.FixturePath("testdata", "cmd", "test", "cmd", "testdata")
166+
idleSVCRoute = filepath.Join(cmdTestData, "idling-svc-route.yaml")
167+
idleDeployment = filepath.Join(cmdTestData, "idling-deployment.yaml")
168+
idledTemplate = fmt.Sprintf("--template={{index .metadata.annotations \"%s\"}}", idledAnnotation)
169+
)
170+
171+
var deploymentName, expectedOutput string
172+
g.JustBeforeEach(func() {
173+
projectName, err := oc.Run("project").Args("-q").Output()
174+
o.Expect(err).NotTo(o.HaveOccurred())
175+
176+
g.By("create required service and routers")
177+
err = oc.Run("create").Args("-f", idleSVCRoute).Execute()
178+
o.Expect(err).NotTo(o.HaveOccurred())
179+
180+
g.By("create deployment and get deployment name")
181+
_, err = oc.Run("create").Args("-f", idleDeployment).Output()
182+
o.Expect(err).NotTo(o.HaveOccurred())
183+
184+
dcList, err := oc.AdminKubeClient().AppsV1().Deployments(projectName).List(context.TODO(), metav1.ListOptions{LabelSelector: "app=idling-echo,deployment=idling-echo"})
185+
o.Expect(dcList.Items).Should(o.HaveLen(1))
186+
deploymentName = dcList.Items[0].Name
187+
188+
expectedOutput = fmt.Sprintf("The service will unidle Deployment \"%s/%s\" to %s replicas once it receives traffic", projectName, deploymentName, scaledReplicaCount)
189+
190+
err = oc.Run("describe").Args("deployments", deploymentName).Execute()
191+
o.Expect(err).NotTo(o.HaveOccurred())
192+
193+
g.By("wait until idling-echo endpoint is ready")
194+
err = wait.PollImmediate(time.Second, 60*time.Second, func() (done bool, err error) {
195+
err = oc.Run("describe").Args("endpoints", "idling-echo").Execute()
196+
if err != nil {
197+
return false, nil
198+
}
199+
200+
return true, nil
201+
})
202+
o.Expect(err).NotTo(o.HaveOccurred())
203+
204+
g.By("wait until replicaset is ready")
205+
var rsName string
206+
err = wait.PollImmediate(time.Second, 60*time.Second, func() (done bool, err error) {
207+
rsList, err := oc.AdminKubeClient().AppsV1().ReplicaSets(projectName).List(context.TODO(), metav1.ListOptions{LabelSelector: "app=idling-echo,deployment=idling-echo"})
208+
o.Expect(err).NotTo(o.HaveOccurred())
209+
if len(rsList.Items) != 1 {
210+
klog.Infof("Expected only a single replicaset, got %d instead", len(rsList.Items))
211+
return false, nil
212+
}
213+
rsName = rsList.Items[0].Name
214+
err = oc.Run("get").Args("replicaset", rsName).Execute()
215+
if err != nil {
216+
return false, nil
217+
}
218+
219+
return true, nil
220+
})
221+
o.Expect(err).NotTo(o.HaveOccurred())
222+
223+
g.By(fmt.Sprintf("scale deployment to %s replicas", scaledReplicaCount))
224+
err = oc.Run("scale").Args("replicaset", rsName, fmt.Sprintf("--replicas=%s", scaledReplicaCount)).Execute()
225+
o.Expect(err).NotTo(o.HaveOccurred())
226+
227+
g.By(fmt.Sprintf("wait until pod is scaled to %s", scaledReplicaCount))
228+
err = wait.PollImmediate(time.Second, 60*time.Second, func() (done bool, err error) {
229+
out, err := oc.Run("get").Args("pods", "-l", "app=idling-echo", "--template={{ len .items }}", "--output=go-template").Output()
230+
if err != nil {
231+
return false, err
232+
}
233+
234+
if out != scaledReplicaCount {
235+
return false, nil
236+
}
237+
238+
return true, nil
239+
})
240+
o.Expect(err).NotTo(o.HaveOccurred())
241+
242+
g.By(fmt.Sprintf("wait until endpoint addresses are scaled to %s", scaledReplicaCount))
243+
err = wait.PollImmediate(time.Second, 60*time.Second, func() (done bool, err error) {
244+
out, err := oc.Run("get").Args("endpoints", "idling-echo", "--template={{ len (index .subsets 0).addresses }}", "--output=go-template").Output()
245+
if err != nil || out != scaledReplicaCount {
246+
return false, nil
247+
}
248+
249+
return true, nil
250+
})
251+
o.Expect(err).NotTo(o.HaveOccurred())
252+
})
253+
254+
g.It("by name", func() {
255+
err := oc.Run("idle").Args(fmt.Sprintf("deployment/%s", deploymentName)).Execute()
256+
o.Expect(err).To(o.HaveOccurred())
257+
258+
out, err := oc.Run("idle").Args("idling-echo").Output()
259+
o.Expect(err).NotTo(o.HaveOccurred())
260+
o.Expect(out).To(o.ContainSubstring(expectedOutput))
261+
262+
out, err = oc.Run("get").Args("service", "idling-echo", idledTemplate, "--output=go-template").Output()
263+
o.Expect(err).NotTo(o.HaveOccurred())
264+
o.Expect(out).NotTo(o.BeEmpty())
265+
})
266+
267+
g.It("by label", func() {
268+
out, err := oc.Run("idle").Args("-l", "app=idling-echo").Output()
269+
o.Expect(err).NotTo(o.HaveOccurred())
270+
o.Expect(out).To(o.ContainSubstring(expectedOutput))
271+
272+
out, err = oc.Run("get").Args("service", "idling-echo", idledTemplate, "--output=go-template").Output()
273+
o.Expect(err).NotTo(o.HaveOccurred())
274+
o.Expect(out).NotTo(o.BeEmpty())
275+
})
276+
277+
g.It("by all", func() {
278+
out, err := oc.Run("idle").Args("--all").Output()
279+
o.Expect(err).NotTo(o.HaveOccurred())
280+
o.Expect(out).To(o.ContainSubstring(expectedOutput))
281+
282+
out, err = oc.Run("get").Args("service", "idling-echo", idledTemplate, "--output=go-template").Output()
283+
o.Expect(err).NotTo(o.HaveOccurred())
284+
o.Expect(out).NotTo(o.BeEmpty())
285+
})
286+
})

test/extended/cli/run.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ var _ = g.Describe("[sig-cli] oc run", func() {
1414

1515
var oc = exutil.NewCLIWithPodSecurityLevel("oc-run", admissionapi.LevelBaseline)
1616

17-
g.It("can use --image flag correctly [apigroup:apps.openshift.io]", func() {
18-
_, err := oc.Run("create").Args("deploymentconfig", "newdcforimage", "--image=validimagevalue").Output()
17+
g.It("can use --image flag correctly", func() {
18+
_, err := oc.Run("create").Args("deployment", "newdcforimage", "--image=validimagevalue").Output()
1919
o.Expect(err).NotTo(o.HaveOccurred())
2020

2121
_, err = oc.Run("run").Args("newdcforimage2", "--image=\"InvalidImageValue0192\"").Output()

0 commit comments

Comments
 (0)