rancher / turtles

Rancher CAPI extension
https://turtles.docs.rancher.com
Apache License 2.0
41 stars 15 forks source link

feat: add script for import controller migration #574

Closed salasberryfin closed 4 weeks ago

salasberryfin commented 1 month ago

kind/feature

What this PR does / why we need it:

Migrating to the new import controller based on clusters.management.cattle.io (v3 clusters) means we need to apply changes to the existing Rancher cluster resources to let the new controller identify CAPI clusters as already imported. As described in the migration proposal #573, the v3 controller looks for cluster resources marked with the following labels:

cluster-api.cattle.io/capi-cluster-owner
cluster-api.cattle.io/capi-cluster-owner-ns
cluster-api.cattle.io/owned

cluster-api.cattle.io/owned is added to all clusters imported via Turtles, even if using the existing clusters.provisioning.cattle.io (v1 clusters) based controller. The other two labels must be added to the existing clusters.management.cattle.io resources to let the new controller's label selector find a match and hence detect that the CAPI cluster is properly imported and no new resource needs to be created.

This PR adds a basic bash script for users to run pre-controller-migration so clusters are labeled accordingly. It simply gets one or multiple namespaces as input and applies labels to all Turtles clusters in that namespace.

We'll also be adding instructions on how to do it manually at the cluster level on a migration guide.

Which issue(s) this PR fixes: Fixes #

Special notes for your reviewer:

Checklist:

salasberryfin commented 1 month ago

Thanks for the comments @alexander-demicev. I reviewed the code and I think all of them have been addressed now.