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.15] Set cluster name label for pre-existing kubeconfig #4848

Merged
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 @@ -33,6 +33,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 @@ -137,6 +138,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 146 in controllers/azuremanagedcontrolplane_reconciler.go

View check run for this annotation

Codecov / codecov/patch

controllers/azuremanagedcontrolplane_reconciler.go#L145-L146

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

Check warning on line 148 in controllers/azuremanagedcontrolplane_reconciler.go

View check run for this annotation

Codecov / codecov/patch

controllers/azuremanagedcontrolplane_reconciler.go#L148

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