Skip to content

Commit

Permalink
fix: updated conditions to check for readiness of deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
mfaizanse committed Apr 17, 2024
1 parent 42f2ac4 commit 25ebffa
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 1 deletion.
4 changes: 3 additions & 1 deletion internal/controller/operator/eventing/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,7 @@ func (r *Reconciler) handleEventingState(ctx context.Context, deployment *kappsv
//
//nolint:gochecknoglobals //TODO: refactor the reconciler to support replacing this function without global variable
var IsDeploymentReady = func(deployment *kappsv1.Deployment) bool {
return deployment.Status.AvailableReplicas == *deployment.Spec.Replicas
return deployment.Status.AvailableReplicas == *deployment.Spec.Replicas &&
deployment.Status.ReadyReplicas == *deployment.Spec.Replicas &&
deployment.Status.UpdatedReplicas == *deployment.Spec.Replicas
}
99 changes: 99 additions & 0 deletions internal/controller/operator/eventing/status_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package eventing

import (

Check failure on line 3 in internal/controller/operator/eventing/status_test.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/kyma-project/eventing-manager) -s blank -s dot --custom-order (gci)
"github.com/stretchr/testify/require"
kappsv1 "k8s.io/api/apps/v1"
"k8s.io/utils/ptr"
"testing"

Check failure on line 7 in internal/controller/operator/eventing/status_test.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/kyma-project/eventing-manager) -s blank -s dot --custom-order (gci)
)

func Test_IsDeploymentReady(t *testing.T) {
t.Parallel()

// define test cases
testCases := []struct {
name string
givenDeployment *kappsv1.Deployment
wantResult bool
}{
{
name: "should return false when all replicas are not updated",
givenDeployment: &kappsv1.Deployment{
Spec: kappsv1.DeploymentSpec{Replicas: ptr.To[int32](2)},
Status: kappsv1.DeploymentStatus{
Replicas: 2,
UpdatedReplicas: 1,
AvailableReplicas: 2,
ReadyReplicas: 2,
},
},
wantResult: false,
},
{
name: "should return false when all replicas are not updated",
givenDeployment: &kappsv1.Deployment{
Spec: kappsv1.DeploymentSpec{Replicas: ptr.To[int32](2)},
Status: kappsv1.DeploymentStatus{
Replicas: 2,
UpdatedReplicas: 1,
AvailableReplicas: 2,
ReadyReplicas: 2,
},
},
wantResult: false,
},
{
name: "should return false when all replicas are not available",
givenDeployment: &kappsv1.Deployment{
Spec: kappsv1.DeploymentSpec{Replicas: ptr.To[int32](2)},
Status: kappsv1.DeploymentStatus{
Replicas: 2,
UpdatedReplicas: 2,
AvailableReplicas: 1,
ReadyReplicas: 2,
},
},
wantResult: false,
},
{
name: "should return false when all replicas are not ready",
givenDeployment: &kappsv1.Deployment{
Spec: kappsv1.DeploymentSpec{Replicas: ptr.To[int32](2)},
Status: kappsv1.DeploymentStatus{
Replicas: 2,
UpdatedReplicas: 2,
AvailableReplicas: 2,
ReadyReplicas: 1,
},
},
wantResult: false,
},
{
name: "should return true when all replicas are ready",
givenDeployment: &kappsv1.Deployment{
Spec: kappsv1.DeploymentSpec{Replicas: ptr.To[int32](2)},
Status: kappsv1.DeploymentStatus{
Replicas: 2,
UpdatedReplicas: 2,
AvailableReplicas: 2,
ReadyReplicas: 2,
},
},
wantResult: true,
},
}

// run test cases
for _, tc := range testCases {
testcase := tc
t.Run(testcase.name, func(t *testing.T) {
t.Parallel()

// when
result := IsDeploymentReady(testcase.givenDeployment)

// then
require.Equal(t, testcase.wantResult, result)
})
}
}

0 comments on commit 25ebffa

Please sign in to comment.