Skip to content

Commit 703f84c

Browse files
Fixed flakiness in oc debug image stream
1 parent dad4ce8 commit 703f84c

1 file changed

Lines changed: 29 additions & 22 deletions

File tree

test/extended/cli/debug.go

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cli
33
import (
44
"context"
55
"fmt"
6+
"strings"
67
"time"
78

89
g "github.com/onsi/ginkgo/v2"
@@ -15,7 +16,6 @@ import (
1516
"k8s.io/klog/v2"
1617
admissionapi "k8s.io/pod-security-admission/api"
1718

18-
configv1 "github.com/openshift/api/config/v1"
1919
exutil "github.com/openshift/origin/test/extended/util"
2020
)
2121

@@ -33,7 +33,6 @@ var _ = g.Describe("[sig-cli] oc debug", func() {
3333
testDeployment := exutil.FixturePath("testdata", "test-deployment.yaml")
3434
testReplicationController := exutil.FixturePath("testdata", "test-replication-controller.yaml")
3535
helloPod := exutil.FixturePath("..", "..", "examples", "hello-openshift", "hello-pod.json")
36-
imageStreamsCentos := exutil.FixturePath("..", "..", "examples", "image-streams", "image-streams-centos7.json")
3736

3837
g.It("deployment from a build [apigroup:image.openshift.io]", func() {
3938
projectName, err := oc.Run("project").Args("-q").Output()
@@ -252,33 +251,41 @@ spec:
252251
})
253252

254253
g.It("ensure it works with image streams [apigroup:image.openshift.io]", func() {
255-
hasImageRegistry, err := exutil.IsCapabilityEnabled(oc, configv1.ClusterVersionCapabilityImageRegistry)
256-
o.Expect(err).NotTo(o.HaveOccurred())
257-
258-
err = oc.Run("create").Args("-f", imageStreamsCentos).Execute()
259-
o.Expect(err).NotTo(o.HaveOccurred())
260-
err = wait.Poll(cliInterval, cliTimeout, func() (bool, error) {
261-
err := oc.Run("get").Args("imagestreamtags", "wildfly:latest").Execute()
262-
return err == nil, nil
254+
ctx := context.Background()
255+
const (
256+
targetIS = "cli"
257+
targetNS = "openshift"
258+
containerImage = `{.spec.containers[0].image}`
259+
digestPullMatch = `^.+@sha256:[a-f0-9]{64}$`
260+
)
261+
262+
g.By("waiting for the internal ImageStreamTag to be available")
263+
err := wait.PollUntilContextTimeout(ctx, cliInterval, cliTimeout, true, func(ctx context.Context) (bool, error) {
264+
if err := oc.AsAdmin().Run("get").Args("istag", targetIS+":latest", "-n", targetNS).Execute(); err != nil {
265+
return false, nil
266+
}
267+
return true, nil
263268
})
264-
o.Expect(err).NotTo(o.HaveOccurred())
265-
266-
var out string
267-
var resolvedImageMatcher = o.MatchRegexp("image:.*oc-debug-.*/wildfly@sha256")
268-
if !hasImageRegistry {
269-
resolvedImageMatcher = o.ContainSubstring("image: quay.io/wildfly/wildfly-centos7")
269+
if err != nil {
270+
g.Skip(fmt.Sprintf("openshift/%s:latest not observed within %s: %v", targetIS, cliTimeout, err))
270271
}
271272

272-
out, err = oc.Run("debug").Args("istag/wildfly:latest", "-o", "yaml").Output()
273+
g.By("verifying oc debug works with istag")
274+
img, err := oc.AsAdmin().Run("debug").Args(
275+
fmt.Sprintf("istag/%s:latest", targetIS), "-n", targetNS, "-o", "jsonpath="+containerImage,
276+
).Output()
273277
o.Expect(err).NotTo(o.HaveOccurred())
274-
o.Expect(out).To(resolvedImageMatcher)
278+
o.Expect(strings.TrimSpace(img)).To(o.MatchRegexp(digestPullMatch), "debug pod should reference the ImageStreamTag by digest (any registry host)")
275279

276-
var sha string
277-
sha, err = oc.Run("get").Args("istag/wildfly:latest", "--template", "{{ .image.metadata.name }}").Output()
280+
g.By("verifying oc debug works with isimage (SHA-based lookup)")
281+
sha, err := oc.AsAdmin().Run("get").Args("istag", targetIS+":latest", "-n", targetNS, "--template", "{{ .image.metadata.name }}").Output()
278282
o.Expect(err).NotTo(o.HaveOccurred())
279-
out, err = oc.Run("debug").Args(fmt.Sprintf("isimage/wildfly@%s", sha), "-o", "yaml").Output()
283+
284+
img, err = oc.AsAdmin().Run("debug").Args(
285+
fmt.Sprintf("isimage/%s@%s", targetIS, strings.TrimSpace(sha)), "-n", targetNS, "-o", "jsonpath="+containerImage,
286+
).Output()
280287
o.Expect(err).NotTo(o.HaveOccurred())
281-
o.Expect(out).To(o.ContainSubstring("image: quay.io/wildfly/wildfly-centos7"))
288+
o.Expect(strings.TrimSpace(img)).To(o.MatchRegexp(digestPullMatch), "debug pod should reference the ImageStreamImage by digest (any registry host)")
282289
})
283290

284291
g.It("ensure that the label is set for node debug", func() {

0 commit comments

Comments
 (0)