mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-10-31 18:28:13 +00:00 
			
		
		
		
	Deployments complete only when all desired pods are available
Signed-off-by: Michail Kargakis <mkargaki@redhat.com>
This commit is contained in:
		| @@ -410,7 +410,7 @@ func SetReplicasAnnotations(rs *extensions.ReplicaSet, desiredReplicas, maxRepli | |||||||
|  |  | ||||||
| // MaxUnavailable returns the maximum unavailable pods a rolling deployment can take. | // MaxUnavailable returns the maximum unavailable pods a rolling deployment can take. | ||||||
| func MaxUnavailable(deployment extensions.Deployment) int32 { | func MaxUnavailable(deployment extensions.Deployment) int32 { | ||||||
| 	if !IsRollingUpdate(&deployment) { | 	if !IsRollingUpdate(&deployment) || *(deployment.Spec.Replicas) == 0 { | ||||||
| 		return int32(0) | 		return int32(0) | ||||||
| 	} | 	} | ||||||
| 	// Error caught by validation | 	// Error caught by validation | ||||||
| @@ -828,12 +828,12 @@ func IsRollingUpdate(deployment *extensions.Deployment) bool { | |||||||
| 	return deployment.Spec.Strategy.Type == extensions.RollingUpdateDeploymentStrategyType | 	return deployment.Spec.Strategy.Type == extensions.RollingUpdateDeploymentStrategyType | ||||||
| } | } | ||||||
|  |  | ||||||
| // DeploymentComplete considers a deployment to be complete once its desired replicas equals its | // DeploymentComplete considers a deployment to be complete once all of its desired replicas | ||||||
| // updatedReplicas, no old pods are running, and it doesn't violate minimum availability. | // are updated and available, and no old pods are running. | ||||||
| func DeploymentComplete(deployment *extensions.Deployment, newStatus *extensions.DeploymentStatus) bool { | func DeploymentComplete(deployment *extensions.Deployment, newStatus *extensions.DeploymentStatus) bool { | ||||||
| 	return newStatus.UpdatedReplicas == *(deployment.Spec.Replicas) && | 	return newStatus.UpdatedReplicas == *(deployment.Spec.Replicas) && | ||||||
| 		newStatus.Replicas == *(deployment.Spec.Replicas) && | 		newStatus.Replicas == *(deployment.Spec.Replicas) && | ||||||
| 		newStatus.AvailableReplicas >= *(deployment.Spec.Replicas)-MaxUnavailable(*deployment) && | 		newStatus.AvailableReplicas == *(deployment.Spec.Replicas) && | ||||||
| 		newStatus.ObservedGeneration >= deployment.Generation | 		newStatus.ObservedGeneration >= deployment.Generation | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -960,37 +960,43 @@ func TestDeploymentComplete(t *testing.T) { | |||||||
| 		expected bool | 		expected bool | ||||||
| 	}{ | 	}{ | ||||||
| 		{ | 		{ | ||||||
| 			name: "complete", | 			name: "not complete: min but not all pods become available", | ||||||
|  |  | ||||||
| 			d:        deployment(5, 5, 5, 4, 1, 0), | 			d:        deployment(5, 5, 5, 4, 1, 0), | ||||||
| 			expected: true, | 			expected: false, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			name: "not complete", | 			name: "not complete: min availability is not honored", | ||||||
|  |  | ||||||
| 			d:        deployment(5, 5, 5, 3, 1, 0), | 			d:        deployment(5, 5, 5, 3, 1, 0), | ||||||
| 			expected: false, | 			expected: false, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			name: "complete #2", | 			name: "complete", | ||||||
|  |  | ||||||
| 			d:        deployment(5, 5, 5, 5, 0, 0), | 			d:        deployment(5, 5, 5, 5, 0, 0), | ||||||
| 			expected: true, | 			expected: true, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			name: "not complete #2", | 			name: "not complete: all pods are available but not updated", | ||||||
|  |  | ||||||
| 			d:        deployment(5, 5, 4, 5, 0, 0), | 			d:        deployment(5, 5, 4, 5, 0, 0), | ||||||
| 			expected: false, | 			expected: false, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			name: "not complete #3", | 			name: "not complete: still running old pods", | ||||||
|  |  | ||||||
| 			// old replica set: spec.replicas=1, status.replicas=1, status.availableReplicas=1 | 			// old replica set: spec.replicas=1, status.replicas=1, status.availableReplicas=1 | ||||||
| 			// new replica set: spec.replicas=1, status.replicas=1, status.availableReplicas=0 | 			// new replica set: spec.replicas=1, status.replicas=1, status.availableReplicas=0 | ||||||
| 			d:        deployment(1, 2, 1, 1, 0, 1), | 			d:        deployment(1, 2, 1, 1, 0, 1), | ||||||
| 			expected: false, | 			expected: false, | ||||||
| 		}, | 		}, | ||||||
|  | 		{ | ||||||
|  | 			name: "not complete: one replica deployment never comes up", | ||||||
|  |  | ||||||
|  | 			d:        deployment(1, 1, 1, 0, 1, 1), | ||||||
|  | 			expected: false, | ||||||
|  | 		}, | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	for _, test := range tests { | 	for _, test := range tests { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Michail Kargakis
					Michail Kargakis