Skip to content

Commit

Permalink
oc import-image: poll on IS to respect resourceNames RBAC
Browse files Browse the repository at this point in the history
`watch` doesn't work with RBAC `resourceNames` as well as `get`. Changing
the `waitForImport` to poll a `get` instead.

fixes #13214
  • Loading branch information
Jan Wozniak committed May 10, 2018
1 parent 89d5bfb commit 133b79b
Showing 1 changed file with 18 additions and 36 deletions.
54 changes: 18 additions & 36 deletions pkg/oc/cli/cmd/importimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (

"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/kubernetes/pkg/api/legacyscheme"
kapi "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
Expand Down Expand Up @@ -299,42 +298,25 @@ func (e importError) Error() string {
}

func (o *ImportImageOptions) waitForImport(resourceVersion string) (*imageapi.ImageStream, error) {
streamWatch, err := o.isClient.Watch(metav1.ListOptions{FieldSelector: fields.OneTermEqualSelector("metadata.name", o.Name).String(), ResourceVersion: resourceVersion})
if err != nil {
return nil, err
}
defer streamWatch.Stop()

for {
select {
case event, ok := <-streamWatch.ResultChan():
if !ok {
return nil, fmt.Errorf("image stream watch ended prematurely")
}

switch event.Type {
case watch.Modified:
s, ok := event.Object.(*imageapi.ImageStream)
if !ok {
continue
}
annotation, ok := s.Annotations[imageapi.DockerImageRepositoryCheckAnnotation]
if !ok {
continue
}

if _, err := time.Parse(time.RFC3339, annotation); err == nil {
return s, nil
}
return nil, importError{annotation}
var is *imageapi.ImageStream
err := wait.Poll(1*time.Second, 60*time.Second, func() (bool, error) {
var err error
is, err = o.isClient.Get(o.Name, metav1.GetOptions{})
if err != nil {
return false, err
}
annotation, ok := is.Annotations[imageapi.DockerImageRepositoryCheckAnnotation]
if !ok {
return false, nil
}

case watch.Deleted:
return nil, fmt.Errorf("the image stream was deleted")
case watch.Error:
return nil, fmt.Errorf("error watching image stream")
}
if _, err := time.Parse(time.RFC3339, annotation); err != nil {
return false, importError{annotation}
}
}

return true, nil
})
return is, err
}

func (o *ImportImageOptions) createImageImport() (*imageapi.ImageStream, *imageapi.ImageStreamImport, error) {
Expand Down

0 comments on commit 133b79b

Please sign in to comment.