Label Fleet clusters with their corresponding CAPI `ClusterClass` on import
Description
The now deprecated CAAPF bridged the gap between CAPI and Fleet by creating a ClusterGroup for each CAPI ClusterClass (see docs), which made it easy for users to orchestrate Fleet deployments to their downstream clusters depending on their flavor (class).
As an operator, after removing CAAPF, I still want to be able to deploy applications to all clusters created from a cluster class.
Notes
- We need to evaluate where this logic should live. Turtles is Rancher's CAPI manager but it does not interact with Fleet resources (as of today). See
Implementation details.
Implementation details
Note that this is just a high-level reference, not a strict implementation specification.
Rancher Turtles already understands CAPI resources and reconciles them into Rancher objects. Though it does not directly interact with Fleet (as of today), it is sensible to implement this feature in Turtles, to maintain the CAPI-to-Rancher (including Fleet as part of Rancher) logic contained. Other options that have been considered and discarded:
- Fleet: it would create a requirement for Fleet engineers to maintain CAPI-related code, or Highlander engineers to maintain Fleet features.
- Core Rancher: adds more complexity to the Rancher abstraction layer and makes it less obvious which component is actually bridging the native CAPI-to-Rancher gap.
Architecture and workflow
As part of the deprecation plan (RFD 0051), the design decision is to propagate the ClusterClass information as labels on the Fleet Cluster object, and to not create ClusterGroups. A ClusterGroup is only a label selector, so users can replicate the same targeting behaviour by selecting on the labels directly from a GitRepo or Bundle.
When a CAPI cluster that was provisioned from a ClusterClass is imported into Rancher, Turtles should label the corresponding Fleet cluster with the name and namespace of the ClusterClass it came from. Since Turtles does not directly interact with Fleet clusters, the labeling could leverage the label propagation feature as any label on the CAPI cluster object is propagated to the management cluster and then the Fleet cluster.
The labels must encode both the name and the namespace of the ClusterClass, as it is a namespaced resource and two different namespaces can each define a ClusterClass with the same name. Without the namespace in the label, clusters from those two classes would be indistinguishable from Fleet's perspective.
The implementation should determine the Fleet workspace namespace at runtime from the Rancher management cluster object, rather than assuming fleet-default (though this is currently the only namespace Fleet clusters live in, but it is subject to change). This keeps the code correct once Rancher allows users to choose a custom Fleet workspace per cluster.
When the CAPI cluster is deleted, the Fleet cluster is removed by Rancher as part of normal cleanup, so no special label removal is needed.
Implementation
Find Fleet cluster
- Turtles manages the
clusters.management.cattle.ioon import, which can be used to find theclusters.fleet.cattle.ioas they share the same name. fleet-defaultis the only supported namespace for Fleet clusters, but this implementation must be resilient to a user selecting an arbitrary namespace.- The controller only proceeds once the management cluster exists and is ready, meaning import has completed.
Label format
- Two labels are written to the Fleet cluster:
ClusterClassname andClusterClassnamespace.
Note that the current label propagation feature omits all labels with the sub-strings cattle.io and k8s.io. We must select label keys that comply with this exclusion or add exceptions for the label propagation rules.
The ClusterClass details come from cluster.spec.topology.classRef.*.
Definition of done
- When a CAPI cluster provisioned from a
ClusterClassis successfully imported, the corresponding Fleet cluster object has labels identifying theClusterClassname and namespace. - Two clusters from
ClusterClasseswith the same name but in different namespaces get distinct label values and do not interfere with each other. - New Fleet types dependencies should have as minimal impact as possible, consistent with how Turtles handles other Rancher API types.
- Unit tests cover the reconcile logic.
- E2E test covers the full flow: provision a cluster from a
ClusterClass, use this feature to deploy applications to workload cluster (essentially equivalent to the tests we run before CAAPF was deprecated).
Notes
CAAPF reference implementation: https://rancher.github.io/cluster-api-addon-provider-fleet/04_reference/01_import-strategy.html
Source: rancher/rancher