Skip to content

Commit 9a9b00a

Browse files
nrbtheobarberbanysbueringer
authored
✨ Sync machine annotations to nodes (#11813)
* Sync machine annotattions to nodes Signed-off-by: Nolan Brubaker <[email protected]> * Plumb manager argument through to controller Signed-off-by: Nolan Brubaker <[email protected]> * Manage annotations from previous reconciles Signed-off-by: Nolan Brubaker <[email protected]> * Add e2e test and refactor filtering Signed-off-by: Nolan Brubaker <[email protected]> * Documents new annotations This change documents the new cluster.x-k8s.io/labels-from-machine and cluster.x-k8s.io/annotations-from-machine annotations. * refactor: drop getManaged{Labels, Annotations} wrappers This refactors reconcileNode to remove the getManagedLabels and getManagedAnnotations wrapper functions, in favour of calling the libraries directly. * Moves Tests GetManagedLabels,GetManagedAnnotations This moves the tests for GetManagedLabels and GetManagedAnnotations to their respective util packages, as that's where they're now implemented. * Don't add known CAPI annotatoins to annotations-from-machine Signed-off-by: Nolan Brubaker <[email protected]> * Reduce length of annotation to fix tests Signed-off-by: Nolan Brubaker <[email protected]> * Add more details about a use case Signed-off-by: Nolan Brubaker <[email protected]> * Address review feedback Signed-off-by: Nolan Brubaker <[email protected]> * Apply suggestions from code review Co-authored-by: Stefan Büringer <[email protected]> Signed-off-by: Nolan Brubaker <[email protected]> * Additional review feedback Signed-off-by: Nolan Brubaker <[email protected]> --------- Signed-off-by: Nolan Brubaker <[email protected]> Co-authored-by: Theo Barber-Bany <[email protected]> Co-authored-by: Stefan Büringer <[email protected]>
1 parent 9e7afa7 commit 9a9b00a

17 files changed

+660
-228
lines changed

api/v1beta1/common_types.go

+3
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ const (
9292
// LabelsFromMachineAnnotation is the annotation set on nodes to track the labels originated from machines.
9393
LabelsFromMachineAnnotation = "cluster.x-k8s.io/labels-from-machine"
9494

95+
// AnnotationsFromMachineAnnotation is the annotation set on nodes to track the annotations that originated from machines.
96+
AnnotationsFromMachineAnnotation = "cluster.x-k8s.io/annotations-from-machine"
97+
9598
// OwnerNameAnnotation is the annotation set on nodes identifying the owner name.
9699
OwnerNameAnnotation = "cluster.x-k8s.io/owner-name"
97100

api/v1beta1/machine_types.go

+3
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ const (
8484
NodeRestrictionLabelDomain = "node-restriction.kubernetes.io"
8585
// ManagedNodeLabelDomain is one of the CAPI managed Node label domains.
8686
ManagedNodeLabelDomain = "node.cluster.x-k8s.io"
87+
88+
// ManagedNodeAnnotationDomain is one of the CAPI managed Node annotation domains.
89+
ManagedNodeAnnotationDomain = "node.cluster.x-k8s.io"
8790
)
8891

8992
// Machine's Available condition and corresponding reasons that will be used in v1Beta2 API version.

controllers/alias.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,19 @@ type MachineReconciler struct {
7979

8080
RemoteConditionsGracePeriod time.Duration
8181

82-
AdditionalSyncMachineLabels []*regexp.Regexp
82+
AdditionalSyncMachineLabels []*regexp.Regexp
83+
AdditionalSyncMachineAnnotations []*regexp.Regexp
8384
}
8485

8586
func (r *MachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
8687
return (&machinecontroller.Reconciler{
87-
Client: r.Client,
88-
APIReader: r.APIReader,
89-
ClusterCache: r.ClusterCache,
90-
WatchFilterValue: r.WatchFilterValue,
91-
RemoteConditionsGracePeriod: r.RemoteConditionsGracePeriod,
92-
AdditionalSyncMachineLabels: r.AdditionalSyncMachineLabels,
88+
Client: r.Client,
89+
APIReader: r.APIReader,
90+
ClusterCache: r.ClusterCache,
91+
WatchFilterValue: r.WatchFilterValue,
92+
RemoteConditionsGracePeriod: r.RemoteConditionsGracePeriod,
93+
AdditionalSyncMachineLabels: r.AdditionalSyncMachineLabels,
94+
AdditionalSyncMachineAnnotations: r.AdditionalSyncMachineAnnotations,
9395
}).SetupWithManager(ctx, mgr, options)
9496
}
9597

docs/book/src/reference/api/labels-and-annotations.md

+2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121
| Annotation | Note | Managed By | Applies to |
2222
|:-----------------------------------------------------------------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:-------------------------|:-----------------------------------------------|
2323
| before-upgrade.hook.cluster.cluster.x-k8s.io | It specifies the prefix we search each annotation for during the before-upgrade lifecycle hook to block propagating the new version to the control plane. These hooks will prevent propagation of changes made to the Cluster Topology to the underlying objects. | User | Clusters |
24+
| cluster.x-k8s.io/annotations-from-machine| It is set on nodes to track the annotations that originated from machines.| Cluster API | Nodes (workload cluster)|
2425
| cluster.x-k8s.io/cloned-from-groupkind | It is the annotation that stores the group-kind of the template from which the current resource has been cloned from. | Cluster API | All Cluster API objects cloned from a template |
2526
| cluster.x-k8s.io/cloned-from-name | It is the annotation that stores the name of the template from which the current resource has been cloned from. | Cluster API | All Cluster API objects cloned from a template |
2627
| cluster.x-k8s.io/cluster-name | It is set on nodes identifying the name of the cluster the node belongs to. | Cluster API | Nodes (workload cluster) |
2728
| cluster.x-k8s.io/cluster-namespace | It is set on nodes identifying the namespace of the cluster the node belongs to. | Cluster API | Nodes (workload cluster) |
2829
| cluster.x-k8s.io/delete-machine | It marks control plane and worker nodes that will be given priority for deletion when KCP or a MachineSet scales down. It is given top priority on all delete policies. | User | Machines |
2930
| cluster.x-k8s.io/disable-machine-create | It can be used to signal a MachineSet to stop creating new machines. It is utilized in the OnDelete MachineDeploymentStrategy to allow the MachineDeployment controller to scale down older MachineSets when Machines are deleted and add the new replicas to the latest MachineSet. | Cluster API | MachineSets |
31+
| cluster.x-k8s.io/labels-from-machine| It is set on nodes to track the labels that originated from machines.| Cluster API | Nodes (workload cluster)|
3032
| cluster.x-k8s.io/managed-by | It can be applied to InfraCluster resources to signify that some external system is managing the cluster infrastructure. Provider InfraCluster controllers will ignore resources with this annotation. An external controller must fulfill the contract of the InfraCluster resource. External infrastructure providers should ensure that the annotation, once set, cannot be removed. | User | InfraClusters |
3133
| cluster.x-k8s.io/machine | It is set on nodes identifying the machine the node belongs to. | Cluster API | Nodes (workload cluster) |
3234
| cluster.x-k8s.io/owner-kind | It is set on nodes identifying the machine's owner kind the node belongs to. | Cluster API | Nodes (workload cluster) |

docs/book/src/reference/api/metadata-propagation.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,18 @@ Template labels and annotations continuously propagate to new and existing Machi
5959
- `.spec.template.metadata.annotations` => `Machine.annotations`, `InfraMachine.annotations`, `BootstrapConfig.annotations`
6060

6161
## Machine
62-
Top-level labels that meet a specific cretria are propagated to the Node labels and top-level annotatation are not propagated.
62+
Top-level labels and annotations that meet a specific criteria are propagated to the Node labels and annotations.
6363
- `.labels.[label-meets-criteria]` => `Node.labels`
64-
- `.annotations` => Not propagated.
64+
- `.annotations.[annotation-meets-criteria]` => `Node.annotations`
6565

6666
Labels that meet at least one of the following criteria are always propagated to the Node:
6767
- Has `node-role.kubernetes.io` as prefix.
6868
- Belongs to `node-restriction.kubernetes.io` domain.
6969
- Belongs to `node.cluster.x-k8s.io` domain.
7070

7171
In addition, any labels that match at least one of the regexes provided by the `--additional-sync-machine-labels` flag on the manager will be synced from the Machine to the Node.
72+
73+
Annotations that meet at least one of the following criteria are always propagated to the Node:
74+
- Belongs to `node.cluster.x-k8s.io` domain
75+
76+
In addition, any annotations that match at least one of the regexes provided by the `--additional-sync-machine-annotations` flag on the manager will be synced from the Machine to the Node.

0 commit comments

Comments
 (0)