Skip to content

Commit

Permalink
Merge pull request #4833 from willie-yao/kubeconfig-label
Browse files Browse the repository at this point in the history
Set cluster name label for pre-existing kubeconfig
  • Loading branch information
k8s-ci-robot authored May 14, 2024
2 parents 40618f5 + d4fda95 commit 4b1d9c1
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions controllers/azuremanagedcontrolplane_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"sigs.k8s.io/cluster-api-provider-azure/azure/services/subnets"
"sigs.k8s.io/cluster-api-provider-azure/azure/services/virtualnetworks"
"sigs.k8s.io/cluster-api-provider-azure/util/tele"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util/secret"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
Expand Down Expand Up @@ -137,6 +138,15 @@ func (r *azureManagedControlPlaneService) reconcileKubeconfig(ctx context.Contex
kubeConfigSecret.Data = map[string][]byte{
secret.KubeconfigDataName: kubeConfigData,
}

// When upgrading from an older version of CAPI, the kubeconfig secret may not have the required
// cluster name label. Add it here to avoid kubeconfig issues during upgrades.
if _, ok := kubeConfigSecret.Labels[clusterv1.ClusterNameLabel]; !ok {
if kubeConfigSecret.Labels == nil {
kubeConfigSecret.Labels = make(map[string]string)
}
kubeConfigSecret.Labels[clusterv1.ClusterNameLabel] = r.scope.ClusterName()
}
return nil
}); err != nil {
return errors.Wrap(err, "failed to reconcile kubeconfig secret for cluster")
Expand Down

0 comments on commit 4b1d9c1

Please sign in to comment.