Skip to content

Commit daedb2e

Browse files
Merge pull request #29080 from openshift-cherrypick-robot/cherry-pick-29007-to-release-4.12
[release-4.12] OCPBUGS-41585: Removes dependency on samples operator images
2 parents 7b7d4ef + 033512e commit daedb2e

File tree

4 files changed

+81
-14
lines changed

4 files changed

+81
-14
lines changed

Diff for: test/extended/builds/contextdir.go

+2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ var _ = g.Describe("[sig-builds][Feature:Builds][Slow] builds with a context dir
4747
g.Describe("s2i context directory build", func() {
4848
g.It(fmt.Sprintf("should s2i build an application using a context directory [apigroup:build.openshift.io]"), func() {
4949

50+
exutil.WaitForImageStreamImport(oc)
5051
exutil.WaitForOpenShiftNamespaceImageStreams(oc)
52+
5153
g.By(fmt.Sprintf("calling oc create -f %q", appFixture))
5254
err := oc.Run("create").Args("-f", appFixture).Execute()
5355
o.Expect(err).NotTo(o.HaveOccurred())

Diff for: test/extended/testdata/bindata.go

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: test/extended/testdata/builds/test-context-build.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"git": {
4343
"uri":"https://github.com/sclorg/s2i-ruby-container"
4444
},
45-
"contextDir": "2.7/test/puma-test-app"
45+
"contextDir": "3.3/test/puma-test-app"
4646
},
4747
"strategy": {
4848
"type": "Source",
@@ -54,8 +54,8 @@
5454
}
5555
],
5656
"from": {
57-
"kind": "DockerImage",
58-
"name": "image-registry.openshift-image-registry.svc:5000/openshift/ruby:2.7-ubi8"
57+
"kind": "ImageStreamTag",
58+
"name": "ruby:latest"
5959
}
6060
}
6161
},

Diff for: test/extended/util/framework.go

+73-8
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,69 @@ func processScanError(log string) error {
234234
return fmt.Errorf(log)
235235
}
236236

237+
// getImageStreamObj returns the updated spec for imageStream object
238+
func getImageStreamObj(imageStreamName, imageRef string) *imagev1.ImageStream {
239+
imageStream := &imagev1.ImageStream{
240+
ObjectMeta: metav1.ObjectMeta{Name: imageStreamName},
241+
Spec: imagev1.ImageStreamSpec{
242+
LookupPolicy: imagev1.ImageLookupPolicy{Local: true},
243+
DockerImageRepository: imageRef,
244+
Tags: []imagev1.TagReference{{
245+
Name: "latest",
246+
ImportPolicy: imagev1.TagImportPolicy{
247+
ImportMode: imagev1.ImportModePreserveOriginal,
248+
},
249+
}},
250+
},
251+
Status: imagev1.ImageStreamStatus{
252+
DockerImageRepository: imageRef,
253+
Tags: []imagev1.NamedTagEventList{{
254+
Tag: "latest",
255+
}},
256+
},
257+
}
258+
return imageStream
259+
}
260+
261+
// WaitForImageStreamImport creates & waits for custom ruby imageStream to be available in current namespace
262+
// TODO: To eliminate the dependency on OpenShift Samples Operator in future,
263+
// WaitForImageStreamImport should be a replacement of WaitForOpenShiftNamespaceImageStreams func
264+
func WaitForImageStreamImport(oc *CLI) error {
265+
ctx := context.Background()
266+
var registryHostname string
267+
268+
// TODO: Reference an image from registry.redhat.io
269+
images := map[string]string{
270+
"ruby": "registry.access.redhat.com/ubi8/ruby-33",
271+
}
272+
273+
// Create custom imageStream using `oc import-image`
274+
e2e.Logf("waiting for imagestreams to be imported")
275+
for imageStreamName, imageRef := range images {
276+
err := CustomImageStream(oc, getImageStreamObj(imageStreamName, imageRef))
277+
if err != nil {
278+
e2e.Logf("failed while creating custom imageStream")
279+
return err
280+
}
281+
282+
// Wait for imageRegistry to be ready
283+
pollErr := wait.PollUntilWithContext(ctx, 10*time.Second, func(context.Context) (bool, error) {
284+
return checkNamespaceImageStreamImported(ctx, oc, imageStreamName, registryHostname, oc.Namespace())
285+
})
286+
// pollErr will be not nil if there was an immediate error, or we timed out.
287+
if pollErr == nil {
288+
return nil
289+
}
290+
DumpImageStream(oc, oc.Namespace(), imageStreamName)
291+
return pollErr
292+
}
293+
return nil
294+
}
295+
237296
// WaitForOpenShiftNamespaceImageStreams waits for the standard set of imagestreams to be imported
238297
func WaitForOpenShiftNamespaceImageStreams(oc *CLI) error {
239298
ctx := context.Background()
240-
langs := []string{"ruby", "nodejs", "perl", "php", "python", "mysql", "postgresql", "jenkins"}
299+
langs := []string{"nodejs", "perl", "php", "python", "mysql", "postgresql", "jenkins"}
241300
e2e.Logf("waiting for image ecoystem imagestreams to be imported")
242301
for _, lang := range langs {
243302
err := WaitForSamplesImagestream(ctx, oc, lang)
@@ -275,7 +334,7 @@ func WaitForSamplesImagestream(ctx context.Context, oc *CLI, imagestream string)
275334
if retried {
276335
return false, nil
277336
}
278-
return checkOpenShiftNamespaceImageStreamImported(ctx, oc, imagestream, registryHostname)
337+
return checkNamespaceImageStreamImported(ctx, oc, imagestream, registryHostname, "openshift")
279338
})
280339
// pollErr will be not nil if there was an immediate error, or we timed out.
281340
if pollErr == nil {
@@ -295,6 +354,12 @@ func WaitForSamplesImagestream(ctx context.Context, oc *CLI, imagestream string)
295354
return pollErr
296355
}
297356

357+
// CustomImageStream uses the provided imageStreamObj reference to create an imagestream with the given name in the given namespace.
358+
func CustomImageStream(oc *CLI, imageStream *imagev1.ImageStream) error {
359+
_, err := oc.ImageClient().ImageV1().ImageStreams(oc.Namespace()).Create(context.Background(), imageStream, metav1.CreateOptions{})
360+
return err
361+
}
362+
298363
// retrySamplesImagestreamImportIfNeeded immediately retries an import for the provided imagestream if:
299364
//
300365
// 1) The imagestream is managed by the samples operator, AND
@@ -361,11 +426,11 @@ func retrySamplesImagestreamImportIfNeeded(ctx context.Context, oc *CLI, imagest
361426
return false, nil
362427
}
363428

364-
// checkOpenShiftNamespaceImageStreamImported checks if the provided imagestream has been imported into the openshift namespace.
429+
// checkNamespaceImageStreamImported checks if the provided imagestream has been imported into the specified namespace.
365430
// Returns true if status has been reported on all tags for the imagestream.
366-
func checkOpenShiftNamespaceImageStreamImported(ctx context.Context, oc *CLI, imagestream string, registryHostname string) (bool, error) {
367-
e2e.Logf("checking imagestream %s/%s", "openshift", imagestream)
368-
is, err := oc.ImageClient().ImageV1().ImageStreams("openshift").Get(ctx, imagestream, metav1.GetOptions{})
431+
func checkNamespaceImageStreamImported(ctx context.Context, oc *CLI, imagestream, registryHostname, namespace string) (bool, error) {
432+
e2e.Logf("checking imagestream %s/%s", namespace, imagestream)
433+
is, err := oc.ImageClient().ImageV1().ImageStreams(namespace).Get(ctx, imagestream, metav1.GetOptions{})
369434
if err != nil {
370435
return false, processScanError(fmt.Sprintf("failed to get imagestream: %v", err))
371436
}
@@ -374,9 +439,9 @@ func checkOpenShiftNamespaceImageStreamImported(ctx context.Context, oc *CLI, im
374439
return false, nil
375440
}
376441
for _, tag := range is.Spec.Tags {
377-
e2e.Logf("checking tag %s for imagestream %s/%s", tag.Name, "openshift", imagestream)
442+
e2e.Logf("checking tag %s for imagestream %s/%s", tag.Name, namespace, imagestream)
378443
if _, found := imageutil.StatusHasTag(is, tag.Name); !found {
379-
e2e.Logf("no status for imagestreamtag %s/%s:%s", "openshift", imagestream, tag.Name)
444+
e2e.Logf("no status for imagestreamtag %s/%s:%s", namespace, imagestream, tag.Name)
380445
return false, nil
381446
}
382447
}

0 commit comments

Comments
 (0)