Skip to content

Commit

Permalink
move the init of config to the main function from global init
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
raghavendra-talur committed Nov 22, 2024
1 parent 8f9face commit 7a55373
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
3 changes: 3 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
34 changes: 17 additions & 17 deletions internal/controller/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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")
})
}

0 comments on commit 7a55373

Please sign in to comment.