Skip to content

Commit 1d500d6

Browse files
author
Yuvaraj Kakaraparthi
committed
add NodeVolumeDetachTimeout to Cluster topology
1 parent a543dd6 commit 1d500d6

File tree

11 files changed

+70
-3
lines changed

11 files changed

+70
-3
lines changed

api/v1alpha4/conversion.go

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ func (src *Cluster) ConvertTo(dstRaw conversion.Hub) error {
4747
dst.Spec.Topology.ControlPlane.NodeDrainTimeout = restored.Spec.Topology.ControlPlane.NodeDrainTimeout
4848
}
4949

50+
if restored.Spec.Topology.ControlPlane.NodeVolumeDetachTimeout != nil {
51+
dst.Spec.Topology.ControlPlane.NodeVolumeDetachTimeout = restored.Spec.Topology.ControlPlane.NodeVolumeDetachTimeout
52+
}
53+
5054
if restored.Spec.Topology.ControlPlane.NodeDeletionTimeout != nil {
5155
dst.Spec.Topology.ControlPlane.NodeDeletionTimeout = restored.Spec.Topology.ControlPlane.NodeDeletionTimeout
5256
}

api/v1alpha4/zz_generated.conversion.go

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta1/cluster_types.go

+5
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ type ControlPlaneTopology struct {
122122
// +optional
123123
NodeDrainTimeout *metav1.Duration `json:"nodeDrainTimeout,omitempty"`
124124

125+
// NodeVolumeDetachTimeout is the total amount of time that the controller will spend on waiting for all volumes
126+
// to be detached. The default value is 0, meaning that the volumes can be detached without any time limitations.
127+
// +optional
128+
NodeVolumeDetachTimeout *metav1.Duration `json:"nodeVolumeDetachTimeout,omitempty"`
129+
125130
// NodeDeletionTimeout defines how long the controller will attempt to delete the Node that the Machine
126131
// hosts after the Machine is marked for deletion. A duration of 0 will retry deletion indefinitely.
127132
// Defaults to 10 seconds.

api/v1beta1/zz_generated.deepcopy.go

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta1/zz_generated.openapi.go

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/cluster.x-k8s.io_clusters.yaml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/contract/controlplane.go

+7
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,13 @@ func (c *ControlPlaneMachineTemplate) NodeDrainTimeout() *Duration {
227227
}
228228
}
229229

230+
// NodeVolumeDetachTimeout provides access to the nodeVolumeDetachTimeout of a MachineTemplate.
231+
func (c *ControlPlaneMachineTemplate) NodeVolumeDetachTimeout() *Duration {
232+
return &Duration{
233+
path: Path{"spec", "machineTemplate", "nodeVolumeDetachTimeout"},
234+
}
235+
}
236+
230237
// NodeDeletionTimeout provides access to the nodeDeletionTimeout of a MachineTemplate.
231238
func (c *ControlPlaneMachineTemplate) NodeDeletionTimeout() *Duration {
232239
return &Duration{

internal/contract/controlplane_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,28 @@ func TestControlPlane(t *testing.T) {
171171
g.Expect(durationString).To(Equal(expectedDurationString))
172172
})
173173

174+
t.Run("Manages spec.machineTemplate.nodeVolumeDetachTimeout", func(t *testing.T) {
175+
g := NewWithT(t)
176+
177+
duration := metav1.Duration{Duration: 2*time.Minute + 10*time.Second}
178+
expectedDurationString := "2m10s"
179+
g.Expect(ControlPlane().MachineTemplate().NodeVolumeDetachTimeout().Path()).To(Equal(Path{"spec", "machineTemplate", "nodeVolumeDetachTimeout"}))
180+
181+
err := ControlPlane().MachineTemplate().NodeVolumeDetachTimeout().Set(obj, duration)
182+
g.Expect(err).ToNot(HaveOccurred())
183+
184+
got, err := ControlPlane().MachineTemplate().NodeVolumeDetachTimeout().Get(obj)
185+
g.Expect(err).ToNot(HaveOccurred())
186+
g.Expect(got).ToNot(BeNil())
187+
g.Expect(*got).To(Equal(duration))
188+
189+
// Check that the literal string value of the duration is correctly formatted.
190+
durationString, found, err := unstructured.NestedString(obj.UnstructuredContent(), "spec", "machineTemplate", "nodeVolumeDetachTimeout")
191+
g.Expect(err).ToNot(HaveOccurred())
192+
g.Expect(found).To(BeTrue())
193+
g.Expect(durationString).To(Equal(expectedDurationString))
194+
})
195+
174196
t.Run("Manages spec.machineTemplate.nodeDeletionTimeout", func(t *testing.T) {
175197
g := NewWithT(t)
176198

internal/controllers/topology/cluster/desired_state.go

+7
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,13 @@ func (r *Reconciler) computeControlPlane(ctx context.Context, s *scope.Scope, in
242242
}
243243
}
244244

245+
// If it is required to manage the NodeVolumeDetachTimeout for the control plane, set the corresponding field.
246+
if s.Blueprint.Topology.ControlPlane.NodeVolumeDetachTimeout != nil {
247+
if err := contract.ControlPlane().MachineTemplate().NodeVolumeDetachTimeout().Set(controlPlane, *s.Blueprint.Topology.ControlPlane.NodeVolumeDetachTimeout); err != nil {
248+
return nil, errors.Wrap(err, "failed to set spec.machineTemplate.nodeVolumeDetachTimeout in the ControlPlane object")
249+
}
250+
}
251+
245252
// If it is required to manage the NodeDeletionTimeout for the control plane, set the corresponding field.
246253
if s.Blueprint.Topology.ControlPlane.NodeDeletionTimeout != nil {
247254
if err := contract.ControlPlane().MachineTemplate().NodeDeletionTimeout().Set(controlPlane, *s.Blueprint.Topology.ControlPlane.NodeDeletionTimeout); err != nil {

internal/controllers/topology/cluster/desired_state_test.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ func TestComputeControlPlane(t *testing.T) {
263263
replicas := int32(3)
264264
duration := 10 * time.Second
265265
nodeDrainTimeout := metav1.Duration{Duration: duration}
266+
nodeVolumeDetachTimeout := metav1.Duration{Duration: duration}
266267
nodeDeletionTimeout := metav1.Duration{Duration: duration}
267268
cluster := &clusterv1.Cluster{
268269
ObjectMeta: metav1.ObjectMeta{
@@ -277,9 +278,10 @@ func TestComputeControlPlane(t *testing.T) {
277278
Labels: map[string]string{"l2": ""},
278279
Annotations: map[string]string{"a2": ""},
279280
},
280-
Replicas: &replicas,
281-
NodeDrainTimeout: &nodeDrainTimeout,
282-
NodeDeletionTimeout: &nodeDeletionTimeout,
281+
Replicas: &replicas,
282+
NodeDrainTimeout: &nodeDrainTimeout,
283+
NodeVolumeDetachTimeout: &nodeVolumeDetachTimeout,
284+
NodeDeletionTimeout: &nodeDeletionTimeout,
283285
},
284286
},
285287
},
@@ -317,6 +319,7 @@ func TestComputeControlPlane(t *testing.T) {
317319
assertNestedField(g, obj, version, contract.ControlPlane().Version().Path()...)
318320
assertNestedField(g, obj, int64(replicas), contract.ControlPlane().Replicas().Path()...)
319321
assertNestedField(g, obj, duration.String(), contract.ControlPlane().MachineTemplate().NodeDrainTimeout().Path()...)
322+
assertNestedField(g, obj, duration.String(), contract.ControlPlane().MachineTemplate().NodeVolumeDetachTimeout().Path()...)
320323
assertNestedField(g, obj, duration.String(), contract.ControlPlane().MachineTemplate().NodeDeletionTimeout().Path()...)
321324
assertNestedFieldUnset(g, obj, contract.ControlPlane().MachineTemplate().InfrastructureRef().Path()...)
322325

internal/controllers/topology/cluster/patches/engine.go

+1
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ func updateDesiredState(ctx context.Context, req *runtimehooksv1.GeneratePatches
371371
contract.ControlPlane().MachineTemplate().Metadata().Path(),
372372
contract.ControlPlane().MachineTemplate().InfrastructureRef().Path(),
373373
contract.ControlPlane().MachineTemplate().NodeDrainTimeout().Path(),
374+
contract.ControlPlane().MachineTemplate().NodeVolumeDetachTimeout().Path(),
374375
contract.ControlPlane().MachineTemplate().NodeDeletionTimeout().Path(),
375376
contract.ControlPlane().Replicas().Path(),
376377
contract.ControlPlane().Version().Path(),

0 commit comments

Comments
 (0)