Skip to content

Commit 3d9af2c

Browse files
committed
check registration webhook deployment for HubRegistrationDegraded condidtion
Signed-off-by: Zhiwei Yin <[email protected]>
1 parent 567caa2 commit 3d9af2c

File tree

2 files changed

+60
-17
lines changed

2 files changed

+60
-17
lines changed

pkg/operator/operators/clustermanager/controllers/statuscontroller/clustermanager_status_controller.go

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,24 +88,30 @@ func (s *clusterManagerStatusController) sync(ctx context.Context, controllerCon
8888
// updateStatusOfRegistration checks registration deployment status and updates condition of clustermanager
8989
func (s *clusterManagerStatusController) updateStatusOfRegistration(clusterManagerName, clusterManagerNamespace string) metav1.Condition {
9090
// Check registration deployment status
91-
registrationDeploymentName := fmt.Sprintf("%s-registration-controller", clusterManagerName)
92-
registrationDeployment, err := s.deploymentLister.Deployments(clusterManagerNamespace).Get(registrationDeploymentName)
93-
if err != nil {
94-
return metav1.Condition{
95-
Type: operatorapiv1.ConditionHubRegistrationDegraded,
96-
Status: metav1.ConditionTrue,
97-
Reason: operatorapiv1.ReasonGetRegistrationDeploymentFailed,
98-
Message: fmt.Sprintf("Failed to get registration deployment %q %q: %v", clusterManagerNamespace, registrationDeploymentName, err),
99-
}
91+
deployments := []string{
92+
fmt.Sprintf("%s-registration-controller", clusterManagerName),
93+
fmt.Sprintf("%s-registration-webhook", clusterManagerName),
10094
}
10195

102-
if unavailablePod := helpers.NumOfUnavailablePod(registrationDeployment); unavailablePod > 0 {
103-
return metav1.Condition{
104-
Type: operatorapiv1.ConditionHubRegistrationDegraded,
105-
Status: metav1.ConditionTrue,
106-
Reason: operatorapiv1.ReasonUnavailableRegistrationPod,
107-
Message: fmt.Sprintf("%v of requested instances are unavailable of registration deployment %q %q",
108-
unavailablePod, clusterManagerNamespace, registrationDeploymentName),
96+
for _, deploymentName := range deployments {
97+
registrationDeployment, err := s.deploymentLister.Deployments(clusterManagerNamespace).Get(deploymentName)
98+
if err != nil {
99+
return metav1.Condition{
100+
Type: operatorapiv1.ConditionHubRegistrationDegraded,
101+
Status: metav1.ConditionTrue,
102+
Reason: operatorapiv1.ReasonGetRegistrationDeploymentFailed,
103+
Message: fmt.Sprintf("Failed to get registration deployment %q %q: %v", clusterManagerNamespace, deploymentName, err),
104+
}
105+
}
106+
107+
if unavailablePod := helpers.NumOfUnavailablePod(registrationDeployment); unavailablePod > 0 {
108+
return metav1.Condition{
109+
Type: operatorapiv1.ConditionHubRegistrationDegraded,
110+
Status: metav1.ConditionTrue,
111+
Reason: operatorapiv1.ReasonUnavailableRegistrationPod,
112+
Message: fmt.Sprintf("%v of requested instances are unavailable of registration deployment %q %q",
113+
unavailablePod, clusterManagerNamespace, deploymentName),
114+
}
109115
}
110116
}
111117

pkg/operator/operators/clustermanager/controllers/statuscontroller/clustermanager_status_controller_test.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,21 @@ func newRegistrationDeployment(desiredReplica, availableReplica int32) *appsv1.D
5959
}
6060
}
6161

62+
func newRegistrationWebhookDeployment(desiredReplica, availableReplica int32) *appsv1.Deployment {
63+
return &appsv1.Deployment{
64+
ObjectMeta: metav1.ObjectMeta{
65+
Name: fmt.Sprintf("%s-registration-webhook", testClusterManagerName),
66+
Namespace: "open-cluster-management-hub",
67+
},
68+
Spec: appsv1.DeploymentSpec{
69+
Replicas: &desiredReplica,
70+
},
71+
Status: appsv1.DeploymentStatus{
72+
AvailableReplicas: availableReplica,
73+
},
74+
}
75+
}
76+
6277
func newPlacementDeployment(desiredReplica, availableReplica int32) *appsv1.Deployment {
6378
return &appsv1.Deployment{
6479
ObjectMeta: metav1.ObjectMeta{
@@ -145,11 +160,33 @@ func TestSyncStatus(t *testing.T) {
145160
testinghelper.AssertOnlyConditions(t, klusterlet, appliedCond, expectedCondition1, expectedCondition2)
146161
},
147162
},
163+
{
164+
name: "unavailable registration webhook pods and placement functional",
165+
queueKey: testClusterManagerName,
166+
clusterManagers: []runtime.Object{newClusterManager()},
167+
deployments: []runtime.Object{
168+
newRegistrationDeployment(3, 3),
169+
newRegistrationWebhookDeployment(3, 0),
170+
newPlacementDeployment(3, 3),
171+
},
172+
validateActions: func(t *testing.T, actions []clienttesting.Action) {
173+
testingcommon.AssertActions(t, actions, "patch")
174+
klusterlet := &operatorapiv1.Klusterlet{}
175+
patchData := actions[0].(clienttesting.PatchActionImpl).Patch
176+
err := json.Unmarshal(patchData, klusterlet)
177+
if err != nil {
178+
t.Fatal(err)
179+
}
180+
expectedCondition1 := testinghelper.NamedCondition(operatorapiv1.ConditionHubRegistrationDegraded, "UnavailableRegistrationPod", metav1.ConditionTrue)
181+
expectedCondition2 := testinghelper.NamedCondition(operatorapiv1.ConditionHubPlacementDegraded, "PlacementFunctional", metav1.ConditionFalse)
182+
testinghelper.AssertOnlyConditions(t, klusterlet, appliedCond, expectedCondition1, expectedCondition2)
183+
},
184+
},
148185
{
149186
name: "registration functional and no placement deployment",
150187
queueKey: testClusterManagerName,
151188
clusterManagers: []runtime.Object{newClusterManager()},
152-
deployments: []runtime.Object{newRegistrationDeployment(3, 3)},
189+
deployments: []runtime.Object{newRegistrationDeployment(3, 3), newRegistrationWebhookDeployment(3, 3)},
153190
validateActions: func(t *testing.T, actions []clienttesting.Action) {
154191
testingcommon.AssertActions(t, actions, "patch")
155192
klusterlet := &operatorapiv1.Klusterlet{}

0 commit comments

Comments
 (0)