-
Notifications
You must be signed in to change notification settings - Fork 22
OCPBUGS-79418: ctrl: sched: add topologySpreadConstraints to deployment #4177
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
c04e8f7
9a2cee9
e192eb5
9a8f010
f30a924
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,11 +24,14 @@ import ( | |
| "k8s.io/klog/v2" | ||
| ) | ||
|
|
||
| // ForDeploymentComplete waits for the deployment to be complete with the number of replicas specified in the deployment spec. | ||
| func (wt Waiter) ForDeploymentComplete(ctx context.Context, dp *appsv1.Deployment) (*appsv1.Deployment, error) { | ||
| // This function waits for the readiness of the pods under the deployment. The best use of this check is for | ||
| // completely new deployments. If the deployment exists on the cluster and simply updated, this check is | ||
| // not enough to guarantee that the deployment is ready with the NEW replica, thus need to cover that by | ||
| // additional checks as the context requires | ||
| return wt.ForDeploymentCompleteWithReplicas(ctx, dp, *(dp.Spec.Replicas)) | ||
| } | ||
|
|
||
| // ForDeploymentCompleteWithReplicas waits for the deployment to be complete and have the specified number of replicas. | ||
| // Use this function when the deployment is expected to have new number of replicas after an update. | ||
| func (wt Waiter) ForDeploymentCompleteWithReplicas(ctx context.Context, dp *appsv1.Deployment, newExpectedReplicas int32) (*appsv1.Deployment, error) { | ||
|
Member
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. good addition. If most of the codebase actually uses the pattern and at glance it seems the case, it's worth keeping the old API
Member
Author
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 intentionally updated the codebase because ForDeploymentComplete without having the correct expected replicas count does not sound complete and can be confusing. Internally in the function, replicas check is a core one and in order to avoid using the incorrect function for deployment waiter I overrode the old API. This was actually an old bug as noted in the omitted comment; the new version is expected to handle all deployments now.
Member
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, so let's just rename
Member
Author
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. in the latest push I restored ForDeploymentComplete to keep the diff as less as possible to reduce conflicts while backporting. I can address changing the whole code base in a followup PR including #4177 (comment) |
||
| key := ObjectKeyFromObject(dp) | ||
| updatedDp := &appsv1.Deployment{} | ||
| immediate := true | ||
|
|
@@ -39,7 +42,7 @@ func (wt Waiter) ForDeploymentComplete(ctx context.Context, dp *appsv1.Deploymen | |
| return false, err | ||
| } | ||
|
|
||
| if !IsDeploymentComplete(dp, &updatedDp.Status) { | ||
| if !IsDeploymentComplete(dp.Generation, &updatedDp.Status, newExpectedReplicas) { | ||
| klog.Warningf("deployment %s not yet complete", key.String()) | ||
| return false, nil | ||
| } | ||
|
|
@@ -51,14 +54,28 @@ func (wt Waiter) ForDeploymentComplete(ctx context.Context, dp *appsv1.Deploymen | |
| } | ||
|
|
||
| func areDeploymentReplicasAvailable(newStatus *appsv1.DeploymentStatus, replicas int32) bool { | ||
| return newStatus.UpdatedReplicas == replicas && | ||
| newStatus.Replicas == replicas && | ||
| newStatus.AvailableReplicas == replicas | ||
| if newStatus.Replicas != replicas { | ||
| klog.InfoS("newStatus.Replicas", "expected", replicas, "found", newStatus.Replicas) | ||
| return false | ||
| } | ||
| if newStatus.UpdatedReplicas != replicas { | ||
| klog.InfoS("newStatus.UpdatedReplicas", "expected", replicas, "found", newStatus.UpdatedReplicas) | ||
| return false | ||
| } | ||
| if newStatus.AvailableReplicas != replicas { | ||
| klog.InfoS("newStatus.AvailableReplicas", "expected", replicas, "found", newStatus.AvailableReplicas) | ||
| return false | ||
| } | ||
| return true | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
|
|
||
| func IsDeploymentComplete(dp *appsv1.Deployment, newStatus *appsv1.DeploymentStatus) bool { | ||
| return areDeploymentReplicasAvailable(newStatus, *(dp.Spec.Replicas)) && | ||
| newStatus.ObservedGeneration >= dp.Generation | ||
| func IsDeploymentComplete(oldGeneration int64, newStatus *appsv1.DeploymentStatus, expectedReplicas int32) bool { | ||
|
ffromani marked this conversation as resolved.
|
||
| if newStatus.ObservedGeneration < oldGeneration { | ||
| klog.InfoS("generation is older than expected to indicate the deployment is complete", "old", oldGeneration, "new", newStatus.ObservedGeneration) | ||
| return false | ||
| } | ||
|
|
||
| return areDeploymentReplicasAvailable(newStatus, expectedReplicas) | ||
| } | ||
|
|
||
| func (wt Waiter) ForDeploymentReplicasCreation(ctx context.Context, dp *appsv1.Deployment, expectedReplicas int32) (*appsv1.Deployment, error) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.