diff --git a/changelog/fragments/5285_bugfix.yaml b/changelog/fragments/5285_bugfix.yaml new file mode 100644 index 00000000000..15c7d646549 --- /dev/null +++ b/changelog/fragments/5285_bugfix.yaml @@ -0,0 +1,16 @@ +# entries is a list of entries to include in +# release notes and/or the migration guide +entries: + - description: > + Expose flags for storage and untar images to fix the issue 5285 + + # kind is one of: + # - addition + # - change + # - deprecation + # - removal + # - bugfix + kind: "bugfix" + + # Is this a breaking change? + breaking: false diff --git a/internal/cmd/operator-sdk/scorecard/cmd.go b/internal/cmd/operator-sdk/scorecard/cmd.go index 481c3e45d78..45dc7a3a9d3 100644 --- a/internal/cmd/operator-sdk/scorecard/cmd.go +++ b/internal/cmd/operator-sdk/scorecard/cmd.go @@ -49,6 +49,8 @@ type scorecardCmd struct { list bool skipCleanup bool waitTime time.Duration + storageImage string + untarImage string testOutput string } @@ -86,6 +88,12 @@ If the argument holds an image tag, it must be present remotely.`, "Disable resource cleanup after tests are run") scorecardCmd.Flags().DurationVarP(&c.waitTime, "wait-time", "w", 30*time.Second, "seconds to wait for tests to complete. Example: 35s") + scorecardCmd.Flags().StringVarP(&c.storageImage, "storage-image", "b", + "docker.io/library/busybox@sha256:c71cb4f7e8ececaffb34037c2637dc86820e4185100e18b4d02d613a9bd772af", + "Storage image to use") + scorecardCmd.Flags().StringVarP(&c.untarImage, "untar-image", "u", + "registry.access.redhat.com/ubi8@sha256:910f6bc0b5ae9b555eb91b88d28d568099b060088616eba2867b07ab6ea457c7", + "Untar image to use") scorecardCmd.Flags().StringVarP(&c.testOutput, "test-output", "t", "test-output", "Test output directory.") @@ -208,6 +216,8 @@ func (c *scorecardCmd) run() (err error) { BundlePath: c.bundle, TestOutput: c.testOutput, BundleMetadata: metadata, + StorageImage: c.storageImage, + UntarImage: c.untarImage, } // Only get the client if running tests. diff --git a/internal/cmd/operator-sdk/scorecard/cmd_test.go b/internal/cmd/operator-sdk/scorecard/cmd_test.go index 5cfc6af6557..dd7ef3566e3 100644 --- a/internal/cmd/operator-sdk/scorecard/cmd_test.go +++ b/internal/cmd/operator-sdk/scorecard/cmd_test.go @@ -65,6 +65,16 @@ var _ = Describe("Running the scorecard command", func() { Expect(flag).NotTo(BeNil()) Expect(flag.Shorthand).To(Equal("w")) Expect(flag.DefValue).To(Equal("30s")) + + flag = cmd.Flags().Lookup("storage-image") + Expect(flag).NotTo(BeNil()) + Expect(flag.Shorthand).To(Equal("b")) + Expect(flag.DefValue).To(Equal("docker.io/library/busybox@sha256:c71cb4f7e8ececaffb34037c2637dc86820e4185100e18b4d02d613a9bd772af")) + + flag = cmd.Flags().Lookup("untar-image") + Expect(flag).NotTo(BeNil()) + Expect(flag.Shorthand).To(Equal("u")) + Expect(flag.DefValue).To(Equal("registry.access.redhat.com/ubi8@sha256:910f6bc0b5ae9b555eb91b88d28d568099b060088616eba2867b07ab6ea457c7")) }) }) diff --git a/internal/scorecard/scorecard.go b/internal/scorecard/scorecard.go index 1487e9c4f0a..2f3c00c7ca7 100644 --- a/internal/scorecard/scorecard.go +++ b/internal/scorecard/scorecard.go @@ -52,6 +52,8 @@ type PodTestRunner struct { BundleMetadata registryutil.Labels Client kubernetes.Interface RESTConfig *rest.Config + StorageImage string + UntarImage string configMapName string } @@ -221,7 +223,7 @@ func (r PodTestRunner) RunTest(ctx context.Context, test v1alpha3.TestConfigurat podDef := getPodDefinition(r.configMapName, test, r) if test.Storage.Spec.MountPath.Path != "" { - addStorageToPod(podDef, test.Storage.Spec.MountPath.Path) + addStorageToPod(podDef, test.Storage.Spec.MountPath.Path, r.StorageImage) } pod, err := r.Client.CoreV1().Pods(r.Namespace).Create(ctx, podDef, metav1.CreateOptions{}) diff --git a/internal/scorecard/storage.go b/internal/scorecard/storage.go index 3ec2e537481..9fd156f13e7 100644 --- a/internal/scorecard/storage.go +++ b/internal/scorecard/storage.go @@ -137,7 +137,7 @@ func untarAll(reader io.Reader, destDir, prefix string) error { return nil } -func addStorageToPod(podDef *v1.Pod, mountPath string) { +func addStorageToPod(podDef *v1.Pod, mountPath string, storageImage string) { // add the emptyDir volume for storage to the test Pod newVolume := v1.Volume{} @@ -149,7 +149,7 @@ func addStorageToPod(podDef *v1.Pod, mountPath string) { // add the storage sidecar container storageContainer := v1.Container{ Name: StorageSidecarContainer, - Image: "busybox", + Image: storageImage, ImagePullPolicy: v1.PullIfNotPresent, Args: []string{ "/bin/sh", diff --git a/internal/scorecard/testpod.go b/internal/scorecard/testpod.go index 5862a83c57f..d0793d3402e 100644 --- a/internal/scorecard/testpod.go +++ b/internal/scorecard/testpod.go @@ -30,10 +30,6 @@ import ( const ( // PodBundleRoot is the directory containing all bundle data within a test pod. PodBundleRoot = "/bundle" - - // The image used to untar bundles prior to running tests within a runner Pod. - // This image tag should always be pinned to a specific version. - scorecardUntarImage = "registry.access.redhat.com/ubi8/ubi:8.4" ) // getPodDefinition fills out a Pod definition based on @@ -80,7 +76,7 @@ func getPodDefinition(configMapName string, test v1alpha3.TestConfiguration, r P InitContainers: []v1.Container{ { Name: "scorecard-untar", - Image: scorecardUntarImage, + Image: r.UntarImage, ImagePullPolicy: v1.PullIfNotPresent, Args: []string{ "tar", diff --git a/website/content/en/docs/cli/operator-sdk_scorecard.md b/website/content/en/docs/cli/operator-sdk_scorecard.md index 7a9c65380d9..71a8a76f3a7 100644 --- a/website/content/en/docs/cli/operator-sdk_scorecard.md +++ b/website/content/en/docs/cli/operator-sdk_scorecard.md @@ -27,7 +27,9 @@ operator-sdk scorecard [flags] -l, --selector string label selector to determine which tests are run -s, --service-account string Service account to use for tests (default "default") -x, --skip-cleanup Disable resource cleanup after tests are run + -b, --storage-image string Storage image to use (default "docker.io/library/busybox@sha256:c71cb4f7e8ececaffb34037c2637dc86820e4185100e18b4d02d613a9bd772af") -t, --test-output string Test output directory. (default "test-output") + -u, --untar-image string Untar image to use (default "registry.access.redhat.com/ubi8@sha256:910f6bc0b5ae9b555eb91b88d28d568099b060088616eba2867b07ab6ea457c7") -w, --wait-time duration seconds to wait for tests to complete. Example: 35s (default 30s) ``` diff --git a/website/content/en/docs/testing-operators/scorecard/custom-tests.md b/website/content/en/docs/testing-operators/scorecard/custom-tests.md index d6f01749634..7c4c68efdb2 100644 --- a/website/content/en/docs/testing-operators/scorecard/custom-tests.md +++ b/website/content/en/docs/testing-operators/scorecard/custom-tests.md @@ -251,6 +251,12 @@ $ operator-sdk scorecard ./bundle --test-output=/mytestoutput **Note**: By default, the gathered test output will be stored in `$(pwd)/test-output`. +### Overwrite storage and untar images + +The `--storage-image` flag can be used when executing the `operator-sdk scorecard` command to overwrite the default busybox image used by scorecard pod. +The `--untar-image` flag can be used when executing the `operator-sdk scorecard` command to overwrite the default untar image used by scorecard pod. +These flags are useful when working in disconnected environment prevents image pull from external registries during scorecard job execution. + ### Scorecard initContainer The scorecard inserts an `initContainer` into the test pods it creates. The