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..25e43600 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,24 @@ 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") + + operatorConfigName, set := os.LookupEnv("OPERATOR_CONFIG_NAME") + if set { + if operatorConfigName == "" { panic("OPERATOR_CONFIG_NAME exists but empty") } - return name } - return "ceph-csi-operator-config" -}) - -var serviceAccountPrefix = utils.Call(func() string { - return os.Getenv("CSI_SERVICE_ACCOUNT_PREFIX") -}) + operatorConfigName = "ceph-csi-operator-config" +}