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 openshift#13214
  • Loading branch information
Jan Wozniak committed May 10, 2018
1 parent 89d5bfb commit 43474fe
Showing 1 changed file with 20 additions and 35 deletions.
55 changes: 20 additions & 35 deletions pkg/oc/cli/cmd/importimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package cmd
import (
"fmt"
"io"
"k8s.io/apimachinery/pkg/util/wait"
"strings"
"time"

"github.com/spf13/cobra"

"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/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,28 @@ 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")
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{ResourceVersion: resourceVersion})
if err != nil {
if errors.IsNotFound(err) {
return false, nil
}
return false, err
}
annotation, ok := is.Annotations[imageapi.DockerImageRepositoryCheckAnnotation]
if !ok {
return false, nil
}

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}

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 43474fe

Please sign in to comment.