// WaitForAnImageStream waits for an ImageStream to fulfill the isOK function func WaitForAnImageStream(client client.ImageStreamInterface, name string, isOK, isFailed func(*imageapi.ImageStream) bool) error { for { list, err := client.List(kapi.ListOptions{FieldSelector: fields.Set{"name": name}.AsSelector()}) if err != nil { return err } for i := range list.Items { if isOK(&list.Items[i]) { return nil } if isFailed(&list.Items[i]) { return fmt.Errorf("The image stream %q status is %q", name, list.Items[i].Annotations[imageapi.DockerImageRepositoryCheckAnnotation]) } } rv := list.ResourceVersion w, err := client.Watch(kapi.ListOptions{FieldSelector: fields.Set{"name": name}.AsSelector(), ResourceVersion: rv}) if err != nil { return err } defer w.Stop() for { val, ok := <-w.ResultChan() if !ok { // reget and re-watch break } if e, ok := val.Object.(*imageapi.ImageStream); ok { if isOK(e) { return nil } if isFailed(e) { return fmt.Errorf("The image stream %q status is %q", name, e.Annotations[imageapi.DockerImageRepositoryCheckAnnotation]) } } } } }