Repository: redhat-openshift-ecosystem/openshift-preflight
Pull request #320 (2021-10-29 21:25:45)

Modify OpenshiftEngine.GetImage() to receive the parent context


Patch:
diff --git a/certification/internal/cli/openshift.go b/certification/internal/cli/openshift.go
index ebe235b..c28d14f 100644
--- a/certification/internal/cli/openshift.go
+++ b/certification/internal/cli/openshift.go
@@ -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)
diff --git a/certification/internal/engine/openshift.go b/certification/internal/engine/openshift.go
index 0c3c19d..c1df985 100644
--- a/certification/internal/engine/openshift.go
+++ b/certification/internal/engine/openshift.go
@@ -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")
@@ -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
@@ -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
 	}
diff --git a/certification/internal/policy/operator/deployable_by_olm.go b/certification/internal/policy/operator/deployable_by_olm.go
index 66c5bad..a4c1e5e 100644
--- a/certification/internal/policy/operator/deployable_by_olm.go
+++ b/certification/internal/policy/operator/deployable_by_olm.go
@@ -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
 	}
@@ -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
 	}
@@ -434,8 +434,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 {


Test patch:
diff --git a/certification/internal/policy/operator/operator_suite_test.go b/certification/internal/policy/operator/operator_suite_test.go
index 50fb076..1ebd18b 100644
--- a/certification/internal/policy/operator/operator_suite_test.go
+++ b/certification/internal/policy/operator/operator_suite_test.go
@@ -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
 }
 
@@ -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
 }