@@ -99,6 +99,9 @@ const (
9999 // AnnotationsFromMachineAnnotation is the annotation set on nodes to track the annotations that originated from machines.
100100 AnnotationsFromMachineAnnotation = "cluster.x-k8s.io/annotations-from-machine"
101101
102+ // TaintsFromMachineAnnotation is the annotation set on nodes to track the taints that originated from machines.
103+ TaintsFromMachineAnnotation = "cluster.x-k8s.io/taints-from-machine"
104+
102105 // OwnerNameAnnotation is the annotation set on nodes identifying the owner name.
103106 OwnerNameAnnotation = "cluster.x-k8s.io/owner-name"
104107
@@ -405,3 +408,58 @@ func (r *ContractVersionedObjectReference) GroupKind() schema.GroupKind {
405408 Kind : r .Kind ,
406409 }
407410}
411+
412+ // MachineTaint defines a taint equivalent to corev1.Taint, but additionally having a propagation field.
413+ type MachineTaint struct {
414+ // key is the taint key to be applied to a node.
415+ // Must be a valid qualified name of maximum size 63 characters
416+ // with an optional subdomain prefix of maximum size 253 characters,
417+ // separated by a `/`.
418+ // +required
419+ // +kubebuilder:validation:MinLength=1
420+ // +kubebuilder:validation:MaxLength=317
421+ // +kubebuilder:validation:Pattern=^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*\/)?([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]$
422+ // +kubebuilder:validation:XValidation:rule="self.contains('/') ? ( self.split('/') [0].size() <= 253 && self.split('/') [1].size() <= 63 && self.split('/').size() == 2 ) : self.size() <= 63",message="key must be a valid qualified name of max size 63 characters with an optional subdomain prefix of max size 253 characters"
423+ Key string `json:"key,omitempty"`
424+
425+ // value is the taint value corresponding to the taint key.
426+ // It must be a valid label value of maximum size 63 characters.
427+ // +optional
428+ // +kubebuilder:validation:MinLength=1
429+ // +kubebuilder:validation:MaxLength=63
430+ // +kubebuilder:validation:Pattern=^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$
431+ Value string `json:"value,omitempty"`
432+
433+ // effect is the effect for the taint. Valid values are NoSchedule, PreferNoSchedule and NoExecute.
434+ // +required
435+ // +kubebuilder:validation:Enum=NoSchedule;PreferNoSchedule;NoExecute
436+ Effect corev1.TaintEffect `json:"effect,omitempty"`
437+
438+ // propagation defines how this taint should be propagated to nodes.
439+ // Valid values are 'Always' and 'OnInitialization'.
440+ // Always: The taint will be continuously reconciled. If it is not set for a node, it will be added during reconciliation.
441+ // OnInitialization: The taint will be added during node initialization. If it gets removed from the node later on it will not get added again.
442+ // +required
443+ Propagation MachineTaintPropagation `json:"propagation,omitempty"`
444+ }
445+
446+ // MachineTaintPropagation defines when a taint should be propagated to nodes.
447+ // +kubebuilder:validation:Enum=Always;OnInitialization
448+ type MachineTaintPropagation string
449+
450+ const (
451+ // MachineTaintPropagationAlways means the taint should be continuously reconciled and kept on the node.
452+ // - If an Always taint is added to the Machine, the taint will be added to the node.
453+ // - If an Always taint is removed from the Machine, the taint will be removed from the node.
454+ // - If an OnInitialization taint is changed to Always, the Machine controller will ensure the taint is set on the node.
455+ // - If an Always taint is removed from the node, it will be re-added during reconciliation.
456+ MachineTaintPropagationAlways MachineTaintPropagation = "Always"
457+
458+ // MachineTaintPropagationOnInitialization means the taint should be set once during initialization and then
459+ // left alone.
460+ // - If an OnInitialization taint is added to the Machine, the taint will only be added to the node on initialization.
461+ // - If an OnInitialization taint is removed from the Machine nothing will be changed on the node.
462+ // - If an Always taint is changed to OnInitialization, the taint will only be added to the node on initialization.
463+ // - If an OnInitialization taint is removed from the node, it will not be re-added during reconciliation.
464+ MachineTaintPropagationOnInitialization MachineTaintPropagation = "OnInitialization"
465+ )
0 commit comments