Skip to content

Commit

Permalink
Add MachineDeployment rolloutAfter support
Browse files Browse the repository at this point in the history
  • Loading branch information
enxebre committed Sep 9, 2021
1 parent 64277af commit d2072ce
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion api/v1alpha4/machinedeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions controllers/machinedeployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d2072ce

Please sign in to comment.