Skip to content

Commit c4fbdf1

Browse files
committed
fix: revert env var flag defaults, use Kubernetes var substitution
The previous commit incorrectly added os.Getenv(...) defaults to flag declarations in cmd/main.go. Go flag defaults are for documentation and local use; env var wiring belongs in the deployment layer. Revert cmd/main.go to plain hard-coded defaults and remove the envOrDefault helper. In manager.yaml, introduce an env: section with the default values and reference them from args via Kubernetes $(VAR_NAME) substitution. Overlays can now override a single env entry by name without touching the args list.
1 parent f1938df commit c4fbdf1

2 files changed

Lines changed: 23 additions & 21 deletions

File tree

cmd/main.go

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -87,29 +87,27 @@ func main() {
8787
var enableManagementControllers bool
8888
var enableCellControllers bool
8989

90-
flag.StringVar(&probeAddr, "health-probe-bind-address", envOrDefault("HEALTH_PROBE_BIND_ADDRESS", ":8081"), "The address the probe endpoint binds to.")
91-
flag.BoolVar(&enableLeaderElection, "leader-elect", os.Getenv("LEADER_ELECT") == "true",
90+
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
91+
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
9292
"Enable leader election for controller manager. "+
9393
"Enabling this will ensure there is only one active controller manager.")
94-
flag.StringVar(&leaderElectionNamespace, "leader-elect-namespace", os.Getenv("LEADER_ELECT_NAMESPACE"), "The namespace to use for leader election.")
95-
flag.StringVar(&karmadaKubeconfig, "karmada-kubeconfig", os.Getenv("KARMADA_KUBECONFIG"),
94+
flag.StringVar(&leaderElectionNamespace, "leader-elect-namespace", "", "The namespace to use for leader election.")
95+
flag.StringVar(&karmadaKubeconfig, "karmada-kubeconfig", "",
9696
"Path to the kubeconfig file for the Karmada control plane. When omitted, Karmada federation features are disabled.")
97-
flag.StringVar(&karmadaContext, "karmada-context", os.Getenv("KARMADA_CONTEXT"),
97+
flag.StringVar(&karmadaContext, "karmada-context", "",
9898
"Context to use from the Karmada kubeconfig. When omitted, the current context is used.")
99-
flag.BoolVar(&enableManagementControllers, "enable-management-controllers",
100-
os.Getenv("ENABLE_MANAGEMENT_CONTROLLERS") != "false",
99+
flag.BoolVar(&enableManagementControllers, "enable-management-controllers", true,
101100
"Enable management-plane controllers (WorkloadDeploymentFederator, InstanceProjector). "+
102101
"Disable when running a cell-only operator instance.")
103-
flag.BoolVar(&enableCellControllers, "enable-cell-controllers",
104-
os.Getenv("ENABLE_CELL_CONTROLLERS") != "false",
102+
flag.BoolVar(&enableCellControllers, "enable-cell-controllers", true,
105103
"Enable cell controllers (WorkloadDeploymentReconciler, InstanceReconciler). "+
106104
"Disable when running a management-only operator instance.")
107105

108106
opts := zap.Options{
109107
Development: true,
110108
}
111109

112-
flag.StringVar(&serverConfigFile, "server-config", os.Getenv("SERVER_CONFIG"), "path to the server config file")
110+
flag.StringVar(&serverConfigFile, "server-config", "", "path to the server config file")
113111

114112
opts.BindFlags(flag.CommandLine)
115113
flag.Parse()
@@ -422,9 +420,3 @@ func ignoreCanceled(err error) error {
422420
return err
423421
}
424422

425-
func envOrDefault(key, def string) string {
426-
if v := os.Getenv(key); v != "" {
427-
return v
428-
}
429-
return def
430-
}

config/base/manager/manager.yaml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,24 @@ spec:
2626
seccompProfile:
2727
type: RuntimeDefault
2828
containers:
29-
- command:
29+
- name: manager
30+
command:
3031
- /manager
3132
args:
32-
- --leader-elect
33-
- --health-probe-bind-address=:8081
34-
- --server-config=/config/config.yaml
33+
- --leader-elect=$(LEADER_ELECT)
34+
- --health-probe-bind-address=$(HEALTH_PROBE_BIND_ADDRESS)
35+
- --server-config=$(SERVER_CONFIG)
36+
- --karmada-kubeconfig=$(KARMADA_KUBECONFIG)
37+
env:
38+
- name: LEADER_ELECT
39+
value: "true"
40+
- name: HEALTH_PROBE_BIND_ADDRESS
41+
value: ":8081"
42+
- name: SERVER_CONFIG
43+
value: /config/config.yaml
44+
- name: KARMADA_KUBECONFIG
45+
value: ""
3546
image: ghcr.io/datum-cloud/compute:latest
36-
name: manager
3747
ports:
3848
- containerPort: 9443
3949
name: webhook-server

0 commit comments

Comments
 (0)