Skip to content

Commit

Permalink
virt-operator: fix kubevirt version parsing
Browse files Browse the repository at this point in the history
there was an issue when virt-operator image had digest
instead of a tag, the hardcoded "latest" tag was used and
KUBEVIRT_VERSION was ignored.

this commit fixes this issue by taking the Kubevirt version from
the KUBEVIRT_VERSION env var in case digest is used instead of tag.

Signed-off-by: enp0s3 <ibezukh@redhat.com>
  • Loading branch information
enp0s3 authored and jean-edouard committed Apr 5, 2023
1 parent ea44b54 commit f4a4fa3
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/virt-operator/util/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := ""
Expand All @@ -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, "@")
}

Expand Down Expand Up @@ -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)
}
Expand Down
60 changes: 60 additions & 0 deletions pkg/virt-operator/util/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}))
})
})

0 comments on commit f4a4fa3

Please sign in to comment.