Skip to content

Commit 26f988e

Browse files
committed
capi: do not override KUBECONFIG
Managed clusters might rely on the KUBECONFIG to reach their kube api server. Instead of using the env var and possibly causing issues, we can specify a custom kube config via cmdline argument for the capi controllers. That seems a more appropriate approach for an ephemeral kube API like the one spawned by envtest.
1 parent d4aa1ca commit 26f988e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pkg/clusterapi/system.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,13 @@ func (c *system) runController(ctx context.Context, ct *controller) error {
479479
templateData := map[string]string{
480480
"WebhookPort": fmt.Sprintf("%d", wh.LocalServingPort),
481481
"WebhookCertDir": wh.LocalServingCertDir,
482+
"KubeconfigPath": c.lcp.KubeconfigPath,
483+
}
484+
485+
// We cannot override KUBECONFIG, e.g., in case the user supplies a callback that needs to access the cluster,
486+
// such as via credential_process in the AWS config file. The kubeconfig path is set in the controller instead.
487+
if ct.Provider == nil || ct.Provider.Name != "azureaso" {
488+
ct.Args = append(ct.Args, "--kubeconfig={{.KubeconfigPath}}")
482489
}
483490

484491
args := make([]string, 0, len(ct.Args))
@@ -500,7 +507,10 @@ func (c *system) runController(ctx context.Context, ct *controller) error {
500507
ct.Env = map[string]string{}
501508
}
502509
// Override KUBECONFIG to point to the local control plane.
503-
ct.Env["KUBECONFIG"] = c.lcp.KubeconfigPath
510+
// azureaso doesn't support the --kubeconfig parameter.
511+
if ct.Provider != nil && ct.Provider.Name == "azureaso" {
512+
ct.Env["KUBECONFIG"] = c.lcp.KubeconfigPath
513+
}
504514
for key, value := range ct.Env {
505515
env = append(env, fmt.Sprintf("%s=%s", key, value))
506516
}

0 commit comments

Comments
 (0)