Commit 83a77fa5 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #38299 from kargakis/calculate-unavailable-correctly

Automatic merge from submit-queue (batch tested with PRs 38608, 38299) controller: set unavailableReplicas correctly when scaling down ``` deployment_controller.go:299] Error syncing deployment e2e-tests-kubectl-2l7xx/e2e-test-nginx-deployment: Deployment.extensions "e2e-test-nginx-deployment" is invalid: status.unavailableReplicas: Invalid value: -1: must be greater than or equal to 0 ``` The validation error above occurs usually when a Deployment is scaled down. In such a case we should default unavailableReplicas to 0 instead of making an invalid api call. @kubernetes/deployment
parents b2047ad4 c82cae85
......@@ -573,6 +573,12 @@ func (dc *DeploymentController) syncDeploymentStatus(allRSs []*extensions.Replic
func (dc *DeploymentController) calculateStatus(allRSs []*extensions.ReplicaSet, newRS *extensions.ReplicaSet, deployment *extensions.Deployment) extensions.DeploymentStatus {
availableReplicas := deploymentutil.GetAvailableReplicaCountForReplicaSets(allRSs)
totalReplicas := deploymentutil.GetReplicaCountForReplicaSets(allRSs)
unavailableReplicas := totalReplicas - availableReplicas
// If unavailableReplicas is negative, then that means the Deployment has more available replicas running than
// desired, eg. whenever it scales down. In such a case we should simply default unavailableReplicas to zero.
if unavailableReplicas < 0 {
unavailableReplicas = 0
}
if availableReplicas >= *(deployment.Spec.Replicas)-deploymentutil.MaxUnavailable(*deployment) {
minAvailability := deploymentutil.NewDeploymentCondition(extensions.DeploymentAvailable, v1.ConditionTrue, deploymentutil.MinimumReplicasAvailable, "Deployment has minimum availability.")
......@@ -588,7 +594,7 @@ func (dc *DeploymentController) calculateStatus(allRSs []*extensions.ReplicaSet,
Replicas: deploymentutil.GetActualReplicaCountForReplicaSets(allRSs),
UpdatedReplicas: deploymentutil.GetActualReplicaCountForReplicaSets([]*extensions.ReplicaSet{newRS}),
AvailableReplicas: availableReplicas,
UnavailableReplicas: totalReplicas - availableReplicas,
UnavailableReplicas: unavailableReplicas,
Conditions: deployment.Status.Conditions,
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment