Skip to content

Commit a79dfea

Browse files
committed
Restructure KCP spec.rollout fields
Signed-off-by: Stefan Büringer buringerst@vmware.com
1 parent f84e6ca commit a79dfea

24 files changed

+223
-241
lines changed

.golangci-kal.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ linters:
167167
linters:
168168
- kubeapilinter
169169
- path: "api/controlplane/kubeadm/v1beta2"
170-
text: "optionalfields: field (Spec|ObjectMeta|KubeadmConfigSpec|Remediation) is optional and should (be a pointer|have the omitempty tag)"
170+
text: "optionalfields: field (Spec|ObjectMeta|KubeadmConfigSpec|Remediation|Rollout|Before) is optional and should (be a pointer|have the omitempty tag)"
171171
linters:
172172
- kubeapilinter
173173
- path: "api/core/v1beta2/cluster_types.go"

api/controlplane/kubeadm/v1beta1/conversion.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ func Convert_v1beta2_KubeadmControlPlaneSpec_To_v1beta1_KubeadmControlPlaneSpec(
169169
return err
170170
}
171171
}
172+
if !reflect.DeepEqual(in.Rollout.Before, controlplanev1.KubeadmControlPlaneRolloutBeforeSpec{}) {
173+
out.RolloutBefore = &RolloutBefore{}
174+
if in.Rollout.Before.CertificatesExpiryDays != 0 { // 0 was never a valid value
175+
out.RolloutBefore.CertificatesExpiryDays = ptr.To(in.Rollout.Before.CertificatesExpiryDays)
176+
}
177+
}
178+
out.RolloutAfter = in.Rollout.After
172179

173180
return nil
174181
}
@@ -183,6 +190,10 @@ func Convert_v1beta1_KubeadmControlPlaneSpec_To_v1beta2_KubeadmControlPlaneSpec(
183190
return err
184191
}
185192
}
193+
if in.RolloutBefore != nil && in.RolloutBefore.CertificatesExpiryDays != nil {
194+
out.Rollout.Before.CertificatesExpiryDays = *in.RolloutBefore.CertificatesExpiryDays
195+
}
196+
out.Rollout.After = in.RolloutAfter
186197

187198
return nil
188199
}
@@ -198,6 +209,13 @@ func Convert_v1beta2_KubeadmControlPlaneTemplateResourceSpec_To_v1beta1_KubeadmC
198209
return err
199210
}
200211
}
212+
if !reflect.DeepEqual(in.Rollout.Before, controlplanev1.KubeadmControlPlaneRolloutBeforeSpec{}) {
213+
out.RolloutBefore = &RolloutBefore{}
214+
if in.Rollout.Before.CertificatesExpiryDays != 0 { // 0 was never a valid value
215+
out.RolloutBefore.CertificatesExpiryDays = ptr.To(in.Rollout.Before.CertificatesExpiryDays)
216+
}
217+
}
218+
out.RolloutAfter = in.Rollout.After
201219

202220
return nil
203221
}
@@ -212,6 +230,10 @@ func Convert_v1beta1_KubeadmControlPlaneTemplateResourceSpec_To_v1beta2_KubeadmC
212230
return err
213231
}
214232
}
233+
if in.RolloutBefore != nil && in.RolloutBefore.CertificatesExpiryDays != nil {
234+
out.Rollout.Before.CertificatesExpiryDays = *in.RolloutBefore.CertificatesExpiryDays
235+
}
236+
out.Rollout.After = in.RolloutAfter
215237

216238
return nil
217239
}

api/controlplane/kubeadm/v1beta1/conversion_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ func KubeadmControlPlaneTemplateFuzzFuncs(_ runtimeserializer.CodecFactory) []in
9999
spokeDiscovery,
100100
hubKubeadmConfigSpec,
101101
hubNodeRegistrationOptions,
102+
spokeKubeadmControlPlaneTemplate,
102103
spokeRemediationStrategy,
103104
spokeKubeadmControlPlaneTemplateMachineTemplate,
104105
spokeBootstrapToken,
@@ -162,6 +163,10 @@ func spokeKubeadmControlPlane(in *KubeadmControlPlane, c randfill.Continue) {
162163
in.Spec.MachineTemplate.InfrastructureRef.UID = ""
163164
in.Spec.MachineTemplate.InfrastructureRef.ResourceVersion = ""
164165
in.Spec.MachineTemplate.InfrastructureRef.FieldPath = ""
166+
167+
if reflect.DeepEqual(in.Spec.RolloutBefore, &RolloutBefore{}) {
168+
in.Spec.RolloutBefore = nil
169+
}
165170
}
166171

167172
func hubKubeadmControlPlaneStatus(in *controlplanev1.KubeadmControlPlaneStatus, c randfill.Continue) {
@@ -232,6 +237,14 @@ func spokeClusterConfiguration(in *bootstrapv1beta1.ClusterConfiguration, c rand
232237
in.ClusterName = ""
233238
}
234239

240+
func spokeKubeadmControlPlaneTemplate(in *KubeadmControlPlaneTemplate, c randfill.Continue) {
241+
c.FillNoCustom(in)
242+
243+
if reflect.DeepEqual(in.Spec.Template.Spec.RolloutBefore, &RolloutBefore{}) {
244+
in.Spec.Template.Spec.RolloutBefore = nil
245+
}
246+
}
247+
235248
func spokeRemediationStrategy(in *RemediationStrategy, c randfill.Continue) {
236249
c.FillNoCustom(in)
237250

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

Lines changed: 6 additions & 38 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: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -444,19 +444,9 @@ type KubeadmControlPlaneSpec struct {
444444
// +optional
445445
KubeadmConfigSpec bootstrapv1.KubeadmConfigSpec `json:"kubeadmConfigSpec,omitempty,omitzero"`
446446

447-
// rolloutBefore is a field to indicate a rollout should be performed
448-
// if the specified criteria is met.
447+
// rollout defines the rollout behavior.
449448
// +optional
450-
RolloutBefore *RolloutBefore `json:"rolloutBefore,omitempty"`
451-
452-
// rolloutAfter is a field to indicate a rollout should be performed
453-
// after the specified time even if no changes have been made to the
454-
// KubeadmControlPlane.
455-
// Example: In the YAML the time can be specified in the RFC3339 format.
456-
// To specify the rolloutAfter target as March 9, 2023, at 9 am UTC
457-
// use "2023-03-09T09:00:00Z".
458-
// +optional
459-
RolloutAfter *metav1.Time `json:"rolloutAfter,omitempty"`
449+
Rollout KubeadmControlPlaneRolloutSpec `json:"rollout,omitempty,omitzero"`
460450

461451
// rolloutStrategy is the RolloutStrategy to use to replace control plane machines with
462452
// new ones.
@@ -540,12 +530,32 @@ type KubeadmControlPlaneMachineTemplateDeletionSpec struct {
540530
NodeDeletionTimeoutSeconds *int32 `json:"nodeDeletionTimeoutSeconds,omitempty"`
541531
}
542532

543-
// RolloutBefore describes when a rollout should be performed on the KCP machines.
544-
type RolloutBefore struct {
533+
// KubeadmControlPlaneRolloutSpec defines the rollout behavior.
534+
// +kubebuilder:validation:MinProperties=1
535+
type KubeadmControlPlaneRolloutSpec struct {
536+
// before is a field to indicate a rollout should be performed
537+
// if the specified criteria is met.
538+
// +optional
539+
Before KubeadmControlPlaneRolloutBeforeSpec `json:"before,omitempty,omitzero"`
540+
541+
// after is a field to indicate a rollout should be performed
542+
// after the specified time even if no changes have been made to the
543+
// KubeadmControlPlane.
544+
// Example: In the YAML the time can be specified in the RFC3339 format.
545+
// To specify the rolloutAfter target as March 9, 2023, at 9 am UTC
546+
// use "2023-03-09T09:00:00Z".
547+
// +optional
548+
After *metav1.Time `json:"after,omitempty"`
549+
}
550+
551+
// KubeadmControlPlaneRolloutBeforeSpec describes when a rollout should be performed on the KCP machines.
552+
// +kubebuilder:validation:MinProperties=1
553+
type KubeadmControlPlaneRolloutBeforeSpec struct {
545554
// certificatesExpiryDays indicates a rollout needs to be performed if the
546555
// certificates of the machine will expire within the specified days.
547556
// +optional
548-
CertificatesExpiryDays *int32 `json:"certificatesExpiryDays,omitempty"`
557+
// +kubebuilder:validation:Minimum=7
558+
CertificatesExpiryDays int32 `json:"certificatesExpiryDays,omitempty"`
549559
}
550560

551561
// RolloutStrategy describes how to replace existing machines

api/controlplane/kubeadm/v1beta2/kubeadmcontrolplanetemplate_types.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,9 @@ type KubeadmControlPlaneTemplateResourceSpec struct {
9595
// +optional
9696
KubeadmConfigSpec bootstrapv1.KubeadmConfigSpec `json:"kubeadmConfigSpec,omitempty,omitzero"`
9797

98-
// rolloutBefore is a field to indicate a rollout should be performed
99-
// if the specified criteria is met.
100-
//
98+
// rollout defines the rollout behavior.
10199
// +optional
102-
RolloutBefore *RolloutBefore `json:"rolloutBefore,omitempty"`
103-
104-
// rolloutAfter is a field to indicate a rollout should be performed
105-
// after the specified time even if no changes have been made to the
106-
// KubeadmControlPlane.
107-
//
108-
// +optional
109-
RolloutAfter *metav1.Time `json:"rolloutAfter,omitempty"`
100+
Rollout KubeadmControlPlaneRolloutSpec `json:"rollout,omitempty,omitzero"`
110101

111102
// rolloutStrategy is the RolloutStrategy to use to replace control plane machines with
112103
// new ones.

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

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

cmd/clusterctl/client/alpha/kubeadmcontrolplane.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func getKubeadmControlPlane(ctx context.Context, proxy cluster.Proxy, name, name
4949

5050
// setRolloutAfterOnKCP sets KubeadmControlPlane.spec.rolloutAfter.
5151
func setRolloutAfterOnKCP(ctx context.Context, proxy cluster.Proxy, name, namespace string) error {
52-
patch := client.RawPatch(types.MergePatchType, []byte(fmt.Sprintf(`{"spec":{"rolloutAfter":"%v"}}`, time.Now().Format(time.RFC3339))))
52+
patch := client.RawPatch(types.MergePatchType, []byte(fmt.Sprintf(`{"spec":{"rollout":{"after":"%v"}}}`, time.Now().Format(time.RFC3339))))
5353
return patchKubeadmControlPlane(ctx, proxy, name, namespace, patch)
5454
}
5555

cmd/clusterctl/client/alpha/rollout_restarter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (r *rollout) ObjectRestarter(ctx context.Context, proxy cluster.Proxy, ref
5353
if annotations.HasPaused(kcp.GetObjectMeta()) {
5454
return errors.Errorf("can't restart paused KubeadmControlPlane (remove annotation 'cluster.x-k8s.io/paused' first): %v/%v", ref.Kind, ref.Name)
5555
}
56-
if kcp.Spec.RolloutAfter != nil && kcp.Spec.RolloutAfter.After(time.Now()) {
56+
if kcp.Spec.Rollout.After != nil && kcp.Spec.Rollout.After.After(time.Now()) {
5757
return errors.Errorf("can't update KubeadmControlPlane (remove 'spec.rolloutAfter' first): %v/%v", ref.Kind, ref.Name)
5858
}
5959
if err := setRolloutAfterOnKCP(ctx, proxy, ref.Name, ref.Namespace); err != nil {

0 commit comments

Comments
 (0)