Skip to content

Commit c30eaea

Browse files
authored
Merge pull request #12499 from sbueringer/pr-deletion-grouping
2 parents 79d6f0a + 1cf8729 commit c30eaea

File tree

99 files changed

+2683
-1639
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+2683
-1639
lines changed

.golangci-kal.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ linters:
186186
text: "optionalfields: field AddressRef is optional and should (be a pointer|have the omitempty tag)"
187187
linters:
188188
- kubeapilinter
189+
- path: "api/core/v1beta2/*|api/controlplane/kubeadm/v1beta2/*"
190+
text: "optionalfields: field Deletion is optional and should (be a pointer|have the omitempty tag)"
191+
linters:
192+
- kubeapilinter
189193

190194
issues:
191195
max-same-issues: 0

api/controlplane/kubeadm/v1beta1/conversion.go

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (src *KubeadmControlPlane) ConvertTo(dstRaw conversion.Hub) error {
5454
if err != nil {
5555
return err
5656
}
57-
dst.Spec.MachineTemplate.InfrastructureRef = *infraRef
57+
dst.Spec.MachineTemplate.Spec.InfrastructureRef = *infraRef
5858

5959
// Manually restore data.
6060
restored := &controlplanev1.KubeadmControlPlane{}
@@ -102,7 +102,7 @@ func (dst *KubeadmControlPlane) ConvertFrom(srcRaw conversion.Hub) error {
102102
return err
103103
}
104104

105-
infraRef, err := convertToObjectReference(&src.Spec.MachineTemplate.InfrastructureRef, src.Namespace)
105+
infraRef, err := convertToObjectReference(&src.Spec.MachineTemplate.Spec.InfrastructureRef, src.Namespace)
106106
if err != nil {
107107
return err
108108
}
@@ -258,38 +258,56 @@ func Convert_v1beta1_KubeadmControlPlaneMachineTemplate_To_v1beta2_KubeadmContro
258258
if err := autoConvert_v1beta1_KubeadmControlPlaneMachineTemplate_To_v1beta2_KubeadmControlPlaneMachineTemplate(in, out, s); err != nil {
259259
return err
260260
}
261-
out.NodeDrainTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeDrainTimeout)
262-
out.NodeVolumeDetachTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeVolumeDetachTimeout)
263-
out.NodeDeletionTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeDeletionTimeout)
261+
if in.ReadinessGates != nil {
262+
in, out := &in.ReadinessGates, &out.Spec.ReadinessGates
263+
*out = make([]clusterv1.MachineReadinessGate, len(*in))
264+
for i := range *in {
265+
if err := clusterv1beta1.Convert_v1beta1_MachineReadinessGate_To_v1beta2_MachineReadinessGate(&(*in)[i], &(*out)[i], s); err != nil {
266+
return err
267+
}
268+
}
269+
}
270+
out.Spec.Deletion.NodeDrainTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeDrainTimeout)
271+
out.Spec.Deletion.NodeVolumeDetachTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeVolumeDetachTimeout)
272+
out.Spec.Deletion.NodeDeletionTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeDeletionTimeout)
264273
return nil
265274
}
266275
func Convert_v1beta2_KubeadmControlPlaneMachineTemplate_To_v1beta1_KubeadmControlPlaneMachineTemplate(in *controlplanev1.KubeadmControlPlaneMachineTemplate, out *KubeadmControlPlaneMachineTemplate, s apimachineryconversion.Scope) error {
267276
if err := autoConvert_v1beta2_KubeadmControlPlaneMachineTemplate_To_v1beta1_KubeadmControlPlaneMachineTemplate(in, out, s); err != nil {
268277
return err
269278
}
270-
out.NodeDrainTimeout = clusterv1.ConvertFromSeconds(in.NodeDrainTimeoutSeconds)
271-
out.NodeVolumeDetachTimeout = clusterv1.ConvertFromSeconds(in.NodeVolumeDetachTimeoutSeconds)
272-
out.NodeDeletionTimeout = clusterv1.ConvertFromSeconds(in.NodeDeletionTimeoutSeconds)
279+
if in.Spec.ReadinessGates != nil {
280+
in, out := &in.Spec.ReadinessGates, &out.ReadinessGates
281+
*out = make([]clusterv1beta1.MachineReadinessGate, len(*in))
282+
for i := range *in {
283+
if err := clusterv1beta1.Convert_v1beta2_MachineReadinessGate_To_v1beta1_MachineReadinessGate(&(*in)[i], &(*out)[i], s); err != nil {
284+
return err
285+
}
286+
}
287+
}
288+
out.NodeDrainTimeout = clusterv1.ConvertFromSeconds(in.Spec.Deletion.NodeDrainTimeoutSeconds)
289+
out.NodeVolumeDetachTimeout = clusterv1.ConvertFromSeconds(in.Spec.Deletion.NodeVolumeDetachTimeoutSeconds)
290+
out.NodeDeletionTimeout = clusterv1.ConvertFromSeconds(in.Spec.Deletion.NodeDeletionTimeoutSeconds)
273291
return nil
274292
}
275293

276294
func Convert_v1beta1_KubeadmControlPlaneTemplateMachineTemplate_To_v1beta2_KubeadmControlPlaneTemplateMachineTemplate(in *KubeadmControlPlaneTemplateMachineTemplate, out *controlplanev1.KubeadmControlPlaneTemplateMachineTemplate, s apimachineryconversion.Scope) error {
277295
if err := autoConvert_v1beta1_KubeadmControlPlaneTemplateMachineTemplate_To_v1beta2_KubeadmControlPlaneTemplateMachineTemplate(in, out, s); err != nil {
278296
return err
279297
}
280-
out.NodeDrainTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeDrainTimeout)
281-
out.NodeVolumeDetachTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeVolumeDetachTimeout)
282-
out.NodeDeletionTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeDeletionTimeout)
298+
out.Spec.Deletion.NodeDrainTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeDrainTimeout)
299+
out.Spec.Deletion.NodeVolumeDetachTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeVolumeDetachTimeout)
300+
out.Spec.Deletion.NodeDeletionTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeDeletionTimeout)
283301
return nil
284302
}
285303

286304
func Convert_v1beta2_KubeadmControlPlaneTemplateMachineTemplate_To_v1beta1_KubeadmControlPlaneTemplateMachineTemplate(in *controlplanev1.KubeadmControlPlaneTemplateMachineTemplate, out *KubeadmControlPlaneTemplateMachineTemplate, s apimachineryconversion.Scope) error {
287305
if err := autoConvert_v1beta2_KubeadmControlPlaneTemplateMachineTemplate_To_v1beta1_KubeadmControlPlaneTemplateMachineTemplate(in, out, s); err != nil {
288306
return err
289307
}
290-
out.NodeDrainTimeout = clusterv1.ConvertFromSeconds(in.NodeDrainTimeoutSeconds)
291-
out.NodeVolumeDetachTimeout = clusterv1.ConvertFromSeconds(in.NodeVolumeDetachTimeoutSeconds)
292-
out.NodeDeletionTimeout = clusterv1.ConvertFromSeconds(in.NodeDeletionTimeoutSeconds)
308+
out.NodeDrainTimeout = clusterv1.ConvertFromSeconds(in.Spec.Deletion.NodeDrainTimeoutSeconds)
309+
out.NodeVolumeDetachTimeout = clusterv1.ConvertFromSeconds(in.Spec.Deletion.NodeVolumeDetachTimeoutSeconds)
310+
out.NodeDeletionTimeout = clusterv1.ConvertFromSeconds(in.Spec.Deletion.NodeDeletionTimeoutSeconds)
293311
return nil
294312
}
295313

api/controlplane/kubeadm/v1beta1/conversion_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ func hubMachineTemplateSpec(in *controlplanev1.KubeadmControlPlaneMachineTemplat
147147

148148
// Ensure ref field is always set to realistic values.
149149
gvk := testGVKs[c.Int31n(4)]
150-
in.InfrastructureRef.APIGroup = gvk.Group
151-
in.InfrastructureRef.Kind = gvk.Kind
150+
in.Spec.InfrastructureRef.APIGroup = gvk.Group
151+
in.Spec.InfrastructureRef.Kind = gvk.Kind
152152
}
153153

154154
func spokeKubeadmControlPlane(in *KubeadmControlPlane, c randfill.Continue) {

api/controlplane/kubeadm/v1beta1/zz_generated.conversion.go

Lines changed: 4 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/controlplane/kubeadm/v1beta2/kubeadm_control_plane_types.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,15 @@ type KubeadmControlPlaneMachineTemplate struct {
482482
// +optional
483483
ObjectMeta clusterv1.ObjectMeta `json:"metadata,omitempty,omitzero"`
484484

485+
// spec defines the spec for Machines
486+
// in a KubeadmControlPlane object.
487+
// +required
488+
Spec KubeadmControlPlaneMachineTemplateSpec `json:"spec,omitempty,omitzero"`
489+
}
490+
491+
// KubeadmControlPlaneMachineTemplateSpec defines the spec for Machines
492+
// in a KubeadmControlPlane object.
493+
type KubeadmControlPlaneMachineTemplateSpec struct {
485494
// infrastructureRef is a required reference to a custom resource
486495
// offered by an infrastructure provider.
487496
// +required
@@ -502,6 +511,14 @@ type KubeadmControlPlaneMachineTemplate struct {
502511
// +kubebuilder:validation:MaxItems=32
503512
ReadinessGates []clusterv1.MachineReadinessGate `json:"readinessGates,omitempty"`
504513

514+
// deletion contains configuration options for Machine deletion.
515+
// +optional
516+
Deletion KubeadmControlPlaneMachineTemplateDeletionSpec `json:"deletion,omitempty,omitzero"`
517+
}
518+
519+
// KubeadmControlPlaneMachineTemplateDeletionSpec contains configuration options for Machine deletion.
520+
// +kubebuilder:validation:MinProperties=1
521+
type KubeadmControlPlaneMachineTemplateDeletionSpec struct {
505522
// nodeDrainTimeoutSeconds is the total amount of time that the controller will spend on draining a controlplane node
506523
// The default value is 0, meaning that the node can be drained without any time limitations.
507524
// NOTE: nodeDrainTimeoutSeconds is different from `kubectl drain --timeout`

api/controlplane/kubeadm/v1beta2/kubeadmcontrolplanetemplate_types.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,31 @@ type KubeadmControlPlaneTemplateResourceSpec struct {
130130
// omits ObjectMeta and InfrastructureRef fields. These fields do not make sense on the KubeadmControlPlaneTemplate,
131131
// because they are calculated by the Cluster topology reconciler during reconciliation and thus cannot
132132
// be configured on the KubeadmControlPlaneTemplate.
133+
// +kubebuilder:validation:MinProperties=1
133134
type KubeadmControlPlaneTemplateMachineTemplate struct {
134135
// metadata is the standard object's metadata.
135136
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
136137
// +optional
137138
ObjectMeta clusterv1.ObjectMeta `json:"metadata,omitempty,omitzero"`
138139

140+
// spec defines the spec for Machines
141+
// in a KubeadmControlPlane object.
142+
// +optional
143+
Spec KubeadmControlPlaneTemplateMachineTemplateSpec `json:"spec,omitempty,omitzero"`
144+
}
145+
146+
// KubeadmControlPlaneTemplateMachineTemplateSpec defines the spec for Machines
147+
// in a KubeadmControlPlane object.
148+
// +kubebuilder:validation:MinProperties=1
149+
type KubeadmControlPlaneTemplateMachineTemplateSpec struct {
150+
// deletion contains configuration options for Machine deletion.
151+
// +optional
152+
Deletion KubeadmControlPlaneTemplateMachineTemplateDeletionSpec `json:"deletion,omitempty,omitzero"`
153+
}
154+
155+
// KubeadmControlPlaneTemplateMachineTemplateDeletionSpec contains configuration options for Machine deletion.
156+
// +kubebuilder:validation:MinProperties=1
157+
type KubeadmControlPlaneTemplateMachineTemplateDeletionSpec struct {
139158
// nodeDrainTimeoutSeconds is the total amount of time that the controller will spend on draining a controlplane node
140159
// The default value is 0, meaning that the node can be drained without any time limitations.
141160
// NOTE: nodeDrainTimeoutSeconds is different from `kubectl drain --timeout`

api/controlplane/kubeadm/v1beta2/zz_generated.deepcopy.go

Lines changed: 75 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)