Skip to content

Comments

feat: Scoped Kube Config for Providers#389

Draft
philtk79 wants to merge 2 commits intomainfrom
feat/scoped-provider-kubeconfig
Draft

feat: Scoped Kube Config for Providers#389
philtk79 wants to merge 2 commits intomainfrom
feat/scoped-provider-kubeconfig

Conversation

@philtk79
Copy link
Contributor

@philtk79 philtk79 commented Feb 11, 2026

refers to #79

@philtk79 philtk79 changed the title First Draft for scoped kubeconfig feat: Scoped Kube Config for Providers Feb 11, 2026
Copy link
Contributor

@akafazov akafazov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this pr needs major refactoring.


// Use scoped kubeconfig when useAdminKubeconfig is false and FrontProxy is set. Also support legacy:
// extension-manager-operator with FrontProxyName set and no useAdminKubeconfig uses scoped.
useScoped := !ptr.Deref(pc.UseAdminKubeconfig, false) && operatorCfg.KCP.FrontProxyName != ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is frontProxyName relevant to this functionality?

// Use scoped kubeconfig when useAdminKubeconfig is false and FrontProxy is set. Also support legacy:
// extension-manager-operator with FrontProxyName set and no useAdminKubeconfig uses scoped.
useScoped := !ptr.Deref(pc.UseAdminKubeconfig, false) && operatorCfg.KCP.FrontProxyName != ""
legacyScoped := pc.Secret == "extension-manager-operator-kubeconfig" && operatorCfg.KCP.FrontProxyName != "" && pc.UseAdminKubeconfig == nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no hard-coded secret names

Comment on lines 186 to 224
apiExportName := pc.APIExportName
if apiExportName == "" {
apiExportName = *pc.EndpointSliceName
}
apiExportPath := pc.APIExportPath
if apiExportPath == "" {
apiExportPath = pc.Path
}
hostPort := fmt.Sprintf("https://%s-front-proxy.%s:%s", operatorCfg.KCP.FrontProxyName, operatorCfg.KCP.Namespace, operatorCfg.KCP.FrontProxyPort)
if pc.External {
hostPort = fmt.Sprintf("https://kcp.api.%s:%d", instance.Spec.Exposure.BaseDomain, instance.Spec.Exposure.Port)
}
hostPath := pc.Path
if apiExportPath != "" {
hostPath = apiExportPath
}
hostURL, err := url.JoinPath(hostPort, "clusters", hostPath)
if err != nil {
log.Error().Err(err).Msg("Failed to build host URL for scoped kubeconfig")
return ctrl.Result{}, errors.NewOperatorError(err, false, false)
}
namespace := "platform-mesh-system"
if ptr.Deref(pc.Namespace, "") != "" {
namespace = *pc.Namespace
}
caData := cfg.TLSClientConfig.CAData
if caData == nil {
caData = []byte{}
}
writeSecret := func(ctx context.Context, name, ns string, kubeconfigBytes []byte) error {
secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: ns},
}
_, createErr := controllerutil.CreateOrUpdate(ctx, r.client, secret, func() error {
secret.Data = map[string][]byte{"kubeconfig": kubeconfigBytes}
return nil
})
return createErr
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be part of the kubeconfig_scoped.go functions

@philtk79 philtk79 force-pushed the feat/scoped-provider-kubeconfig branch from f32017a to e0ab1e5 Compare February 24, 2026 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants