@@ -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"
@@ -299,42 +298,28 @@ func (e importError) Error() string {
299
298
}
300
299
301
300
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" )
301
+ var is * imageapi.ImageStream
302
+ err := wait .Poll (1 * time .Second , 60 * time .Second , func () (bool , error ) {
303
+ var err error
304
+ is , err = o .isClient .Get (o .Name , metav1.GetOptions {ResourceVersion : resourceVersion })
305
+ if err != nil {
306
+ if errors .IsNotFound (err ) {
307
+ return false , nil
313
308
}
309
+ return false , err
310
+ }
311
+ annotation , ok := is .Annotations [imageapi .DockerImageRepositoryCheckAnnotation ]
312
+ if ! ok {
313
+ return false , nil
314
+ }
314
315
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 }
330
-
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
- }
316
+ if _ , err := time .Parse (time .RFC3339 , annotation ); err != nil {
317
+ return false , importError {annotation }
336
318
}
337
- }
319
+
320
+ return true , nil
321
+ })
322
+ return is , err
338
323
}
339
324
340
325
func (o * ImportImageOptions ) createImageImport () (* imageapi.ImageStream , * imageapi.ImageStreamImport , error ) {
0 commit comments