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 7182629 commit 750c9cd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions api/v1alpha4/machinedeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"`

Expand Down
4 changes: 2 additions & 2 deletions controllers/machinedeployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 750c9cd

Please sign in to comment.