@@ -234,10 +234,69 @@ func processScanError(log string) error {
234
234
return fmt .Errorf (log )
235
235
}
236
236
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
+
237
296
// WaitForOpenShiftNamespaceImageStreams waits for the standard set of imagestreams to be imported
238
297
func WaitForOpenShiftNamespaceImageStreams (oc * CLI ) error {
239
298
ctx := context .Background ()
240
- langs := []string {"ruby" , " nodejs" , "perl" , "php" , "python" , "mysql" , "postgresql" , "jenkins" }
299
+ langs := []string {"nodejs" , "perl" , "php" , "python" , "mysql" , "postgresql" , "jenkins" }
241
300
e2e .Logf ("waiting for image ecoystem imagestreams to be imported" )
242
301
for _ , lang := range langs {
243
302
err := WaitForSamplesImagestream (ctx , oc , lang )
@@ -275,7 +334,7 @@ func WaitForSamplesImagestream(ctx context.Context, oc *CLI, imagestream string)
275
334
if retried {
276
335
return false , nil
277
336
}
278
- return checkOpenShiftNamespaceImageStreamImported (ctx , oc , imagestream , registryHostname )
337
+ return checkNamespaceImageStreamImported (ctx , oc , imagestream , registryHostname , "openshift" )
279
338
})
280
339
// pollErr will be not nil if there was an immediate error, or we timed out.
281
340
if pollErr == nil {
@@ -295,6 +354,12 @@ func WaitForSamplesImagestream(ctx context.Context, oc *CLI, imagestream string)
295
354
return pollErr
296
355
}
297
356
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
+
298
363
// retrySamplesImagestreamImportIfNeeded immediately retries an import for the provided imagestream if:
299
364
//
300
365
// 1) The imagestream is managed by the samples operator, AND
@@ -361,11 +426,11 @@ func retrySamplesImagestreamImportIfNeeded(ctx context.Context, oc *CLI, imagest
361
426
return false , nil
362
427
}
363
428
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.
365
430
// 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 {})
369
434
if err != nil {
370
435
return false , processScanError (fmt .Sprintf ("failed to get imagestream: %v" , err ))
371
436
}
@@ -374,9 +439,9 @@ func checkOpenShiftNamespaceImageStreamImported(ctx context.Context, oc *CLI, im
374
439
return false , nil
375
440
}
376
441
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 )
378
443
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 )
380
445
return false , nil
381
446
}
382
447
}
0 commit comments