Skip to content

Commit eca6b07

Browse files
Merge pull request #28307 from eggfoobar/fix-image-registry-no-cap
OCPBUGS-20205: feat: added support for ImageRegistry capability
2 parents 0098195 + 50dbd82 commit eca6b07

File tree

9 files changed

+214
-39
lines changed

9 files changed

+214
-39
lines changed

pkg/clioptions/clusterdiscovery/provider.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/onsi/ginkgo/v2"
99
"github.com/onsi/gomega"
1010

11+
"github.com/openshift/origin/test/extended/util/image"
1112
e2e "k8s.io/kubernetes/test/e2e/framework"
1213

1314
exutil "github.com/openshift/origin/test/extended/util"
@@ -67,6 +68,16 @@ func InitializeTestFramework(context *e2e.TestContextType, config *ClusterConfig
6768

6869
// IPFamily constants are taken from kube e2e and used by tests
6970
context.IPFamily = config.IPFamily
71+
72+
imageStreamString, _, err := exutil.NewCLIWithoutNamespace("").AsAdmin().Run("adm", "release", "info", `-ojsonpath={.references}`).Outputs()
73+
if err != nil {
74+
return err
75+
}
76+
77+
if err := image.InitializeReleasePullSpecString(imageStreamString, config.HasNoOptionalCapabilities); err != nil {
78+
return err
79+
}
80+
7081
return nil
7182
}
7283

pkg/monitortests/network/disruptionpodnetwork/monitortest.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ func (pna *podNetworkAvalibility) StartCollection(ctx context.Context, adminREST
178178
pna.targetService = service
179179

180180
hostNetworkTargetDeployment.Spec.Replicas = &numNodes
181+
hostNetworkTargetDeployment.Spec.Template.Spec.Containers[0].Image = image.LimitedShellImage()
181182
if _, err := pna.kubeClient.AppsV1().Deployments(pna.namespaceName).Create(context.Background(), hostNetworkTargetDeployment, metav1.CreateOptions{}); err != nil {
182183
return err
183184
}

test/extended/cli/debug.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"k8s.io/apimachinery/pkg/util/wait"
1111
admissionapi "k8s.io/pod-security-admission/api"
1212

13+
configv1 "github.com/openshift/api/config/v1"
1314
exutil "github.com/openshift/origin/test/extended/util"
1415
)
1516

@@ -181,7 +182,10 @@ spec:
181182
})
182183

183184
g.It("ensure it works with image streams [apigroup:image.openshift.io]", func() {
184-
err := oc.Run("create").Args("-f", imageStreamsCentos).Execute()
185+
hasImageRegistry, err := exutil.IsCapabilityEnabled(oc, configv1.ClusterVersionCapabilityImageRegistry)
186+
o.Expect(err).NotTo(o.HaveOccurred())
187+
188+
err = oc.Run("create").Args("-f", imageStreamsCentos).Execute()
185189
o.Expect(err).NotTo(o.HaveOccurred())
186190
err = wait.Poll(cliInterval, cliTimeout, func() (bool, error) {
187191
err := oc.Run("get").Args("imagestreamtags", "wildfly:latest").Execute()
@@ -190,9 +194,14 @@ spec:
190194
o.Expect(err).NotTo(o.HaveOccurred())
191195

192196
var out string
197+
var resolvedImageMatcher = o.MatchRegexp("image:.*oc-debug-.*/wildfly@sha256")
198+
if !hasImageRegistry {
199+
resolvedImageMatcher = o.ContainSubstring("image: quay.io/wildfly/wildfly-centos7")
200+
}
201+
193202
out, err = oc.Run("debug").Args("istag/wildfly:latest", "-o", "yaml").Output()
194203
o.Expect(err).NotTo(o.HaveOccurred())
195-
o.Expect(out).To(o.MatchRegexp("image:.*oc-debug-.*/wildfly@sha256"))
204+
o.Expect(out).To(resolvedImageMatcher)
196205

197206
var sha string
198207
sha, err = oc.Run("get").Args("istag/wildfly:latest", "--template", "{{ .image.metadata.name }}").Output()

test/extended/images/extract.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ import (
1515
k8simage "k8s.io/kubernetes/test/utils/image"
1616
admissionapi "k8s.io/pod-security-admission/api"
1717

18+
configv1 "github.com/openshift/api/config/v1"
1819
imageapi "github.com/openshift/api/image/v1"
1920
imageclientset "github.com/openshift/client-go/image/clientset/versioned"
2021
exutil "github.com/openshift/origin/test/extended/util"
22+
"github.com/openshift/origin/test/extended/util/image"
2123
)
2224

2325
var _ = g.Describe("[sig-imageregistry][Feature:ImageExtract] Image extract", func() {
@@ -35,12 +37,23 @@ var _ = g.Describe("[sig-imageregistry][Feature:ImageExtract] Image extract", fu
3537
oc = exutil.NewCLIWithPodSecurityLevel("image-extract", admissionapi.LevelBaseline)
3638

3739
g.It("should extract content from an image [apigroup:image.openshift.io]", func() {
40+
hasImageRegistry, err := exutil.IsCapabilityEnabled(oc, configv1.ClusterVersionCapabilityImageRegistry)
41+
o.Expect(err).NotTo(o.HaveOccurred())
3842
is, err := oc.ImageClient().ImageV1().ImageStreams("openshift").Get(context.Background(), "tools", metav1.GetOptions{})
3943
o.Expect(err).NotTo(o.HaveOccurred())
40-
o.Expect(is.Status.DockerImageRepository).NotTo(o.BeEmpty(), "registry not yet configured?")
41-
registry := strings.Split(is.Status.DockerImageRepository, "/")[0]
4244

4345
ns = oc.Namespace()
46+
extractImage := image.ShellImage()
47+
48+
// If ImageRegistry is present, we expect DockerImageRepository to have a value
49+
// and we create the registry url for ImageStream extracting, otherwise we use
50+
// the ShellImage()
51+
if hasImageRegistry {
52+
o.Expect(is.Status.DockerImageRepository).NotTo(o.BeEmpty(), "registry not yet configured?")
53+
registry := strings.Split(is.Status.DockerImageRepository, "/")[0]
54+
extractImage = fmt.Sprintf("%s/%s/1:tools", registry, ns)
55+
}
56+
4457
cli := e2epod.PodClientNS(oc.KubeFramework(), ns)
4558
client := imageclientset.NewForConfigOrDie(oc.UserConfig()).ImageV1()
4659

@@ -74,35 +87,30 @@ var _ = g.Describe("[sig-imageregistry][Feature:ImageExtract] Image extract", fu
7487
o.Expect(img.Status.Status).To(o.Equal("Success"), fmt.Sprintf("imagestreamimport status for spec.image[%d] (message: %s)", i, img.Status.Message))
7588
}
7689

77-
// toolsLayers := isi.Status.Images[0].Image.DockerImageLayers
78-
// toolsLen := len(toolsLayers)
79-
// mysqlLayers := isi.Status.Images[1].Image.DockerImageLayers
80-
// mysqlLen := len(mysqlLayers)
81-
8290
pod := cli.Create(context.TODO(), cliPodWithPullSecret(oc, heredoc.Docf(`
8391
set -x
8492
8593
# command exits if directory doesn't exist
86-
! oc image extract --insecure %[2]s/%[1]s/1:tools --path=/:/tmp/doesnotexist
94+
! oc image extract --insecure %[1]s --path=/:/tmp/doesnotexist
8795
# command exits if directory isn't empty
88-
! oc image extract --insecure %[2]s/%[1]s/1:tools --path=/:/
96+
! oc image extract --insecure %[1]s --path=/:/
8997
9098
# extract a directory to a directory, verify the contents
9199
mkdir -p /tmp/test
92-
oc image extract --insecure %[2]s/%[1]s/1:tools --path=/etc/cron.d/:/tmp/test/
100+
oc image extract --insecure %[1]s --path=/etc/cron.d/:/tmp/test/
93101
[ -f /tmp/test/0hourly ] && grep root /tmp/test/0hourly
94102
95103
# extract multiple individual files
96104
mkdir -p /tmp/test2
97-
oc image extract --insecure %[2]s/%[1]s/1:tools --path=/etc/shadow:/tmp/test2 --path=/etc/system-release:/tmp/test2
105+
oc image extract --insecure %[1]s --path=/etc/shadow:/tmp/test2 --path=/etc/system-release:/tmp/test2
98106
[ -f /tmp/test2/shadow ] && [ -L /tmp/test2/system-release ]
99107
100108
# extract a single file to the current directory
101109
mkdir -p /tmp/test3
102110
cd /tmp/test3
103-
oc image extract --insecure %[2]s/%[1]s/1:tools --file=/etc/shadow
111+
oc image extract --insecure %[1]s --file=/etc/shadow
104112
[ -f /tmp/test3/shadow ]
105-
`, ns, registry)))
113+
`, extractImage)))
106114
cli.WaitForSuccess(context.TODO(), pod.Name, podStartupTimeout)
107115
})
108116
})

test/extended/images/resolve.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
o "github.com/onsi/gomega"
1010

1111
appsv1 "github.com/openshift/api/apps/v1"
12+
configv1 "github.com/openshift/api/config/v1"
1213
kappsv1 "k8s.io/api/apps/v1"
1314
kbatchv1 "k8s.io/api/batch/v1"
1415
kapiv1 "k8s.io/api/core/v1"
@@ -28,7 +29,10 @@ var _ = g.Describe("[sig-imageregistry][Feature:ImageLookup] Image policy", func
2829
ctx := context.Background()
2930

3031
g.It("should update standard Kube object image fields when local names are on [apigroup:image.openshift.io]", func() {
31-
err := oc.Run("tag").Args(k8simage.GetE2EImage(k8simage.BusyBox), "busybox:latest").Execute()
32+
hasImageRegistry, err := exutil.IsCapabilityEnabled(oc, configv1.ClusterVersionCapabilityImageRegistry)
33+
o.Expect(err).NotTo(o.HaveOccurred())
34+
35+
err = oc.Run("tag").Args(k8simage.GetE2EImage(k8simage.BusyBox), "busybox:latest").Execute()
3236
o.Expect(err).NotTo(o.HaveOccurred())
3337
err = oc.Run("set", "image-lookup").Args("busybox").Execute()
3438
o.Expect(err).NotTo(o.HaveOccurred())
@@ -68,8 +72,15 @@ var _ = g.Describe("[sig-imageregistry][Feature:ImageLookup] Image policy", func
6872
g.Skip("default image resolution is not configured, can't verify pod resolution")
6973
}
7074

75+
// When ImageRegistry is not present this should not get resolved and will remain
76+
// and Attempt resolve meaning it will not get changed by the admission plugin
77+
unknownImageSuffix := "busybox:unknown"
78+
if hasImageRegistry {
79+
unknownImageSuffix = "/" + oc.Namespace() + "/" + unknownImageSuffix
80+
}
81+
7182
o.Expect(pod.Spec.Containers[0].Image).To(o.Equal(internalImageReference))
72-
o.Expect(pod.Spec.Containers[1].Image).To(o.HaveSuffix("/" + oc.Namespace() + "/busybox:unknown"))
83+
o.Expect(pod.Spec.Containers[1].Image).To(o.HaveSuffix(unknownImageSuffix))
7384
defer func() { oc.KubeClient().CoreV1().Pods(oc.Namespace()).Delete(ctx, pod.Name, metav1.DeleteOptions{}) }()
7485

7586
// replica sets should auto replace local references
@@ -219,7 +230,10 @@ var _ = g.Describe("[sig-imageregistry][Feature:ImageLookup] Image policy", func
219230
})
220231

221232
g.It("should perform lookup when the object has the resolve-names annotation [apigroup:image.openshift.io]", func() {
222-
err := oc.Run("tag").Args(k8simage.GetE2EImage(k8simage.BusyBox), "busybox:latest").Execute()
233+
hasImageRegistry, err := exutil.IsCapabilityEnabled(oc, configv1.ClusterVersionCapabilityImageRegistry)
234+
o.Expect(err).NotTo(o.HaveOccurred())
235+
236+
err = oc.Run("tag").Args(k8simage.GetE2EImage(k8simage.BusyBox), "busybox:latest").Execute()
223237
o.Expect(err).NotTo(o.HaveOccurred())
224238

225239
var internalImageReference string
@@ -258,8 +272,15 @@ var _ = g.Describe("[sig-imageregistry][Feature:ImageLookup] Image policy", func
258272
g.Skip("default image resolution is not configured, can't verify pod resolution")
259273
}
260274

275+
// When ImageRegistry is not present this should not get resolved and will remain
276+
// and Attempt resolve meaning it will not get changed by the admission plugin
277+
unknownImageSuffix := "busybox:unknown"
278+
if hasImageRegistry {
279+
unknownImageSuffix = "/" + oc.Namespace() + "/" + unknownImageSuffix
280+
}
281+
261282
o.Expect(pod.Spec.Containers[0].Image).To(o.Equal(internalImageReference))
262-
o.Expect(pod.Spec.Containers[1].Image).To(o.HaveSuffix("/" + oc.Namespace() + "/busybox:unknown"))
283+
o.Expect(pod.Spec.Containers[1].Image).To(o.HaveSuffix(unknownImageSuffix))
263284

264285
g.By("auto replacing local references on ReplicaSets")
265286
rs, err := oc.KubeClient().AppsV1().ReplicaSets(oc.Namespace()).Create(ctx, &kappsv1.ReplicaSet{

test/extended/util/annotate/generated/zz_generated.annotations.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/extended/util/annotate/rules.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,15 @@ var (
231231
"[Skipped:NoOptionalCapabilities]": {
232232
// This test requires a valid console url which doesn't exist when the optional console capability is disabled.
233233
`\[sig-cli\] oc basics can show correct whoami result with console`,
234+
235+
// Image Registry Skips:
236+
// Requires ImageRegistry to upload appended images
237+
`\[sig-imageregistry\]\[Feature:ImageAppend\] Image append should create images by appending them`,
238+
// Requires ImageRegistry to redirect blob pull
239+
`\[sig-imageregistry\] Image registry \[apigroup:route.openshift.io\] should redirect on blob pull`,
240+
// Requires ImageRegistry service to be active for OCM to be able to create pull secrets
241+
`\[sig-devex\]\[Feature:OpenShiftControllerManager\] TestAutomaticCreationOfPullSecrets \[apigroup:config.openshift.io\]`,
242+
`\[sig-devex\]\[Feature:OpenShiftControllerManager\] TestDockercfgTokenDeletedController \[apigroup:image.openshift.io\]`,
234243
},
235244
}
236245
)

test/extended/util/framework.go

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,25 @@ func processScanError(log string) error {
240240
// WaitForOpenShiftNamespaceImageStreams waits for the standard set of imagestreams to be imported
241241
func WaitForOpenShiftNamespaceImageStreams(oc *CLI) error {
242242
ctx := context.Background()
243-
langs := []string{"ruby", "nodejs", "perl", "php", "python", "mysql", "postgresql", "jenkins"}
243+
images := []string{"ruby", "nodejs", "perl", "php", "python", "mysql", "postgresql", "jenkins"}
244+
245+
hasSamplesOperator, err := IsCapabilityEnabled(oc, configv1.ClusterVersionCapabilityOpenShiftSamples)
246+
if err != nil {
247+
return err
248+
}
249+
// Check to see if we have ImageRegistry and SamplesOperator enabled
250+
hasImageRegistry, err := IsCapabilityEnabled(oc, configv1.ClusterVersionCapabilityImageRegistry)
251+
if err != nil {
252+
return err
253+
}
254+
255+
if !hasSamplesOperator {
256+
images = []string{"cli", "tools", "tests", "installer"}
257+
}
258+
244259
e2e.Logf("waiting for image ecoystem imagestreams to be imported")
245-
for _, lang := range langs {
246-
err := WaitForSamplesImagestream(ctx, oc, lang)
260+
for _, image := range images {
261+
err := WaitForSamplesImagestream(ctx, oc, image, hasImageRegistry, hasSamplesOperator)
247262
if err != nil {
248263
DumpSampleOperator(oc)
249264
return err
@@ -258,11 +273,15 @@ func WaitForOpenShiftNamespaceImageStreams(oc *CLI) error {
258273
// managed by the samples operator, and therefore will not be retried.
259274
//
260275
// This will wait up to 150 seconds for the referenced imagestream to finish importing.
261-
func WaitForSamplesImagestream(ctx context.Context, oc *CLI, imagestream string) error {
262-
// First wait for the internal registry hostname to be published
263-
registryHostname, err := WaitForInternalRegistryHostname(oc)
264-
if err != nil {
265-
return err
276+
func WaitForSamplesImagestream(ctx context.Context, oc *CLI, imagestream string, imageRegistryEnabled, openshiftSamplesEnabled bool) error {
277+
var registryHostname string
278+
var err error
279+
280+
if imageRegistryEnabled {
281+
registryHostname, err = WaitForInternalRegistryHostname(oc)
282+
if err != nil {
283+
return err
284+
}
266285
}
267286

268287
var retried bool
@@ -271,12 +290,14 @@ func WaitForSamplesImagestream(ctx context.Context, oc *CLI, imagestream string)
271290
// Based on a sampling of CI tests, imagestream imports from registry.redhat.io can take up to 2 minutes to complete.
272291
// Imports which take longer generally indicate that there is a performance regression or outage in the container registry.
273292
pollErr := wait.Poll(10*time.Second, 150*time.Second, func() (bool, error) {
274-
retried, err = retrySamplesImagestreamImportIfNeeded(ctx, oc, imagestream)
275-
if err != nil {
276-
return false, err
277-
}
278-
if retried {
279-
return false, nil
293+
if openshiftSamplesEnabled {
294+
retried, err = retrySamplesImagestreamImportIfNeeded(ctx, oc, imagestream)
295+
if err != nil {
296+
return false, err
297+
}
298+
if retried {
299+
return false, nil
300+
}
280301
}
281302
return checkOpenShiftNamespaceImageStreamImported(ctx, oc, imagestream, registryHostname)
282303
})
@@ -2205,3 +2226,16 @@ func collectConfigManifestsFromDir(configManifestsDir string) (error, []runtime.
22052226

22062227
return err, objects
22072228
}
2229+
2230+
func IsCapabilityEnabled(oc *CLI, cap configv1.ClusterVersionCapability) (bool, error) {
2231+
cv, err := oc.AdminConfigClient().ConfigV1().ClusterVersions().Get(context.Background(), "version", metav1.GetOptions{})
2232+
if err != nil {
2233+
return false, err
2234+
}
2235+
for _, capability := range cv.Status.Capabilities.EnabledCapabilities {
2236+
if capability == cap {
2237+
return true, nil
2238+
}
2239+
}
2240+
return false, nil
2241+
}

0 commit comments

Comments
 (0)