diff --git a/pkg/operator/operators/clustermanager/controllers/statuscontroller/clustermanager_status_controller.go b/pkg/operator/operators/clustermanager/controllers/statuscontroller/clustermanager_status_controller.go index 995cf022ba..5969223f5b 100644 --- a/pkg/operator/operators/clustermanager/controllers/statuscontroller/clustermanager_status_controller.go +++ b/pkg/operator/operators/clustermanager/controllers/statuscontroller/clustermanager_status_controller.go @@ -88,24 +88,30 @@ func (s *clusterManagerStatusController) sync(ctx context.Context, controllerCon // updateStatusOfRegistration checks registration deployment status and updates condition of clustermanager func (s *clusterManagerStatusController) updateStatusOfRegistration(clusterManagerName, clusterManagerNamespace string) metav1.Condition { // Check registration deployment status - registrationDeploymentName := fmt.Sprintf("%s-registration-controller", clusterManagerName) - registrationDeployment, err := s.deploymentLister.Deployments(clusterManagerNamespace).Get(registrationDeploymentName) - if err != nil { - return metav1.Condition{ - Type: operatorapiv1.ConditionHubRegistrationDegraded, - Status: metav1.ConditionTrue, - Reason: operatorapiv1.ReasonGetRegistrationDeploymentFailed, - Message: fmt.Sprintf("Failed to get registration deployment %q %q: %v", clusterManagerNamespace, registrationDeploymentName, err), - } + deployments := []string{ + fmt.Sprintf("%s-registration-controller", clusterManagerName), + fmt.Sprintf("%s-registration-webhook", clusterManagerName), } - if unavailablePod := helpers.NumOfUnavailablePod(registrationDeployment); unavailablePod > 0 { - return metav1.Condition{ - Type: operatorapiv1.ConditionHubRegistrationDegraded, - Status: metav1.ConditionTrue, - Reason: operatorapiv1.ReasonUnavailableRegistrationPod, - Message: fmt.Sprintf("%v of requested instances are unavailable of registration deployment %q %q", - unavailablePod, clusterManagerNamespace, registrationDeploymentName), + for _, deploymentName := range deployments { + registrationDeployment, err := s.deploymentLister.Deployments(clusterManagerNamespace).Get(deploymentName) + if err != nil { + return metav1.Condition{ + Type: operatorapiv1.ConditionHubRegistrationDegraded, + Status: metav1.ConditionTrue, + Reason: operatorapiv1.ReasonGetRegistrationDeploymentFailed, + Message: fmt.Sprintf("Failed to get registration deployment %q %q: %v", clusterManagerNamespace, deploymentName, err), + } + } + + if unavailablePod := helpers.NumOfUnavailablePod(registrationDeployment); unavailablePod > 0 { + return metav1.Condition{ + Type: operatorapiv1.ConditionHubRegistrationDegraded, + Status: metav1.ConditionTrue, + Reason: operatorapiv1.ReasonUnavailableRegistrationPod, + Message: fmt.Sprintf("%v of requested instances are unavailable of registration deployment %q %q", + unavailablePod, clusterManagerNamespace, deploymentName), + } } } diff --git a/pkg/operator/operators/clustermanager/controllers/statuscontroller/clustermanager_status_controller_test.go b/pkg/operator/operators/clustermanager/controllers/statuscontroller/clustermanager_status_controller_test.go index 66b8979dfe..a7105558a5 100644 --- a/pkg/operator/operators/clustermanager/controllers/statuscontroller/clustermanager_status_controller_test.go +++ b/pkg/operator/operators/clustermanager/controllers/statuscontroller/clustermanager_status_controller_test.go @@ -59,6 +59,21 @@ func newRegistrationDeployment(desiredReplica, availableReplica int32) *appsv1.D } } +func newRegistrationWebhookDeployment(desiredReplica, availableReplica int32) *appsv1.Deployment { + return &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: fmt.Sprintf("%s-registration-webhook", testClusterManagerName), + Namespace: "open-cluster-management-hub", + }, + Spec: appsv1.DeploymentSpec{ + Replicas: &desiredReplica, + }, + Status: appsv1.DeploymentStatus{ + AvailableReplicas: availableReplica, + }, + } +} + func newPlacementDeployment(desiredReplica, availableReplica int32) *appsv1.Deployment { return &appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ @@ -145,11 +160,33 @@ func TestSyncStatus(t *testing.T) { testinghelper.AssertOnlyConditions(t, klusterlet, appliedCond, expectedCondition1, expectedCondition2) }, }, + { + name: "unavailable registration webhook pods and placement functional", + queueKey: testClusterManagerName, + clusterManagers: []runtime.Object{newClusterManager()}, + deployments: []runtime.Object{ + newRegistrationDeployment(3, 3), + newRegistrationWebhookDeployment(3, 0), + newPlacementDeployment(3, 3), + }, + validateActions: func(t *testing.T, actions []clienttesting.Action) { + testingcommon.AssertActions(t, actions, "patch") + klusterlet := &operatorapiv1.Klusterlet{} + patchData := actions[0].(clienttesting.PatchActionImpl).Patch + err := json.Unmarshal(patchData, klusterlet) + if err != nil { + t.Fatal(err) + } + expectedCondition1 := testinghelper.NamedCondition(operatorapiv1.ConditionHubRegistrationDegraded, "UnavailableRegistrationPod", metav1.ConditionTrue) + expectedCondition2 := testinghelper.NamedCondition(operatorapiv1.ConditionHubPlacementDegraded, "PlacementFunctional", metav1.ConditionFalse) + testinghelper.AssertOnlyConditions(t, klusterlet, appliedCond, expectedCondition1, expectedCondition2) + }, + }, { name: "registration functional and no placement deployment", queueKey: testClusterManagerName, clusterManagers: []runtime.Object{newClusterManager()}, - deployments: []runtime.Object{newRegistrationDeployment(3, 3)}, + deployments: []runtime.Object{newRegistrationDeployment(3, 3), newRegistrationWebhookDeployment(3, 3)}, validateActions: func(t *testing.T, actions []clienttesting.Action) { testingcommon.AssertActions(t, actions, "patch") klusterlet := &operatorapiv1.Klusterlet{}