Skip to content

Commit

Permalink
Fix environment variable names in code and CSV (#100)
Browse files Browse the repository at this point in the history
Now the operator expects the same environment
variables as is specified in the CSV.

Signed-off-by: Andrej Krejcir <[email protected]>
  • Loading branch information
akrejcir authored Jan 21, 2021
1 parent 76ce74b commit 2911ade
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 25 deletions.
2 changes: 1 addition & 1 deletion config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
args:
- --enable-leader-election
env:
- name: KVM_IMAGE
- name: KVM_INFO_IMAGE
- name: VALIDATOR_IMAGE
- name: VIRT_LAUNCHER_IMAGE
- name: NODE_LABELLER_IMAGE
Expand Down
7 changes: 1 addition & 6 deletions controllers/ssp_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package controllers
import (
"context"
"fmt"
"os"
"reflect"
"strconv"

Expand Down Expand Up @@ -185,11 +184,7 @@ func (r *SSPReconciler) clearCache() {
}

func getOperatorVersion() string {
opVer := os.Getenv("OPERATOR_VERSION")
if opVer == "" {
return defaultOperatorVersion
}
return opVer
return common.EnvOrDefault(common.OperatorVersionKey, defaultOperatorVersion)
}

func isPaused(object metav1.Object) bool {
Expand Down
2 changes: 1 addition & 1 deletion data/olm-catalog/ssp-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ spec:
command:
- /manager
env:
- name: KVM_IMAGE
- name: KVM_INFO_IMAGE
- name: VALIDATOR_IMAGE
- name: VIRT_LAUNCHER_IMAGE
- name: NODE_LABELLER_IMAGE
Expand Down
15 changes: 8 additions & 7 deletions hack/csv-generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ import (
gyaml "github.com/ghodss/yaml"
"github.com/operator-framework/api/pkg/lib/version"
csvv1 "github.com/operator-framework/api/pkg/operators/v1alpha1"

"github.com/spf13/cobra"
v1 "k8s.io/api/core/v1"
extv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/util/yaml"

"kubevirt.io/ssp-operator/internal/common"
)

type generatorFlags struct {
Expand Down Expand Up @@ -155,22 +156,22 @@ func replaceVariables(flags generatorFlags, csv *csvv1.ClusterServiceVersion) er
updatedVariables := make([]v1.EnvVar, 0)
for _, envVariable := range container.Env {

if envVariable.Name == "KVM_IMAGE" {
if envVariable.Name == common.KvmInfoNfdPluginImageKey {
envVariable.Value = flags.kvmInfoImage
}
if envVariable.Name == "VALIDATOR_IMAGE" {
if envVariable.Name == common.TemplateValidatorImageKey {
envVariable.Value = flags.validatorImage
}
if envVariable.Name == "VIRT_LAUNCHER_IMAGE" {
if envVariable.Name == common.VirtLauncherImageKey {
envVariable.Value = flags.virtLauncher
}
if envVariable.Name == "NODE_LABELLER_IMAGE" {
if envVariable.Name == common.KubevirtNodeLabellerImageKey {
envVariable.Value = flags.nodeLabellerImage
}
if envVariable.Name == "CPU_PLUGIN_IMAGE" {
if envVariable.Name == common.KubevirtCpuNfdPluginImageKey {
envVariable.Value = flags.cpuPlugin
}
if envVariable.Name == "OPERATOR_VERSION" {
if envVariable.Name == common.OperatorVersionKey {
envVariable.Value = flags.operatorVersion
}
updatedVariables = append(updatedVariables, envVariable)
Expand Down
28 changes: 18 additions & 10 deletions hack/csv-generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"github.com/blang/semver"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"

"github.com/operator-framework/api/pkg/lib/version"
csvv1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
logf "sigs.k8s.io/controller-runtime/pkg/log"

"kubevirt.io/ssp-operator/internal/common"
)

var log = logf.Log.WithName("csv_generator")
Expand All @@ -26,7 +27,14 @@ var _ = Describe("csv generator", func() {
nodeLabellerImage: "test",
virtLauncher: "test",
}
envValues := []v1.EnvVar{{Name: "KVM_IMAGE"}, {Name: "VALIDATOR_IMAGE"}, {Name: "VIRT_LAUNCHER_IMAGE"}, {Name: "OPERATOR_VERSION"}, {Name: "NODE_LABELLER_IMAGE"}, {Name: "CPU_PLUGIN_IMAGE"}}
envValues := []v1.EnvVar{
{Name: common.KvmInfoNfdPluginImageKey},
{Name: common.TemplateValidatorImageKey},
{Name: common.VirtLauncherImageKey},
{Name: common.OperatorVersionKey},
{Name: common.KubevirtNodeLabellerImageKey},
{Name: common.KubevirtCpuNfdPluginImageKey},
}

csv := csvv1.ClusterServiceVersion{
Spec: csvv1.ClusterServiceVersionSpec{
Expand Down Expand Up @@ -67,22 +75,22 @@ var _ = Describe("csv generator", func() {
Expect(container.Image).To(Equal(flags.operatorImage))

for _, envVariable := range container.Env {
if envVariable.Name == "KVM_IMAGE" {
if envVariable.Name == common.KvmInfoNfdPluginImageKey {
Expect(envVariable.Value).To(Equal(flags.kvmInfoImage))
}
if envVariable.Name == "VALIDATOR_IMAGE" {
if envVariable.Name == common.TemplateValidatorImageKey {
Expect(envVariable.Value).To(Equal(flags.validatorImage))
}
if envVariable.Name == "VIRT_LAUNCHER_IMAGE" {
if envVariable.Name == common.VirtLauncherImageKey {
Expect(envVariable.Value).To(Equal(flags.virtLauncher))
}
if envVariable.Name == "NODE_LABELLER_IMAGE" {
if envVariable.Name == common.KubevirtNodeLabellerImageKey {
Expect(envVariable.Value).To(Equal(flags.nodeLabellerImage))
}
if envVariable.Name == "CPU_PLUGIN_IMAGE" {
if envVariable.Name == common.KubevirtCpuNfdPluginImageKey {
Expect(envVariable.Value).To(Equal(flags.cpuPlugin))
}
if envVariable.Name == "OPERATOR_VERSION" {
if envVariable.Name == common.OperatorVersionKey {
Expect(envVariable.Value).To(Equal(flags.operatorVersion))
}
}
Expand Down
2 changes: 2 additions & 0 deletions internal/common/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
)

const (
OperatorVersionKey = "OPERATOR_VERSION"

TemplateValidatorImageKey = "VALIDATOR_IMAGE"
KubevirtNodeLabellerImageKey = "NODE_LABELLER_IMAGE"
KvmInfoNfdPluginImageKey = "KVM_INFO_IMAGE"
Expand Down

0 comments on commit 2911ade

Please sign in to comment.