-
Notifications
You must be signed in to change notification settings - Fork 1.4k
✨ Adds AvailableCondition and ReadyCondition Conditions to MachineDeployment
#4625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ import ( | |
| clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4" | ||
| "sigs.k8s.io/cluster-api/util" | ||
| "sigs.k8s.io/cluster-api/util/annotations" | ||
| "sigs.k8s.io/cluster-api/util/conditions" | ||
| "sigs.k8s.io/cluster-api/util/patch" | ||
| "sigs.k8s.io/cluster-api/util/predicates" | ||
| ctrl "sigs.k8s.io/controller-runtime" | ||
|
|
@@ -129,7 +130,12 @@ func (r *MachineDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Re | |
|
|
||
| defer func() { | ||
| // Always attempt to patch the object and status after each reconciliation. | ||
| if err := patchHelper.Patch(ctx, deployment); err != nil { | ||
| // Patch ObservedGeneration only if the reconciliation completed successfully | ||
| patchOpts := []patch.Option{} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see the := approach used far more frequently in the capi code base. If you don't mind, I will leave it as is. |
||
| if reterr == nil { | ||
| patchOpts = append(patchOpts, patch.WithStatusObservedGeneration{}) | ||
| } | ||
| if err := patchMachineDeployment(ctx, patchHelper, deployment, patchOpts...); err != nil { | ||
| reterr = kerrors.NewAggregate([]error{reterr, err}) | ||
| } | ||
| }() | ||
|
|
@@ -148,6 +154,24 @@ func (r *MachineDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Re | |
| return result, err | ||
| } | ||
|
|
||
| func patchMachineDeployment(ctx context.Context, patchHelper *patch.Helper, d *clusterv1.MachineDeployment, options ...patch.Option) error { | ||
| // Always update the readyCondition by summarizing the state of other conditions. | ||
| conditions.SetSummary(d, | ||
| conditions.WithConditions( | ||
| clusterv1.MachineDeploymentAvailableCondition, | ||
| ), | ||
| ) | ||
|
|
||
| // Patch the object, ignoring conflicts on the conditions owned by this controller. | ||
| options = append(options, | ||
| patch.WithOwnedConditions{Conditions: []clusterv1.ConditionType{ | ||
| clusterv1.ReadyCondition, | ||
| clusterv1.MachineDeploymentAvailableCondition, | ||
| }}, | ||
| ) | ||
| return patchHelper.Patch(ctx, d, options...) | ||
| } | ||
|
|
||
| func (r *MachineDeploymentReconciler) reconcile(ctx context.Context, cluster *clusterv1.Cluster, d *clusterv1.MachineDeployment) (ctrl.Result, error) { | ||
| log := ctrl.LoggerFrom(ctx) | ||
| log.V(4).Info("Reconcile MachineDeployment") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ import ( | |
| clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4" | ||
| "sigs.k8s.io/cluster-api/controllers/mdutil" | ||
| "sigs.k8s.io/cluster-api/util" | ||
| "sigs.k8s.io/cluster-api/util/conditions" | ||
| "sigs.k8s.io/cluster-api/util/patch" | ||
| ctrl "sigs.k8s.io/controller-runtime" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
|
|
@@ -353,6 +354,16 @@ func (r *MachineDeploymentReconciler) scale(ctx context.Context, deployment *clu | |
| // syncDeploymentStatus checks if the status is up-to-date and sync it if necessary. | ||
| func (r *MachineDeploymentReconciler) syncDeploymentStatus(allMSs []*clusterv1.MachineSet, newMS *clusterv1.MachineSet, d *clusterv1.MachineDeployment) error { | ||
| d.Status = calculateStatus(allMSs, newMS, d) | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. may be add a comment here that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the only other strategy I see implemented today is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As today maxUnavailable and MaxSurge are only applicable when I think reinforcing this would make it easier for new folks to ramp up and avoid confusion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. Added the comment. |
||
| // minReplicasNeeded will be equal to d.Spec.Replicas when the strategy is not RollingUpdateMachineDeploymentStrategyType. | ||
| minReplicasNeeded := *(d.Spec.Replicas) - mdutil.MaxUnavailable(*d) | ||
|
|
||
| if d.Status.AvailableReplicas >= minReplicasNeeded { | ||
| // NOTE: The structure of calculateStatus() does not allow us to update the machinedeployment directly, we can only update the status obj it returns. Ideally, we should change calculateStatus() --> updateStatus() to be consistent with the rest of the code base, until then, we update conditions here. | ||
Arvinderpal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| conditions.MarkTrue(d, clusterv1.MachineDeploymentAvailableCondition) | ||
| } else { | ||
| conditions.MarkFalse(d, clusterv1.MachineDeploymentAvailableCondition, clusterv1.WaitingForAvailableMachinesReason, clusterv1.ConditionSeverityWarning, "Minimum availability requires %d replicas, current %d available", minReplicasNeeded, d.Status.AvailableReplicas) | ||
| } | ||
Arvinderpal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return nil | ||
| } | ||
|
|
||
|
|
@@ -380,6 +391,7 @@ func calculateStatus(allMSs []*clusterv1.MachineSet, newMS *clusterv1.MachineSet | |
| ReadyReplicas: mdutil.GetReadyReplicaCountForMachineSets(allMSs), | ||
| AvailableReplicas: availableReplicas, | ||
| UnavailableReplicas: unavailableReplicas, | ||
| Conditions: deployment.Status.Conditions, | ||
| } | ||
|
|
||
| if *deployment.Spec.Replicas == status.ReadyReplicas { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.