Skip to content

🌱 check registration webhook deployment for HubRegistrationDegraded condition #1043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{}
Expand Down
Loading