From 7a553734eed4e57649b64506b274eb541e95971e Mon Sep 17 00:00:00 2001 From: Raghavendra Talur Date: Wed, 20 Nov 2024 01:11:06 -0500 Subject: [PATCH] move the init of config to the main function from global init This will make it easier to setup the test framework with a different config when required. If the configuration is built in the global init of the controller then it can not be skipped. Signed-off-by: Raghavendra Talur --- cmd/main.go | 3 +++ internal/controller/defaults.go | 34 ++++++++++++++++----------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 97228a5e..dab536f5 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -94,6 +94,9 @@ func main() { TLSOpts: tlsOpts, }) + // Init the config options from the environment + controller.InitConfig() + mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ Scheme: scheme, Metrics: metricsserver.Options{ diff --git a/internal/controller/defaults.go b/internal/controller/defaults.go index d1a909c6..06ff1ab8 100644 --- a/internal/controller/defaults.go +++ b/internal/controller/defaults.go @@ -24,7 +24,6 @@ import ( "k8s.io/utils/ptr" csiv1a1 "github.com/ceph/ceph-csi-operator/api/v1alpha1" - "github.com/ceph/ceph-csi-operator/internal/utils" ) var imageDefaults = map[string]string{ @@ -65,25 +64,26 @@ var defaultDeploymentStrategy = appsv1.DeploymentStrategy{ }, } -var operatorNamespace = utils.Call(func() string { - namespace := os.Getenv("OPERATOR_NAMESPACE") - if namespace == "" { +var ( + operatorNamespace string + operatorConfigName string + serviceAccountPrefix string +) + +func InitConfig() { + if operatorNamespace = os.Getenv("OPERATOR_NAMESPACE"); operatorNamespace == "" { panic("Required OPERATOR_NAMESPACE environment variable is either missing or empty") } - return namespace -}) -var operatorConfigName = utils.Call(func() string { - name, ok := os.LookupEnv("OPERATOR_CONFIG_NAME") - if ok { - if name == "" { + serviceAccountPrefix = os.Getenv("CSI_SERVICE_ACCOUNT_PREFIX") + + envOperatorConfigName, set := os.LookupEnv("OPERATOR_CONFIG_NAME") + if set { + if envOperatorConfigName == "" { panic("OPERATOR_CONFIG_NAME exists but empty") } - return name + operatorConfigName = envOperatorConfigName + } else { + operatorConfigName = "ceph-csi-operator-config" } - return "ceph-csi-operator-config" -}) - -var serviceAccountPrefix = utils.Call(func() string { - return os.Getenv("CSI_SERVICE_ACCOUNT_PREFIX") -}) +}