From 750c9cd0d40f33c8dcaea09c051744a17f980bd7 Mon Sep 17 00:00:00 2001 From: Enxebre Date: Thu, 9 Sep 2021 13:03:43 +0200 Subject: [PATCH] Add MachineDeployment rolloutAfter support --- api/v1alpha4/machinedeployment_types.go | 10 ++++++---- controllers/machinedeployment_controller.go | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/api/v1alpha4/machinedeployment_types.go b/api/v1alpha4/machinedeployment_types.go index e6d95e5058a2..96e819ccbd74 100644 --- a/api/v1alpha4/machinedeployment_types.go +++ b/api/v1alpha4/machinedeployment_types.go @@ -33,8 +33,11 @@ const ( OnDeleteMachineDeploymentStrategyType MachineDeploymentStrategyType = "OnDelete" // RevisionAnnotation is the revision annotation of a machine deployment's machine sets which records its rollout sequence. - RevisionAnnotation = "machinedeployment.clusters.x-k8s.io/revision" - RolloutAfterAnnotation = "machinedeployment.clusters.x-k8s.io/RolloutAfterAnnotation" + RevisionAnnotation = "machinedeployment.clusters.x-k8s.io/revision" + + // RolledoutAfterAnnotation annotates the MachineTemplateSpec to trigger a + // MachineDeployment rollout when the RolloutAfter criteria is met. + RolledoutAfterAnnotation = "machinedeployment.clusters.x-k8s.io/RolledoutAfter" // RevisionHistoryAnnotation maintains the history of all old revisions that a machine set has served for a machine deployment. RevisionHistoryAnnotation = "machinedeployment.clusters.x-k8s.io/revision-history" @@ -58,8 +61,7 @@ type MachineDeploymentSpec struct { // +kubebuilder:validation:MinLength=1 ClusterName string `json:"clusterName"` - // RolloutAfter performs a rollout of the entire cluster one component at a time, - // control plane first and then machine deployments. + // RolloutAfter performs a rollout of the MachineDeployment, // +optional RolloutAfter *metav1.Time `json:"rolloutAfter,omitempty"` diff --git a/controllers/machinedeployment_controller.go b/controllers/machinedeployment_controller.go index 51de17943350..3f53926a3958 100644 --- a/controllers/machinedeployment_controller.go +++ b/controllers/machinedeployment_controller.go @@ -223,9 +223,9 @@ func (r *MachineDeploymentReconciler) reconcile(ctx context.Context, cluster *cl // TODO (alberto): store this in the reconciler. now := metav1.Now() if now.After(d.Spec.RolloutAfter.Time) && - d.Spec.RolloutAfter.Time.String() != d.Spec.Template.Labels[clusterv1.RolloutAfterAnnotation] { + d.Spec.RolloutAfter.Time.String() != d.Spec.Template.Labels[clusterv1.RolledoutAfterAnnotation] { // Triggers rolling update. - d.Spec.Template.Labels[clusterv1.RolloutAfterAnnotation] = d.Spec.RolloutAfter.String() + d.Spec.Template.Labels[clusterv1.RolledoutAfterAnnotation] = d.Spec.RolloutAfter.String() return ctrl.Result{}, r.Client.Update(ctx, d) }