diff --git a/internal/controller/operator/eventing/status.go b/internal/controller/operator/eventing/status.go index b7b10f28..953547e8 100644 --- a/internal/controller/operator/eventing/status.go +++ b/internal/controller/operator/eventing/status.go @@ -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 } diff --git a/internal/controller/operator/eventing/status_test.go b/internal/controller/operator/eventing/status_test.go new file mode 100644 index 00000000..72f12c9f --- /dev/null +++ b/internal/controller/operator/eventing/status_test.go @@ -0,0 +1,99 @@ +package eventing + +import ( + "github.com/stretchr/testify/require" + kappsv1 "k8s.io/api/apps/v1" + "k8s.io/utils/ptr" + "testing" +) + +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) + }) + } +}