@@ -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,25 @@ 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" )
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 }
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 {})
305
+ if err != nil {
306
+ return false , err
307
+ }
308
+ annotation , ok := is .Annotations [imageapi .DockerImageRepositoryCheckAnnotation ]
309
+ if ! ok {
310
+ return false , nil
311
+ }
330
312
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
- }
313
+ if _ , err := time .Parse (time .RFC3339 , annotation ); err != nil {
314
+ return false , importError {annotation }
336
315
}
337
- }
316
+
317
+ return true , nil
318
+ })
319
+ return is , err
338
320
}
339
321
340
322
func (o * ImportImageOptions ) createImageImport () (* imageapi.ImageStream , * imageapi.ImageStreamImport , error ) {
0 commit comments