Skip to content

Commit c1925fb

Browse files
committed
add nodeDrainTimeout to Machine and rety indefinitely
The machine controller now uses the configured timeout when deleting the Node belonging to a Machine. It will also requeue the Machine for reconciliation if deletion fails, which will lead to infinite retries.
1 parent b1ec806 commit c1925fb

20 files changed

+262
-54
lines changed

api/v1alpha3/conversion.go

+8
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ func (src *Machine) ConvertTo(dstRaw conversion.Hub) error {
9696
return err
9797
}
9898

99+
dst.Spec.NodeDeletionTimeout = restored.Spec.NodeDeletionTimeout
99100
dst.Status.NodeInfo = restored.Status.NodeInfo
100101
return nil
101102
}
@@ -138,6 +139,7 @@ func (src *MachineSet) ConvertTo(dstRaw conversion.Hub) error {
138139
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
139140
return err
140141
}
142+
dst.Spec.Template.Spec.NodeDeletionTimeout = restored.Spec.Template.Spec.NodeDeletionTimeout
141143
dst.Status.Conditions = restored.Status.Conditions
142144
return nil
143145
}
@@ -191,6 +193,7 @@ func (src *MachineDeployment) ConvertTo(dstRaw conversion.Hub) error {
191193
dst.Spec.Strategy.RollingUpdate.DeletePolicy = restored.Spec.Strategy.RollingUpdate.DeletePolicy
192194
}
193195

196+
dst.Spec.Template.Spec.NodeDeletionTimeout = restored.Spec.Template.Spec.NodeDeletionTimeout
194197
dst.Status.Conditions = restored.Status.Conditions
195198
return nil
196199
}
@@ -303,6 +306,11 @@ func Convert_v1beta1_MachineStatus_To_v1alpha3_MachineStatus(in *v1beta1.Machine
303306
return autoConvert_v1beta1_MachineStatus_To_v1alpha3_MachineStatus(in, out, s)
304307
}
305308

309+
func Convert_v1beta1_MachineSpec_To_v1alpha3_MachineSpec(in *v1beta1.MachineSpec, out *MachineSpec, s apiconversion.Scope) error {
310+
// spec.nodeDeletionTimeout has been added with v1beta1.
311+
return autoConvert_v1beta1_MachineSpec_To_v1alpha3_MachineSpec(in, out, s)
312+
}
313+
306314
func Convert_v1beta1_MachineDeploymentStatus_To_v1alpha3_MachineDeploymentStatus(in *v1beta1.MachineDeploymentStatus, out *MachineDeploymentStatus, s apiconversion.Scope) error {
307315
// Status.Conditions was introduced in v1alpha4, thus requiring a custom conversion function; the values is going to be preserved in an annotation thus allowing roundtrip without loosing informations
308316
return autoConvert_v1beta1_MachineDeploymentStatus_To_v1alpha3_MachineDeploymentStatus(in, out, s)

api/v1alpha3/zz_generated.conversion.go

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

api/v1alpha4/conversion.go

+63-6
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,33 @@ func (dst *ClusterClassList) ConvertFrom(srcRaw conversion.Hub) error {
119119
func (src *Machine) ConvertTo(dstRaw conversion.Hub) error {
120120
dst := dstRaw.(*v1beta1.Machine)
121121

122-
return Convert_v1alpha4_Machine_To_v1beta1_Machine(src, dst, nil)
122+
if err := Convert_v1alpha4_Machine_To_v1beta1_Machine(src, dst, nil); err != nil {
123+
return err
124+
}
125+
126+
// Manually restore data.
127+
restored := &v1beta1.Machine{}
128+
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
129+
return err
130+
}
131+
132+
dst.Spec.NodeDeletionTimeout = restored.Spec.NodeDeletionTimeout
133+
return nil
123134
}
124135

125136
func (dst *Machine) ConvertFrom(srcRaw conversion.Hub) error {
126137
src := srcRaw.(*v1beta1.Machine)
127138

128-
return Convert_v1beta1_Machine_To_v1alpha4_Machine(src, dst, nil)
139+
if err := Convert_v1beta1_Machine_To_v1alpha4_Machine(src, dst, nil); err != nil {
140+
return err
141+
}
142+
143+
// Preserve Hub data on down-conversion except for metadata
144+
if err := utilconversion.MarshalData(src, dst); err != nil {
145+
return err
146+
}
147+
148+
return nil
129149
}
130150

131151
func (src *MachineList) ConvertTo(dstRaw conversion.Hub) error {
@@ -143,13 +163,29 @@ func (dst *MachineList) ConvertFrom(srcRaw conversion.Hub) error {
143163
func (src *MachineSet) ConvertTo(dstRaw conversion.Hub) error {
144164
dst := dstRaw.(*v1beta1.MachineSet)
145165

146-
return Convert_v1alpha4_MachineSet_To_v1beta1_MachineSet(src, dst, nil)
166+
if err := Convert_v1alpha4_MachineSet_To_v1beta1_MachineSet(src, dst, nil); err != nil {
167+
return err
168+
}
169+
170+
// Manually restore data.
171+
restored := &v1beta1.MachineSet{}
172+
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
173+
return err
174+
}
175+
176+
dst.Spec.Template.Spec.NodeDeletionTimeout = restored.Spec.Template.Spec.NodeDeletionTimeout
177+
return nil
147178
}
148179

149180
func (dst *MachineSet) ConvertFrom(srcRaw conversion.Hub) error {
150181
src := srcRaw.(*v1beta1.MachineSet)
151182

152-
return Convert_v1beta1_MachineSet_To_v1alpha4_MachineSet(src, dst, nil)
183+
if err := Convert_v1beta1_MachineSet_To_v1alpha4_MachineSet(src, dst, nil); err != nil {
184+
return err
185+
}
186+
187+
// Preserve Hub data on down-conversion except for metadata
188+
return utilconversion.MarshalData(src, dst)
153189
}
154190

155191
func (src *MachineSetList) ConvertTo(dstRaw conversion.Hub) error {
@@ -167,13 +203,29 @@ func (dst *MachineSetList) ConvertFrom(srcRaw conversion.Hub) error {
167203
func (src *MachineDeployment) ConvertTo(dstRaw conversion.Hub) error {
168204
dst := dstRaw.(*v1beta1.MachineDeployment)
169205

170-
return Convert_v1alpha4_MachineDeployment_To_v1beta1_MachineDeployment(src, dst, nil)
206+
if err := Convert_v1alpha4_MachineDeployment_To_v1beta1_MachineDeployment(src, dst, nil); err != nil {
207+
return err
208+
}
209+
210+
// Manually restore data.
211+
restored := &v1beta1.MachineDeployment{}
212+
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
213+
return err
214+
}
215+
216+
dst.Spec.Template.Spec.NodeDeletionTimeout = restored.Spec.Template.Spec.NodeDeletionTimeout
217+
return nil
171218
}
172219

173220
func (dst *MachineDeployment) ConvertFrom(srcRaw conversion.Hub) error {
174221
src := srcRaw.(*v1beta1.MachineDeployment)
175222

176-
return Convert_v1beta1_MachineDeployment_To_v1alpha4_MachineDeployment(src, dst, nil)
223+
if err := Convert_v1beta1_MachineDeployment_To_v1alpha4_MachineDeployment(src, dst, nil); err != nil {
224+
return err
225+
}
226+
227+
// Preserve Hub data on down-conversion except for metadata
228+
return utilconversion.MarshalData(src, dst)
177229
}
178230

179231
func (src *MachineDeploymentList) ConvertTo(dstRaw conversion.Hub) error {
@@ -222,6 +274,11 @@ func Convert_v1beta1_ClusterClassSpec_To_v1alpha4_ClusterClassSpec(in *v1beta1.C
222274
return autoConvert_v1beta1_ClusterClassSpec_To_v1alpha4_ClusterClassSpec(in, out, s)
223275
}
224276

277+
func Convert_v1beta1_MachineSpec_To_v1alpha4_MachineSpec(in *v1beta1.MachineSpec, out *MachineSpec, s apiconversion.Scope) error {
278+
// spec.nodeDeletionTimeout has been added with v1beta1.
279+
return autoConvert_v1beta1_MachineSpec_To_v1alpha4_MachineSpec(in, out, s)
280+
}
281+
225282
func Convert_v1beta1_Topology_To_v1alpha4_Topology(in *v1beta1.Topology, out *Topology, s apiconversion.Scope) error {
226283
// spec.topology.variables has been added with v1beta1.
227284
return autoConvert_v1beta1_Topology_To_v1alpha4_Topology(in, out, s)

api/v1alpha4/zz_generated.conversion.go

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

api/v1beta1/machine_types.go

+4
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ type MachineSpec struct {
9595
// NOTE: NodeDrainTimeout is different from `kubectl drain --timeout`
9696
// +optional
9797
NodeDrainTimeout *metav1.Duration `json:"nodeDrainTimeout,omitempty"`
98+
99+
// NodeDeletionTimeout is the timeout used when deleting the Node belonging to a Machine from its
100+
// cluster's api. The default timeout is 10 seconds.
101+
NodeDeletionTimeout *metav1.Duration `json:"nodeDeletionTimeout,omitempty"`
98102
}
99103

100104
// ANCHOR_END: MachineSpec

api/v1beta1/machine_webhook.go

+6
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ package v1beta1
1919
import (
2020
"fmt"
2121
"strings"
22+
"time"
2223

2324
apierrors "k8s.io/apimachinery/pkg/api/errors"
25+
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2426
"k8s.io/apimachinery/pkg/runtime"
2527
"k8s.io/apimachinery/pkg/util/validation/field"
2628
"sigs.k8s.io/cluster-api/util/version"
@@ -59,6 +61,10 @@ func (m *Machine) Default() {
5961
normalizedVersion := "v" + *m.Spec.Version
6062
m.Spec.Version = &normalizedVersion
6163
}
64+
65+
if m.Spec.NodeDeletionTimeout == nil {
66+
m.Spec.NodeDeletionTimeout = &v1.Duration{Duration: 10 * time.Millisecond}
67+
}
6268
}
6369

6470
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.

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.

cmd/clusterctl/config/manifest/clusterctl-api.yaml

+13-4
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,33 @@ spec:
3636
description: Provider defines an entry in the provider inventory.
3737
properties:
3838
apiVersion:
39-
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
39+
description: 'APIVersion defines the versioned schema of this representation
40+
of an object. Servers should convert recognized schemas to the latest
41+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
4042
type: string
4143
kind:
42-
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
44+
description: 'Kind is a string value representing the REST resource this
45+
object represents. Servers may infer this from the endpoint the client
46+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
4347
type: string
4448
metadata:
4549
type: object
4650
providerName:
4751
description: ProviderName indicates the name of the provider.
4852
type: string
4953
type:
50-
description: Type indicates the type of the provider. See ProviderType for a list of supported values
54+
description: Type indicates the type of the provider. See ProviderType
55+
for a list of supported values
5156
type: string
5257
version:
5358
description: Version indicates the component version.
5459
type: string
5560
watchedNamespace:
56-
description: 'WatchedNamespace indicates the namespace where the provider controller is is watching. if empty the provider controller is watching for objects in all namespaces. Deprecated: in clusterctl v1alpha4 all the providers watch all the namespaces; this field will be removed in a future version of this API'
61+
description: 'WatchedNamespace indicates the namespace where the provider
62+
controller is is watching. if empty the provider controller is watching
63+
for objects in all namespaces. Deprecated: in clusterctl v1alpha4 all
64+
the providers watch all the namespaces; this field will be removed in
65+
a future version of this API'
5766
type: string
5867
type: object
5968
served: true

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

+5
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,11 @@ spec:
12851285
description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids'
12861286
type: string
12871287
type: object
1288+
nodeDeletionTimeout:
1289+
description: NodeDeletionTimeout is the timeout used when
1290+
deleting the Node belonging to a Machine from its cluster's
1291+
api. The default timeout is 10 seconds.
1292+
type: string
12881293
nodeDrainTimeout:
12891294
description: 'NodeDrainTimeout is the total amount of time
12901295
that the controller will spend on draining a node. The default

0 commit comments

Comments
 (0)