Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.13] Set cluster name label for pre-existing kubeconfig #4847

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions controllers/azuremanagedcontrolplane_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"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 @@ -135,6 +136,15 @@
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)

Check warning on line 144 in controllers/azuremanagedcontrolplane_reconciler.go

View check run for this annotation

Codecov / codecov/patch

controllers/azuremanagedcontrolplane_reconciler.go#L143-L144

Added lines #L143 - L144 were not covered by tests
}
kubeConfigSecret.Labels[clusterv1.ClusterNameLabel] = r.scope.ClusterName()

Check warning on line 146 in controllers/azuremanagedcontrolplane_reconciler.go

View check run for this annotation

Codecov / codecov/patch

controllers/azuremanagedcontrolplane_reconciler.go#L146

Added line #L146 was not covered by tests
}
return nil
}); err != nil {
return errors.Wrap(err, "failed to reconcile kubeconfig secret for cluster")
Expand Down
Loading