From 7f4670d622345ee077abe7a76f635bb2f9bb4fa4 Mon Sep 17 00:00:00 2001 From: Michail Kargakis Date: Tue, 21 Mar 2017 13:24:14 -0400 Subject: [PATCH] Disable readyReplicas validation for Deployments Because there is no field in 1.5, when we update to 1.6 and the controller tries to update the Deployment, it will be denied by validation because the pre-existing availableReplicas field is greater than readyReplicas (normally readyReplicas should always be greater or equal). --- pkg/apis/extensions/validation/validation.go | 4 +++- pkg/apis/extensions/validation/validation_test.go | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/apis/extensions/validation/validation.go b/pkg/apis/extensions/validation/validation.go index 3b309cef7f0..3181624cb03 100644 --- a/pkg/apis/extensions/validation/validation.go +++ b/pkg/apis/extensions/validation/validation.go @@ -352,7 +352,9 @@ func ValidateDeploymentStatus(status *extensions.DeploymentStatus, fldPath *fiel if status.AvailableReplicas > status.Replicas { allErrs = append(allErrs, field.Invalid(fldPath.Child("availableReplicas"), status.AvailableReplicas, msg)) } - if status.AvailableReplicas > status.ReadyReplicas { + // TODO: ReadyReplicas is introduced in 1.6 and this check breaks the Deployment controller when pre-1.6 clusters get upgraded. + // Remove the comparison to zero once we stop supporting upgrades from 1.5. + if status.ReadyReplicas > 0 && status.AvailableReplicas > status.ReadyReplicas { allErrs = append(allErrs, field.Invalid(fldPath.Child("availableReplicas"), status.AvailableReplicas, "cannot be greater than readyReplicas")) } return allErrs diff --git a/pkg/apis/extensions/validation/validation_test.go b/pkg/apis/extensions/validation/validation_test.go index 5a0d2b089e4..4bf65cd71cd 100644 --- a/pkg/apis/extensions/validation/validation_test.go +++ b/pkg/apis/extensions/validation/validation_test.go @@ -1290,6 +1290,15 @@ func TestValidateDeploymentStatus(t *testing.T) { observedGeneration: 1, expectedErr: true, }, + // TODO: Remove the following test case once we stop supporting upgrades from 1.5. + { + name: "don't validate readyReplicas when it's zero", + replicas: 3, + readyReplicas: 0, + availableReplicas: 3, + observedGeneration: 1, + expectedErr: false, + }, } for _, test := range tests {