@@ -10,8 +10,7 @@ import (
10
10
11
11
"k8s.io/apimachinery/pkg/api/errors"
12
12
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13
- "k8s.io/apimachinery/pkg/fields"
14
- "k8s.io/apimachinery/pkg/watch"
13
+ "k8s.io/apimachinery/pkg/util/wait"
15
14
"k8s.io/kubernetes/pkg/api/legacyscheme"
16
15
kapi "k8s.io/kubernetes/pkg/apis/core"
17
16
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
@@ -256,8 +255,7 @@ func (o *ImportImageOptions) Run() error {
256
255
257
256
fmt .Fprintln (o .out , "Importing (ctrl+c to stop waiting) ..." )
258
257
259
- resourceVersion := stream .ResourceVersion
260
- updatedStream , err := o .waitForImport (resourceVersion )
258
+ updatedStream , err := o .waitForImport ()
261
259
if err != nil {
262
260
if _ , ok := err .(importError ); ok {
263
261
return err
@@ -298,43 +296,26 @@ func (e importError) Error() string {
298
296
return fmt .Sprintf ("unable to import image: %s" , e .annotation )
299
297
}
300
298
301
- func (o * ImportImageOptions ) waitForImport (resourceVersion string ) (* imageapi.ImageStream , error ) {
302
- streamWatch , err := o .isClient .Watch (metav1.ListOptions {FieldSelector : fields .OneTermEqualSelector ("metadata.name" , o .Name ).String (), ResourceVersion : resourceVersion })
303
- if err != nil {
304
- return nil , err
305
- }
306
- defer streamWatch .Stop ()
307
-
308
- for {
309
- select {
310
- case event , ok := <- streamWatch .ResultChan ():
311
- if ! ok {
312
- return nil , fmt .Errorf ("image stream watch ended prematurely" )
313
- }
314
-
315
- switch event .Type {
316
- case watch .Modified :
317
- s , ok := event .Object .(* imageapi.ImageStream )
318
- if ! ok {
319
- continue
320
- }
321
- annotation , ok := s .Annotations [imageapi .DockerImageRepositoryCheckAnnotation ]
322
- if ! ok {
323
- continue
324
- }
325
-
326
- if _ , err := time .Parse (time .RFC3339 , annotation ); err == nil {
327
- return s , nil
328
- }
329
- return nil , importError {annotation }
299
+ func (o * ImportImageOptions ) waitForImport () (* imageapi.ImageStream , error ) {
300
+ var is * imageapi.ImageStream
301
+ err := wait .PollImmediate (1 * time .Second , 60 * time .Second , func () (bool , error ) {
302
+ var err error
303
+ is , err = o .isClient .Get (o .Name , metav1.GetOptions {})
304
+ if err != nil {
305
+ return false , err
306
+ }
307
+ annotation , ok := is .Annotations [imageapi .DockerImageRepositoryCheckAnnotation ]
308
+ if ! ok {
309
+ return false , nil
310
+ }
330
311
331
- case watch .Deleted :
332
- return nil , fmt .Errorf ("the image stream was deleted" )
333
- case watch .Error :
334
- return nil , fmt .Errorf ("error watching image stream" )
335
- }
312
+ if _ , err := time .Parse (time .RFC3339 , annotation ); err != nil {
313
+ return false , importError {annotation }
336
314
}
337
- }
315
+
316
+ return true , nil
317
+ })
318
+ return is , err
338
319
}
339
320
340
321
func (o * ImportImageOptions ) createImageImport () (* imageapi.ImageStream , * imageapi.ImageStreamImport , error ) {
0 commit comments