Skip to content

Commit

Permalink
Merge pull request #320 from samira-barouti/bugfix-context
Browse files Browse the repository at this point in the history
Modify OpenshiftEngine.GetImage() to receive the parent context
  • Loading branch information
bcrochet authored Nov 1, 2021
2 parents 7b0e262 + 491c9f6 commit 1a2ef8a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion certification/internal/cli/openshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type OpenshiftEngine interface {

GetCSV(ctx context.Context, name string, namespace string) (*operatorv1alpha1.ClusterServiceVersion, error)

GetImages() (map[string]struct{}, error)
GetImages(ctx context.Context) (map[string]struct{}, error)

CreateRoleBinding(ctx context.Context, data RoleBindingData, namespace string) (*rbacv1.RoleBinding, error)
GetRoleBinding(ctx context.Context, name string, namespace string) (*rbacv1.RoleBinding, error)
Expand Down
6 changes: 3 additions & 3 deletions certification/internal/engine/openshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func (oe *openshiftEngine) GetCSV(ctx context.Context, name string, namespace st
return csvClient.Get(ctx, name)
}

func (oe *openshiftEngine) GetImages() (map[string]struct{}, error) {
func (oe *openshiftEngine) GetImages(ctx context.Context) (map[string]struct{}, error) {
kubeconfig, err := ctrl.GetConfig()
if err != nil {
log.Error("could not get kubeconfig")
Expand All @@ -332,7 +332,7 @@ func (oe *openshiftEngine) GetImages() (map[string]struct{}, error) {
log.Error("unable to obtain k8s client: ", err)
return nil, err
}
pods, err := k8sClientset.CoreV1().Pods("").List(context.Background(), metav1.ListOptions{})
pods, err := k8sClientset.CoreV1().Pods("").List(ctx, metav1.ListOptions{})
if err != nil {
log.Error("could not retrieve pod list: ", err)
return nil, err
Expand All @@ -353,7 +353,7 @@ func (oe *openshiftEngine) GetImages() (map[string]struct{}, error) {
return nil, err
}
var imageStreamList imagestreamv1.ImageStreamList
if err := isClient.List(context.Background(), &imageStreamList, &crclient.ListOptions{}); err != nil {
if err := isClient.List(ctx, &imageStreamList, &crclient.ListOptions{}); err != nil {
log.Error("could not list image stream: ", err)
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions certification/internal/policy/operator/deployable_by_olm.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (p *DeployableByOlmCheck) Validate(bundleRef certification.ImageReference)
ctx := context.Background()

// gather the list of registry and pod images
beforeOperatorImages, err := p.getImages()
beforeOperatorImages, err := p.getImages(ctx)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -91,7 +91,7 @@ func (p *DeployableByOlmCheck) Validate(bundleRef certification.ImageReference)
return false, err
}

afterOperatorImages, err := p.getImages()
afterOperatorImages, err := p.getImages(ctx)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -435,8 +435,8 @@ func (p *DeployableByOlmCheck) readFileAsByteArray(filename string) ([]byte, err
return content, nil
}

func (p *DeployableByOlmCheck) getImages() (map[string]struct{}, error) {
return p.OpenshiftEngine.GetImages()
func (p *DeployableByOlmCheck) getImages(ctx context.Context) (map[string]struct{}, error) {
return p.OpenshiftEngine.GetImages(ctx)
}

func (p *DeployableByOlmCheck) Name() string {
Expand Down
4 changes: 2 additions & 2 deletions certification/internal/policy/operator/operator_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (foe FakeOpenshiftEngine) GetCSV(ctx context.Context, name, namespace strin
}, nil
}

func (foe FakeOpenshiftEngine) GetImages() (map[string]struct{}, error) {
func (foe FakeOpenshiftEngine) GetImages(ctx context.Context) (map[string]struct{}, error) {
return map[string]struct{}{}, nil
}

Expand Down Expand Up @@ -431,7 +431,7 @@ func (foe BadOpenshiftEngine) GetCSV(ctx context.Context, name, namespace string
return nil, nil
}

func (foe BadOpenshiftEngine) GetImages() (map[string]struct{}, error) {
func (foe BadOpenshiftEngine) GetImages(ctx context.Context) (map[string]struct{}, error) {
return nil, nil
}

Expand Down

0 comments on commit 1a2ef8a

Please sign in to comment.