Skip to content

Commit 881a17a

Browse files
authored
Merge pull request #11980 from nrb/backport-annot-prop
[release-1.9] ✨ Sync machine annotations to nodes
2 parents d73c020 + 90f5228 commit 881a17a

17 files changed

+660
-228
lines changed

api/v1beta1/common_types.go

Lines changed: 3 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,19 @@ type MachineReconciler struct {
7474

7575
RemoteConditionsGracePeriod time.Duration
7676

77-
AdditionalSyncMachineLabels []*regexp.Regexp
77+
AdditionalSyncMachineLabels []*regexp.Regexp
78+
AdditionalSyncMachineAnnotations []*regexp.Regexp
7879
}
7980

8081
func (r *MachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
8182
return (&machinecontroller.Reconciler{
82-
Client: r.Client,
83-
APIReader: r.APIReader,
84-
ClusterCache: r.ClusterCache,
85-
WatchFilterValue: r.WatchFilterValue,
86-
RemoteConditionsGracePeriod: r.RemoteConditionsGracePeriod,
87-
AdditionalSyncMachineLabels: r.AdditionalSyncMachineLabels,
83+
Client: r.Client,
84+
APIReader: r.APIReader,
85+
ClusterCache: r.ClusterCache,
86+
WatchFilterValue: r.WatchFilterValue,
87+
RemoteConditionsGracePeriod: r.RemoteConditionsGracePeriod,
88+
AdditionalSyncMachineLabels: r.AdditionalSyncMachineLabels,
89+
AdditionalSyncMachineAnnotations: r.AdditionalSyncMachineAnnotations,
8890
}).SetupWithManager(ctx, mgr, options)
8991
}
9092

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020

2121
| Annotation | Note | Managed By | Applies to |
2222
|:-----------------------------------------------------------------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:-------------------------|:-----------------------------------------------|
23+
| 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)|
2324
| 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 |
2425
| 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 |
2526
| 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) |
2627
| 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) |
2728
| 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 |
2829
| 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 |
30+
| 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)|
2931
| 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 |
3032
| cluster.x-k8s.io/machine | It is set on nodes identifying the machine the node belongs to. | Cluster API | Nodes (workload cluster) |
3133
| 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

Lines changed: 7 additions & 2 deletions
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)