Skip to content

Commit

Permalink
Merge pull request #1278 from marcellmartini/bug/issue-1277
Browse files Browse the repository at this point in the history
Fix the check in IsDeploymentAvailable function.
  • Loading branch information
denis256 committed Apr 30, 2023
2 parents e78d052 + 28e8c23 commit cd88b02
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
12 changes: 7 additions & 5 deletions modules/k8s/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
35 changes: 19 additions & 16 deletions modules/k8s/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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,
},
}

Expand Down

0 comments on commit cd88b02

Please sign in to comment.