Skip to content
Merged
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
5 changes: 5 additions & 0 deletions api/v1alpha4/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ func (src *Cluster) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.Topology.ControlPlane.NodeDrainTimeout = restored.Spec.Topology.ControlPlane.NodeDrainTimeout
}

if restored.Spec.Topology.ControlPlane.NodeVolumeDetachTimeout != nil {
dst.Spec.Topology.ControlPlane.NodeVolumeDetachTimeout = restored.Spec.Topology.ControlPlane.NodeVolumeDetachTimeout
}

if restored.Spec.Topology.ControlPlane.NodeDeletionTimeout != nil {
dst.Spec.Topology.ControlPlane.NodeDeletionTimeout = restored.Spec.Topology.ControlPlane.NodeDeletionTimeout
}
Expand All @@ -59,6 +63,7 @@ func (src *Cluster) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.Topology.Workers.MachineDeployments[i].FailureDomain = restored.Spec.Topology.Workers.MachineDeployments[i].FailureDomain
dst.Spec.Topology.Workers.MachineDeployments[i].Variables = restored.Spec.Topology.Workers.MachineDeployments[i].Variables
dst.Spec.Topology.Workers.MachineDeployments[i].NodeDrainTimeout = restored.Spec.Topology.Workers.MachineDeployments[i].NodeDrainTimeout
dst.Spec.Topology.Workers.MachineDeployments[i].NodeVolumeDetachTimeout = restored.Spec.Topology.Workers.MachineDeployments[i].NodeVolumeDetachTimeout
dst.Spec.Topology.Workers.MachineDeployments[i].NodeDeletionTimeout = restored.Spec.Topology.Workers.MachineDeployments[i].NodeDeletionTimeout
}
}
Expand Down
2 changes: 2 additions & 0 deletions api/v1alpha4/zz_generated.conversion.go

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

10 changes: 10 additions & 0 deletions api/v1beta1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ type ControlPlaneTopology struct {
// +optional
NodeDrainTimeout *metav1.Duration `json:"nodeDrainTimeout,omitempty"`

// NodeVolumeDetachTimeout is the total amount of time that the controller will spend on waiting for all volumes
// to be detached. The default value is 0, meaning that the volumes can be detached without any time limitations.
// +optional
NodeVolumeDetachTimeout *metav1.Duration `json:"nodeVolumeDetachTimeout,omitempty"`

// NodeDeletionTimeout defines how long the controller will attempt to delete the Node that the Machine
// hosts after the Machine is marked for deletion. A duration of 0 will retry deletion indefinitely.
// Defaults to 10 seconds.
Expand Down Expand Up @@ -173,6 +178,11 @@ type MachineDeploymentTopology struct {
// +optional
NodeDrainTimeout *metav1.Duration `json:"nodeDrainTimeout,omitempty"`

// NodeVolumeDetachTimeout is the total amount of time that the controller will spend on waiting for all volumes
// to be detached. The default value is 0, meaning that the volumes can be detached without any time limitations.
// +optional
NodeVolumeDetachTimeout *metav1.Duration `json:"nodeVolumeDetachTimeout,omitempty"`

// NodeDeletionTimeout defines how long the controller will attempt to delete the Node that the Machine
// hosts after the Machine is marked for deletion. A duration of 0 will retry deletion indefinitely.
// Defaults to 10 seconds.
Expand Down
10 changes: 10 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

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

12 changes: 12 additions & 0 deletions api/v1beta1/zz_generated.openapi.go

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

13 changes: 13 additions & 0 deletions config/crd/bases/cluster.x-k8s.io_clusters.yaml

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

7 changes: 7 additions & 0 deletions internal/contract/controlplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ func (c *ControlPlaneMachineTemplate) NodeDrainTimeout() *Duration {
}
}

// NodeVolumeDetachTimeout provides access to the nodeVolumeDetachTimeout of a MachineTemplate.
func (c *ControlPlaneMachineTemplate) NodeVolumeDetachTimeout() *Duration {
return &Duration{
path: Path{"spec", "machineTemplate", "nodeVolumeDetachTimeout"},
}
}

// NodeDeletionTimeout provides access to the nodeDeletionTimeout of a MachineTemplate.
func (c *ControlPlaneMachineTemplate) NodeDeletionTimeout() *Duration {
return &Duration{
Expand Down
22 changes: 22 additions & 0 deletions internal/contract/controlplane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,28 @@ func TestControlPlane(t *testing.T) {
g.Expect(durationString).To(Equal(expectedDurationString))
})

t.Run("Manages spec.machineTemplate.nodeVolumeDetachTimeout", func(t *testing.T) {
g := NewWithT(t)

duration := metav1.Duration{Duration: 2*time.Minute + 10*time.Second}
expectedDurationString := "2m10s"
g.Expect(ControlPlane().MachineTemplate().NodeVolumeDetachTimeout().Path()).To(Equal(Path{"spec", "machineTemplate", "nodeVolumeDetachTimeout"}))

err := ControlPlane().MachineTemplate().NodeVolumeDetachTimeout().Set(obj, duration)
g.Expect(err).ToNot(HaveOccurred())

got, err := ControlPlane().MachineTemplate().NodeVolumeDetachTimeout().Get(obj)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(got).ToNot(BeNil())
g.Expect(*got).To(Equal(duration))

// Check that the literal string value of the duration is correctly formatted.
durationString, found, err := unstructured.NestedString(obj.UnstructuredContent(), "spec", "machineTemplate", "nodeVolumeDetachTimeout")
g.Expect(err).ToNot(HaveOccurred())
g.Expect(found).To(BeTrue())
g.Expect(durationString).To(Equal(expectedDurationString))
})

t.Run("Manages spec.machineTemplate.nodeDeletionTimeout", func(t *testing.T) {
g := NewWithT(t)

Expand Down
22 changes: 15 additions & 7 deletions internal/controllers/topology/cluster/desired_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,13 @@ func (r *Reconciler) computeControlPlane(ctx context.Context, s *scope.Scope, in
}
}

// If it is required to manage the NodeVolumeDetachTimeout for the control plane, set the corresponding field.
if s.Blueprint.Topology.ControlPlane.NodeVolumeDetachTimeout != nil {
if err := contract.ControlPlane().MachineTemplate().NodeVolumeDetachTimeout().Set(controlPlane, *s.Blueprint.Topology.ControlPlane.NodeVolumeDetachTimeout); err != nil {
return nil, errors.Wrap(err, "failed to set spec.machineTemplate.nodeVolumeDetachTimeout in the ControlPlane object")
}
}

// If it is required to manage the NodeDeletionTimeout for the control plane, set the corresponding field.
if s.Blueprint.Topology.ControlPlane.NodeDeletionTimeout != nil {
if err := contract.ControlPlane().MachineTemplate().NodeDeletionTimeout().Set(controlPlane, *s.Blueprint.Topology.ControlPlane.NodeDeletionTimeout); err != nil {
Expand Down Expand Up @@ -538,13 +545,14 @@ func computeMachineDeployment(_ context.Context, s *scope.Scope, desiredControlP
Annotations: mergeMap(machineDeploymentTopology.Metadata.Annotations, machineDeploymentBlueprint.Metadata.Annotations),
},
Spec: clusterv1.MachineSpec{
ClusterName: s.Current.Cluster.Name,
Version: pointer.String(version),
Bootstrap: clusterv1.Bootstrap{ConfigRef: contract.ObjToRef(desiredMachineDeployment.BootstrapTemplate)},
InfrastructureRef: *contract.ObjToRef(desiredMachineDeployment.InfrastructureMachineTemplate),
FailureDomain: machineDeploymentTopology.FailureDomain,
NodeDrainTimeout: machineDeploymentTopology.NodeDrainTimeout,
NodeDeletionTimeout: machineDeploymentTopology.NodeDeletionTimeout,
ClusterName: s.Current.Cluster.Name,
Version: pointer.String(version),
Bootstrap: clusterv1.Bootstrap{ConfigRef: contract.ObjToRef(desiredMachineDeployment.BootstrapTemplate)},
InfrastructureRef: *contract.ObjToRef(desiredMachineDeployment.InfrastructureMachineTemplate),
FailureDomain: machineDeploymentTopology.FailureDomain,
NodeDrainTimeout: machineDeploymentTopology.NodeDrainTimeout,
NodeVolumeDetachTimeout: machineDeploymentTopology.NodeVolumeDetachTimeout,
NodeDeletionTimeout: machineDeploymentTopology.NodeDeletionTimeout,
},
},
},
Expand Down
23 changes: 14 additions & 9 deletions internal/controllers/topology/cluster/desired_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ func TestComputeControlPlane(t *testing.T) {
replicas := int32(3)
duration := 10 * time.Second
nodeDrainTimeout := metav1.Duration{Duration: duration}
nodeVolumeDetachTimeout := metav1.Duration{Duration: duration}
nodeDeletionTimeout := metav1.Duration{Duration: duration}
cluster := &clusterv1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -277,9 +278,10 @@ func TestComputeControlPlane(t *testing.T) {
Labels: map[string]string{"l2": ""},
Annotations: map[string]string{"a2": ""},
},
Replicas: &replicas,
NodeDrainTimeout: &nodeDrainTimeout,
NodeDeletionTimeout: &nodeDeletionTimeout,
Replicas: &replicas,
NodeDrainTimeout: &nodeDrainTimeout,
NodeVolumeDetachTimeout: &nodeVolumeDetachTimeout,
NodeDeletionTimeout: &nodeDeletionTimeout,
},
},
},
Expand Down Expand Up @@ -317,6 +319,7 @@ func TestComputeControlPlane(t *testing.T) {
assertNestedField(g, obj, version, contract.ControlPlane().Version().Path()...)
assertNestedField(g, obj, int64(replicas), contract.ControlPlane().Replicas().Path()...)
assertNestedField(g, obj, duration.String(), contract.ControlPlane().MachineTemplate().NodeDrainTimeout().Path()...)
assertNestedField(g, obj, duration.String(), contract.ControlPlane().MachineTemplate().NodeVolumeDetachTimeout().Path()...)
assertNestedField(g, obj, duration.String(), contract.ControlPlane().MachineTemplate().NodeDeletionTimeout().Path()...)
assertNestedFieldUnset(g, obj, contract.ControlPlane().MachineTemplate().InfrastructureRef().Path()...)

Expand Down Expand Up @@ -1321,17 +1324,19 @@ func TestComputeMachineDeployment(t *testing.T) {
replicas := int32(5)
failureDomain := "always-up-region"
nodeDrainTimeout := metav1.Duration{Duration: 10 * time.Second}
nodeVolumeDetachTimeout := metav1.Duration{Duration: 10 * time.Second}
nodeDeletionTimeout := metav1.Duration{Duration: 10 * time.Second}
mdTopology := clusterv1.MachineDeploymentTopology{
Metadata: clusterv1.ObjectMeta{
Labels: map[string]string{"foo": "baz"},
},
Class: "linux-worker",
Name: "big-pool-of-machines",
Replicas: &replicas,
FailureDomain: &failureDomain,
NodeDrainTimeout: &nodeDrainTimeout,
NodeDeletionTimeout: &nodeDeletionTimeout,
Class: "linux-worker",
Name: "big-pool-of-machines",
Replicas: &replicas,
FailureDomain: &failureDomain,
NodeDrainTimeout: &nodeDrainTimeout,
NodeVolumeDetachTimeout: &nodeVolumeDetachTimeout,
NodeDeletionTimeout: &nodeDeletionTimeout,
}

t.Run("Generates the machine deployment and the referenced templates", func(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions internal/controllers/topology/cluster/patches/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ func updateDesiredState(ctx context.Context, req *runtimehooksv1.GeneratePatches
contract.ControlPlane().MachineTemplate().Metadata().Path(),
contract.ControlPlane().MachineTemplate().InfrastructureRef().Path(),
contract.ControlPlane().MachineTemplate().NodeDrainTimeout().Path(),
contract.ControlPlane().MachineTemplate().NodeVolumeDetachTimeout().Path(),
contract.ControlPlane().MachineTemplate().NodeDeletionTimeout().Path(),
contract.ControlPlane().Replicas().Path(),
contract.ControlPlane().Version().Path(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ spec:
controlPlane:
metadata: {}
nodeDeletionTimeout: "30s"
nodeVolumeDetachTimeout: "5m"
replicas: ${CONTROL_PLANE_MACHINE_COUNT}
workers:
machineDeployments:
- class: "default-worker"
name: "md-0"
nodeDeletionTimeout: "30s"
nodeVolumeDetachTimeout: "5m"
replicas: ${WORKER_MACHINE_COUNT}
failureDomain: fd4
variables:
Expand Down