Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/controlplane/kubeadm/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func (src *KubeadmControlPlane) ConvertTo(dstRaw conversion.Hub) error {
// Recover other values
if ok {
bootstrapv1beta1.RestoreKubeadmConfigSpec(&restored.Spec.KubeadmConfigSpec, &dst.Spec.KubeadmConfigSpec)
dst.Spec.MachineTemplate.Spec.Taints = restored.Spec.MachineTemplate.Spec.Taints
}

if src.Spec.RemediationStrategy != nil {
Expand Down Expand Up @@ -134,6 +135,7 @@ func (src *KubeadmControlPlaneTemplate) ConvertTo(dstRaw conversion.Hub) error {
// Recover other values
if ok {
bootstrapv1beta1.RestoreKubeadmConfigSpec(&restored.Spec.Template.Spec.KubeadmConfigSpec, &dst.Spec.Template.Spec.KubeadmConfigSpec)
dst.Spec.Template.Spec.MachineTemplate.Spec.Taints = restored.Spec.Template.Spec.MachineTemplate.Spec.Taints
}

if src.Spec.Template.Spec.RemediationStrategy != nil {
Expand Down
17 changes: 17 additions & 0 deletions api/controlplane/kubeadm/v1beta2/kubeadm_control_plane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,23 @@ type KubeadmControlPlaneMachineTemplateSpec struct {
// deletion contains configuration options for Machine deletion.
// +optional
Deletion KubeadmControlPlaneMachineTemplateDeletionSpec `json:"deletion,omitempty,omitzero"`

// taints are the node taints that Cluster API will manage.
// This list is not necessarily complete: other Kubernetes components may add or remove other taints from nodes,
// e.g. the node controller might add the node.kubernetes.io/not-ready taint.
// Only those taints defined in this list will be added or removed by core Cluster API controllers.
//
// There can be at most 64 taints.
// A pod would have to tolerate all existing taints to run on the corresponding node.
//
// NOTE: This list is implemented as a "map" type, meaning that individual elements can be managed by different owners.
// +optional
// +listType=map
// +listMapKey=key
// +listMapKey=effect
// +kubebuilder:validation:MinItems=1
// +kubebuilder:validation:MaxItems=64
Taints []clusterv1.MachineTaint `json:"taints,omitempty"`
}

// KubeadmControlPlaneMachineTemplateDeletionSpec contains configuration options for Machine deletion.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,23 @@ type KubeadmControlPlaneTemplateMachineTemplateSpec struct {
// deletion contains configuration options for Machine deletion.
// +optional
Deletion KubeadmControlPlaneTemplateMachineTemplateDeletionSpec `json:"deletion,omitempty,omitzero"`

// taints are the node taints that Cluster API will manage.
// This list is not necessarily complete: other Kubernetes components may add or remove other taints from nodes,
// e.g. the node controller might add the node.kubernetes.io/not-ready taint.
// Only those taints defined in this list will be added or removed by core Cluster API controllers.
//
// There can be at most 64 taints.
// A pod would have to tolerate all existing taints to run on the corresponding node.
//
// NOTE: This list is implemented as a "map" type, meaning that individual elements can be managed by different owners.
// +optional
// +listType=map
// +listMapKey=key
// +listMapKey=effect
// +kubebuilder:validation:MinItems=1
// +kubebuilder:validation:MaxItems=64
Taints []clusterv1.MachineTaint `json:"taints,omitempty"`
}

// KubeadmControlPlaneTemplateMachineTemplateDeletionSpec contains configuration options for Machine deletion.
Expand Down
10 changes: 10 additions & 0 deletions api/controlplane/kubeadm/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion controlplane/kubeadm/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ spec:
- "--leader-elect"
- "--diagnostics-address=${CAPI_DIAGNOSTICS_ADDRESS:=:8443}"
- "--insecure-diagnostics=${CAPI_INSECURE_DIAGNOSTICS:=false}"
- "--feature-gates=MachinePool=${EXP_MACHINE_POOL:=true},ClusterTopology=${CLUSTER_TOPOLOGY:=false},KubeadmBootstrapFormatIgnition=${EXP_KUBEADM_BOOTSTRAP_FORMAT_IGNITION:=false},PriorityQueue=${EXP_PRIORITY_QUEUE:=true},ReconcilerRateLimiting=${EXP_RECONCILER_RATE_LIMITING:=false},InPlaceUpdates=${EXP_IN_PLACE_UPDATES:=false}"
- "--feature-gates=MachinePool=${EXP_MACHINE_POOL:=true},ClusterTopology=${CLUSTER_TOPOLOGY:=false},KubeadmBootstrapFormatIgnition=${EXP_KUBEADM_BOOTSTRAP_FORMAT_IGNITION:=false},PriorityQueue=${EXP_PRIORITY_QUEUE:=true},ReconcilerRateLimiting=${EXP_RECONCILER_RATE_LIMITING:=false},InPlaceUpdates=${EXP_IN_PLACE_UPDATES:=false},MachineTaintPropagation=${EXP_MACHINE_TAINT_PROPAGATION:=false}"
image: controller:latest
name: manager
env:
Expand Down
1 change: 1 addition & 0 deletions controlplane/kubeadm/internal/controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ func (r *KubeadmControlPlaneReconciler) syncMachines(ctx context.Context, contro
m.Spec.Deletion.NodeDrainTimeoutSeconds = controlPlane.KCP.Spec.MachineTemplate.Spec.Deletion.NodeDrainTimeoutSeconds
m.Spec.Deletion.NodeDeletionTimeoutSeconds = controlPlane.KCP.Spec.MachineTemplate.Spec.Deletion.NodeDeletionTimeoutSeconds
m.Spec.Deletion.NodeVolumeDetachTimeoutSeconds = controlPlane.KCP.Spec.MachineTemplate.Spec.Deletion.NodeVolumeDetachTimeoutSeconds
m.Spec.Taints = controlPlane.KCP.Spec.MachineTemplate.Spec.Taints

// Note: We intentionally don't set "minReadySeconds" on Machines because we consider it enough to have machine availability driven by readiness of control plane components.
if err := patchHelper.Patch(ctx, m); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func ComputeDesiredMachine(kcp *controlplanev1.KubeadmControlPlane, cluster *clu
desiredMachine.Spec.Deletion.NodeDrainTimeoutSeconds = kcp.Spec.MachineTemplate.Spec.Deletion.NodeDrainTimeoutSeconds
desiredMachine.Spec.Deletion.NodeDeletionTimeoutSeconds = kcp.Spec.MachineTemplate.Spec.Deletion.NodeDeletionTimeoutSeconds
desiredMachine.Spec.Deletion.NodeVolumeDetachTimeoutSeconds = kcp.Spec.MachineTemplate.Spec.Deletion.NodeVolumeDetachTimeoutSeconds
desiredMachine.Spec.Taints = kcp.Spec.MachineTemplate.Spec.Taints

// Note: We intentionally don't set "minReadySeconds" on Machines because we consider it enough to have machine availability driven by readiness of control plane components.
if existingMachine != nil {
Expand Down
42 changes: 42 additions & 0 deletions controlplane/kubeadm/internal/desiredstate/desired_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,47 @@ func Test_ComputeDesiredMachine(t *testing.T) {
isUpdatingExistingMachine: false,
wantErr: false,
},
{
name: "should return the correct Machine object when creating a new Machine with taints",
kcp: &controlplanev1.KubeadmControlPlane{
ObjectMeta: metav1.ObjectMeta{
Name: kcpName,
Namespace: cluster.Namespace,
},
Spec: controlplanev1.KubeadmControlPlaneSpec{
Version: "v1.16.6",
MachineTemplate: controlplanev1.KubeadmControlPlaneMachineTemplate{
ObjectMeta: kcpMachineTemplateObjectMeta,
Spec: controlplanev1.KubeadmControlPlaneMachineTemplateSpec{
Taints: []clusterv1.MachineTaint{
{
Key: "foo",
Effect: "NoSchedule",
Propagation: clusterv1.MachineTaintPropagationAlways,
},
{
Key: "bar",
Effect: "NoExecute",
Propagation: clusterv1.MachineTaintPropagationOnInitialization,
},
},
Deletion: controlplanev1.KubeadmControlPlaneMachineTemplateDeletionSpec{
NodeDrainTimeoutSeconds: duration5s,
NodeDeletionTimeoutSeconds: duration5s,
NodeVolumeDetachTimeoutSeconds: duration5s,
},
},
},
KubeadmConfigSpec: bootstrapv1.KubeadmConfigSpec{
ClusterConfiguration: bootstrapv1.ClusterConfiguration{
CertificatesDir: "foo",
},
},
},
},
isUpdatingExistingMachine: false,
wantErr: false,
},
{
name: "should return the correct Machine object when updating an existing Machine (empty ClusterConfiguration annotation)",
kcp: &controlplanev1.KubeadmControlPlane{
Expand Down Expand Up @@ -497,6 +538,7 @@ func Test_ComputeDesiredMachine(t *testing.T) {
NodeVolumeDetachTimeoutSeconds: tt.kcp.Spec.MachineTemplate.Spec.Deletion.NodeVolumeDetachTimeoutSeconds,
},
ReadinessGates: append(append(MandatoryMachineReadinessGates, etcdMandatoryMachineReadinessGates...), tt.kcp.Spec.MachineTemplate.Spec.ReadinessGates...),
Taints: tt.kcp.Spec.MachineTemplate.Spec.Taints,
}
// Verify Name.
for _, matcher := range tt.want {
Expand Down
3 changes: 3 additions & 0 deletions controlplane/kubeadm/internal/webhooks/kubeadmcontrolplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
controlplanev1 "sigs.k8s.io/cluster-api/api/controlplane/kubeadm/v1beta2"
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
topologynames "sigs.k8s.io/cluster-api/internal/topology/names"
"sigs.k8s.io/cluster-api/internal/util/taints"
"sigs.k8s.io/cluster-api/util/container"
"sigs.k8s.io/cluster-api/util/secret"
"sigs.k8s.io/cluster-api/util/version"
Expand Down Expand Up @@ -339,6 +340,8 @@ func validateKubeadmControlPlaneSpec(s controlplanev1.KubeadmControlPlaneSpec, p
)
}

allErrs = append(allErrs, taints.ValidateMachineTaints(s.MachineTemplate.Spec.Taints, pathPrefix.Child("machineTemplate", "spec", "taints"))...)

// Validate the metadata of the MachineTemplate
allErrs = append(allErrs, s.MachineTemplate.ObjectMeta.Validate(pathPrefix.Child("machineTemplate", "metadata"))...)

Expand Down
Loading
Loading