diff --git a/pkg/virt-operator/util/config.go b/pkg/virt-operator/util/config.go index 9d920b6faad4..400fc26b6e41 100644 --- a/pkg/virt-operator/util/config.go +++ b/pkg/virt-operator/util/config.go @@ -285,6 +285,7 @@ func getConfig(registry, tag, namespace string, additionalProperties map[string] imageString := GetOperatorImageWithEnvVarManager(envVarManager) imageRegEx := regexp.MustCompile(operatorImageRegex) matches := imageRegEx.FindAllStringSubmatch(imageString, 1) + kubeVirtVersion := envVarManager.Getenv(KubeVirtVersionEnvName) tagFromOperator := "" operatorSha := "" @@ -309,6 +310,9 @@ func getConfig(registry, tag, namespace string, additionalProperties map[string] // we have a shasum... chances are high that we get the shasums for the other images as well from env vars, // but as a fallback use latest tag tagFromOperator = "latest" + if kubeVirtVersion != "" { + tagFromOperator = kubeVirtVersion + } operatorSha = strings.TrimPrefix(version, "@") } @@ -347,7 +351,6 @@ func getConfig(registry, tag, namespace string, additionalProperties map[string] exportServerSha := envVarManager.Getenv(VirtExportServerShasumEnvName) gsSha := envVarManager.Getenv(GsEnvShasumName) prHelperSha := envVarManager.Getenv(PrHelperShasumEnvName) - kubeVirtVersion := envVarManager.Getenv(KubeVirtVersionEnvName) if operatorSha != "" && apiSha != "" && controllerSha != "" && handlerSha != "" && launcherSha != "" && kubeVirtVersion != "" { config = newDeploymentConfigWithShasums(registry, imagePrefix, kubeVirtVersion, operatorSha, apiSha, controllerSha, handlerSha, launcherSha, exportProxySha, exportServerSha, gsSha, prHelperSha, namespace, additionalProperties, passthroughEnv) } diff --git a/pkg/virt-operator/util/config_test.go b/pkg/virt-operator/util/config_test.go index 01b4c076e2c5..11ecfeeedaa8 100644 --- a/pkg/virt-operator/util/config_test.go +++ b/pkg/virt-operator/util/config_test.go @@ -401,4 +401,64 @@ var _ = Describe("Operator Config", func() { Entry("not provided at all - expected to fail", "", false), ) }) + + Context("kubevirt version", func() { + type testInput struct { + kubevirtVerEnvVar string + tag string + digest string + version string + } + + BeforeEach(func() { + ExpectWithOffset(1, envVarManager.Unsetenv(KubeVirtVersionEnvName)).To(Succeed()) + ExpectWithOffset(1, envVarManager.Unsetenv(VirtOperatorImageEnvName)).To(Succeed()) + }) + + DescribeTable("is read from", func(input *testInput) { + operatorImage := fmt.Sprintf("acme.com/kubevirt/my-virt-operator%s", input.tag) + + if input.digest != "" { + operatorImage = fmt.Sprintf("acme.com/kubevirt/my-virt-operator%s", input.digest) + } + + Expect(envVarManager.Setenv(VirtOperatorImageEnvName, operatorImage)).To(Succeed()) + + if input.kubevirtVerEnvVar != "" { + Expect(envVarManager.Setenv(KubeVirtVersionEnvName, input.kubevirtVerEnvVar)).To(Succeed()) + } + + err := VerifyEnv() + Expect(err).ToNot(HaveOccurred()) + + parsedConfig, err := GetConfigFromEnv() + Expect(err).ToNot(HaveOccurred()) + + kubevirtVersion := parsedConfig.GetKubeVirtVersion() + Expect(kubevirtVersion).To(Equal(input.version)) + + }, + Entry("virt-operator image tag when both KUBEVIRT_VERSION is set and virt-operator provided with tag", + &testInput{ + kubevirtVerEnvVar: "v3.0.0-env.var", + tag: ":v3.0.0", + version: "v3.0.0", + }), + + Entry("KUBEVIRT_VERSION variable when virt-operator provided with digest", + &testInput{ + kubevirtVerEnvVar: "v3.0.0", + digest: "@sha256:trivebuk", + version: "v3.0.0", + }), + Entry("operator tag when no KUBEVIRT_VERSION provided and operator image is with a tag", + &testInput{ + tag: ":v3.0.0", + version: "v3.0.0", + }), + Entry("hardcoded \"latest\" string when no KUBEVIRT_VERSION provided and operator image is with a digest", + &testInput{ + version: "latest", + })) + }) })