diff --git a/api/v1alpha4/machinedeployment_types.go b/api/v1alpha4/machinedeployment_types.go index 805a9dcc924c..e6d95e5058a2 100644 --- a/api/v1alpha4/machinedeployment_types.go +++ b/api/v1alpha4/machinedeployment_types.go @@ -33,7 +33,8 @@ 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" + RevisionAnnotation = "machinedeployment.clusters.x-k8s.io/revision" + RolloutAfterAnnotation = "machinedeployment.clusters.x-k8s.io/RolloutAfterAnnotation" // 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" @@ -57,6 +58,11 @@ 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. + // +optional + RolloutAfter *metav1.Time `json:"rolloutAfter,omitempty"` + // Number of desired machines. Defaults to 1. // This is a pointer to distinguish between explicit zero and not specified. // +optional diff --git a/controllers/machinedeployment_controller.go b/controllers/machinedeployment_controller.go index b11e6162ca16..51de17943350 100644 --- a/controllers/machinedeployment_controller.go +++ b/controllers/machinedeployment_controller.go @@ -220,6 +220,15 @@ func (r *MachineDeploymentReconciler) reconcile(ctx context.Context, cluster *cl return ctrl.Result{}, errors.Errorf("missing MachineDeployment strategy") } + // 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] { + // Triggers rolling update. + d.Spec.Template.Labels[clusterv1.RolloutAfterAnnotation] = d.Spec.RolloutAfter.String() + return ctrl.Result{}, r.Client.Update(ctx, d) + } + if d.Spec.Strategy.Type == clusterv1.RollingUpdateMachineDeploymentStrategyType { if d.Spec.Strategy.RollingUpdate == nil { return ctrl.Result{}, errors.Errorf("missing MachineDeployment settings for strategy type: %s", d.Spec.Strategy.Type)