Skip to content

Commit 0982ab0

Browse files
committed
[Bugfix for #5285] Expose flags for storage and untar images
Signed-off-by: Tatiana Krishtop <[email protected]>
1 parent 7685cb1 commit 0982ab0

File tree

8 files changed

+50
-8
lines changed

8 files changed

+50
-8
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# entries is a list of entries to include in
2+
# release notes and/or the migration guide
3+
entries:
4+
- description: >
5+
Expose flags for storage and untar images to fix the issue 5285
6+
7+
# kind is one of:
8+
# - addition
9+
# - change
10+
# - deprecation
11+
# - removal
12+
# - bugfix
13+
kind: "bugfix"
14+
15+
# Is this a breaking change?
16+
breaking: false

internal/cmd/operator-sdk/scorecard/cmd.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ type scorecardCmd struct {
4949
list bool
5050
skipCleanup bool
5151
waitTime time.Duration
52+
storageImage string
53+
untarImage string
5254
testOutput string
5355
}
5456

@@ -86,6 +88,12 @@ If the argument holds an image tag, it must be present remotely.`,
8688
"Disable resource cleanup after tests are run")
8789
scorecardCmd.Flags().DurationVarP(&c.waitTime, "wait-time", "w", 30*time.Second,
8890
"seconds to wait for tests to complete. Example: 35s")
91+
scorecardCmd.Flags().StringVarP(&c.storageImage, "storage-image", "b",
92+
"docker.io/library/busybox@sha256:c71cb4f7e8ececaffb34037c2637dc86820e4185100e18b4d02d613a9bd772af",
93+
"Storage image to use")
94+
scorecardCmd.Flags().StringVarP(&c.untarImage, "untar-image", "u",
95+
"registry.access.redhat.com/ubi8@sha256:910f6bc0b5ae9b555eb91b88d28d568099b060088616eba2867b07ab6ea457c7",
96+
"Untar image to use")
8997
scorecardCmd.Flags().StringVarP(&c.testOutput, "test-output", "t", "test-output",
9098
"Test output directory.")
9199

@@ -208,6 +216,8 @@ func (c *scorecardCmd) run() (err error) {
208216
BundlePath: c.bundle,
209217
TestOutput: c.testOutput,
210218
BundleMetadata: metadata,
219+
StorageImage: c.storageImage,
220+
UntarImage: c.untarImage,
211221
}
212222

213223
// Only get the client if running tests.

internal/cmd/operator-sdk/scorecard/cmd_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ var _ = Describe("Running the scorecard command", func() {
6565
Expect(flag).NotTo(BeNil())
6666
Expect(flag.Shorthand).To(Equal("w"))
6767
Expect(flag.DefValue).To(Equal("30s"))
68+
69+
flag = cmd.Flags().Lookup("storage-image")
70+
Expect(flag).NotTo(BeNil())
71+
Expect(flag.Shorthand).To(Equal("b"))
72+
Expect(flag.DefValue).To(Equal("docker.io/library/busybox@sha256:c71cb4f7e8ececaffb34037c2637dc86820e4185100e18b4d02d613a9bd772af"))
73+
74+
flag = cmd.Flags().Lookup("untar-image")
75+
Expect(flag).NotTo(BeNil())
76+
Expect(flag.Shorthand).To(Equal("u"))
77+
Expect(flag.DefValue).To(Equal("registry.access.redhat.com/ubi8@sha256:910f6bc0b5ae9b555eb91b88d28d568099b060088616eba2867b07ab6ea457c7"))
6878
})
6979
})
7080

internal/scorecard/scorecard.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ type PodTestRunner struct {
5252
BundleMetadata registryutil.Labels
5353
Client kubernetes.Interface
5454
RESTConfig *rest.Config
55+
StorageImage string
56+
UntarImage string
5557

5658
configMapName string
5759
}
@@ -221,7 +223,7 @@ func (r PodTestRunner) RunTest(ctx context.Context, test v1alpha3.TestConfigurat
221223
podDef := getPodDefinition(r.configMapName, test, r)
222224

223225
if test.Storage.Spec.MountPath.Path != "" {
224-
addStorageToPod(podDef, test.Storage.Spec.MountPath.Path)
226+
addStorageToPod(podDef, test.Storage.Spec.MountPath.Path, r.StorageImage)
225227
}
226228

227229
pod, err := r.Client.CoreV1().Pods(r.Namespace).Create(ctx, podDef, metav1.CreateOptions{})

internal/scorecard/storage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func untarAll(reader io.Reader, destDir, prefix string) error {
137137
return nil
138138
}
139139

140-
func addStorageToPod(podDef *v1.Pod, mountPath string) {
140+
func addStorageToPod(podDef *v1.Pod, mountPath string, storageImage string) {
141141

142142
// add the emptyDir volume for storage to the test Pod
143143
newVolume := v1.Volume{}
@@ -149,7 +149,7 @@ func addStorageToPod(podDef *v1.Pod, mountPath string) {
149149
// add the storage sidecar container
150150
storageContainer := v1.Container{
151151
Name: StorageSidecarContainer,
152-
Image: "busybox",
152+
Image: storageImage,
153153
ImagePullPolicy: v1.PullIfNotPresent,
154154
Args: []string{
155155
"/bin/sh",

internal/scorecard/testpod.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ import (
3030
const (
3131
// PodBundleRoot is the directory containing all bundle data within a test pod.
3232
PodBundleRoot = "/bundle"
33-
34-
// The image used to untar bundles prior to running tests within a runner Pod.
35-
// This image tag should always be pinned to a specific version.
36-
scorecardUntarImage = "registry.access.redhat.com/ubi8/ubi:8.4"
3733
)
3834

3935
// getPodDefinition fills out a Pod definition based on
@@ -80,7 +76,7 @@ func getPodDefinition(configMapName string, test v1alpha3.TestConfiguration, r P
8076
InitContainers: []v1.Container{
8177
{
8278
Name: "scorecard-untar",
83-
Image: scorecardUntarImage,
79+
Image: r.UntarImage,
8480
ImagePullPolicy: v1.PullIfNotPresent,
8581
Args: []string{
8682
"tar",

website/content/en/docs/cli/operator-sdk_scorecard.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ operator-sdk scorecard [flags]
2727
-l, --selector string label selector to determine which tests are run
2828
-s, --service-account string Service account to use for tests (default "default")
2929
-x, --skip-cleanup Disable resource cleanup after tests are run
30+
-b, --storage-image string Storage image to use (default "docker.io/library/busybox@sha256:c71cb4f7e8ececaffb34037c2637dc86820e4185100e18b4d02d613a9bd772af")
3031
-t, --test-output string Test output directory. (default "test-output")
32+
-u, --untar-image string Untar image to use (default "registry.access.redhat.com/ubi8@sha256:910f6bc0b5ae9b555eb91b88d28d568099b060088616eba2867b07ab6ea457c7")
3133
-w, --wait-time duration seconds to wait for tests to complete. Example: 35s (default 30s)
3234
```
3335

website/content/en/docs/testing-operators/scorecard/custom-tests.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ $ operator-sdk scorecard ./bundle --test-output=/mytestoutput
251251

252252
**Note**: By default, the gathered test output will be stored in `$(pwd)/test-output`.
253253

254+
### Overwrite storage and untar images
255+
256+
The `--storage-image` flag can be used when executing the `operator-sdk scorecard` command to overwrite the default busybox image used by scorecard pod.
257+
The `--untar-image` flag can be used when executing the `operator-sdk scorecard` command to overwrite the default untar image used by scorecard pod.
258+
These flags are useful when working in disconnected environment prevents image pull from external registries during scorecard job execution.
259+
254260
### Scorecard initContainer
255261

256262
The scorecard inserts an `initContainer` into the test pods it creates. The

0 commit comments

Comments
 (0)