Skip to content

Commit d4fda95

Browse files
committed
Set cluster name label for pre-existing kubeconfig
1 parent abba169 commit d4fda95

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

controllers/azuremanagedcontrolplane_reconciler.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"sigs.k8s.io/cluster-api-provider-azure/azure/services/subnets"
3434
"sigs.k8s.io/cluster-api-provider-azure/azure/services/virtualnetworks"
3535
"sigs.k8s.io/cluster-api-provider-azure/util/tele"
36+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3637
"sigs.k8s.io/cluster-api/util/secret"
3738
"sigs.k8s.io/controller-runtime/pkg/client"
3839
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
@@ -137,6 +138,15 @@ func (r *azureManagedControlPlaneService) reconcileKubeconfig(ctx context.Contex
137138
kubeConfigSecret.Data = map[string][]byte{
138139
secret.KubeconfigDataName: kubeConfigData,
139140
}
141+
142+
// When upgrading from an older version of CAPI, the kubeconfig secret may not have the required
143+
// cluster name label. Add it here to avoid kubeconfig issues during upgrades.
144+
if _, ok := kubeConfigSecret.Labels[clusterv1.ClusterNameLabel]; !ok {
145+
if kubeConfigSecret.Labels == nil {
146+
kubeConfigSecret.Labels = make(map[string]string)
147+
}
148+
kubeConfigSecret.Labels[clusterv1.ClusterNameLabel] = r.scope.ClusterName()
149+
}
140150
return nil
141151
}); err != nil {
142152
return errors.Wrap(err, "failed to reconcile kubeconfig secret for cluster")

0 commit comments

Comments
 (0)