diff --git a/modules/k8s/deployment.go b/modules/k8s/deployment.go index dceab1c56..14225bb97 100644 --- a/modules/k8s/deployment.go +++ b/modules/k8s/deployment.go @@ -98,11 +98,13 @@ func WaitUntilDeploymentAvailableE( // IsDeploymentAvailable returns true if all pods within the deployment are ready and started func IsDeploymentAvailable(deploy *appsv1.Deployment) bool { - availableType := 0 - - if deploy.Status.UnavailableReplicas > 0 { - return false + for _, dc := range deploy.Status.Conditions { + if dc.Type == appsv1.DeploymentProgressing && + dc.Status == v1.ConditionTrue && + dc.Reason == "NewReplicaSetAvailable" { + return true + } } - return deploy.Status.Conditions[availableType].Status == v1.ConditionTrue + return false } diff --git a/modules/k8s/deployment_test.go b/modules/k8s/deployment_test.go index 4314168e0..7dde12468 100644 --- a/modules/k8s/deployment_test.go +++ b/modules/k8s/deployment_test.go @@ -18,7 +18,8 @@ import ( "github.com/gruntwork-io/terratest/modules/random" "github.com/stretchr/testify/require" - v1 "k8s.io/api/apps/v1" + appsv1 "k8s.io/api/apps/v1" + v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -76,36 +77,38 @@ func TestWaitUntilDeploymentAvailable(t *testing.T) { func TestTestIsDeploymentAvailable(t *testing.T) { testCases := []struct { title string - deploy *v1.Deployment + deploy *appsv1.Deployment expectedResult bool }{ { - title: "TestIsDeploymentAvailableReadyButWithUnavailableReplicas", - deploy: &v1.Deployment{ - Status: v1.DeploymentStatus{ - UnavailableReplicas: 1, - Conditions: []v1.DeploymentCondition{ + title: "TestIsDeploymentAvailableWithProgressingNewReplicaSetAvailable", + deploy: &appsv1.Deployment{ + Status: appsv1.DeploymentStatus{ + Conditions: []appsv1.DeploymentCondition{ { - Status: "True", + Type: appsv1.DeploymentProgressing, + Status: v1.ConditionTrue, + Reason: "NewReplicaSetAvailable", }, }, }, }, - expectedResult: false, + expectedResult: true, }, { - title: "TestIsDeploymentAvailableReadyButWithoutUnavailableReplicas", - deploy: &v1.Deployment{ - Status: v1.DeploymentStatus{ - UnavailableReplicas: 0, - Conditions: []v1.DeploymentCondition{ + title: "TestIsDeploymentAvailableWithoutProgressingNewReplicaSetAvailable", + deploy: &appsv1.Deployment{ + Status: appsv1.DeploymentStatus{ + Conditions: []appsv1.DeploymentCondition{ { - Status: "True", + Type: appsv1.DeploymentProgressing, + Status: v1.ConditionTrue, + Reason: "ReplicaSetUpdated", }, }, }, }, - expectedResult: true, + expectedResult: false, }, }