Skip to content

Commit

Permalink
Refine v1beta2 ControlPlaneHealthy condition
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziopandini committed Nov 19, 2024
1 parent a21faa0 commit a8cd67e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 28 deletions.
10 changes: 2 additions & 8 deletions controlplane/kubeadm/internal/controllers/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2019,10 +2019,7 @@ func TestKubeadmControlPlaneReconciler_reconcileControlPlaneAndMachinesCondition
Status: metav1.ConditionUnknown,
Reason: controlplanev1.KubeadmControlPlaneControlPlaneComponentsHealthUnknownV1Beta2Reason,
Message: "* Machine machine1-test:\n" +
" * APIServerPodHealthy: Waiting for GenericInfrastructureMachine to report spec.providerID\n" +
" * ControllerManagerPodHealthy: Waiting for GenericInfrastructureMachine to report spec.providerID\n" +
" * SchedulerPodHealthy: Waiting for GenericInfrastructureMachine to report spec.providerID\n" +
" * EtcdPodHealthy: Waiting for GenericInfrastructureMachine to report spec.providerID",
" * Waiting for GenericInfrastructureMachine to report spec.providerID",
},
},
expectMachineConditions: []metav1.Condition{
Expand Down Expand Up @@ -2099,10 +2096,7 @@ func TestKubeadmControlPlaneReconciler_reconcileControlPlaneAndMachinesCondition
Status: metav1.ConditionUnknown,
Reason: controlplanev1.KubeadmControlPlaneControlPlaneComponentsHealthUnknownV1Beta2Reason,
Message: "* Machine machine1-test:\n" +
" * APIServerPodHealthy: Waiting for GenericInfrastructureMachine to report spec.providerID\n" +
" * ControllerManagerPodHealthy: Waiting for GenericInfrastructureMachine to report spec.providerID\n" +
" * SchedulerPodHealthy: Waiting for GenericInfrastructureMachine to report spec.providerID\n" +
" * EtcdPodHealthy: Waiting for GenericInfrastructureMachine to report spec.providerID",
" * Waiting for GenericInfrastructureMachine to report spec.providerID",
},
},
expectMachineConditions: []metav1.Condition{
Expand Down
10 changes: 10 additions & 0 deletions controlplane/kubeadm/internal/workload_cluster_conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -961,8 +961,12 @@ func aggregateV1Beta2ConditionsFromMachinesToKCP(input aggregateV1Beta2Condition
for i := range input.controlPlane.Machines {
machine := input.controlPlane.Machines[i]
machineMessages := []string{}
conditionCount := 0
conditionMessages := sets.Set[string]{}
for _, condition := range input.machineConditions {
if machineCondition := v1beta2conditions.Get(machine, condition); machineCondition != nil {
conditionCount++
conditionMessages.Insert(machineCondition.Message)
switch machineCondition.Status {
case metav1.ConditionTrue:
kcpMachinesWithInfo.Insert(machine.Name)
Expand All @@ -985,6 +989,12 @@ func aggregateV1Beta2ConditionsFromMachinesToKCP(input aggregateV1Beta2Condition
}

if len(machineMessages) > 0 {
if conditionCount > 1 && len(conditionMessages) == 1 {
message := fmt.Sprintf(" * Control plane components: %s", conditionMessages.UnsortedList()[0])
messageMap[message] = append(messageMap[message], machine.Name)
continue
}

message := strings.Join(machineMessages, "\n")
messageMap[message] = append(messageMap[message], machine.Name)
}
Expand Down
25 changes: 5 additions & 20 deletions controlplane/kubeadm/internal/workload_cluster_conditions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -804,10 +804,7 @@ func TestUpdateStaticPodConditions(t *testing.T) {
Status: metav1.ConditionUnknown,
Reason: controlplanev1.KubeadmControlPlaneControlPlaneComponentsHealthUnknownV1Beta2Reason,
Message: "* Machine m1:\n" +
" * APIServerPodHealthy: Waiting for GenericInfraMachine to report spec.providerID\n" +
" * ControllerManagerPodHealthy: Waiting for GenericInfraMachine to report spec.providerID\n" +
" * SchedulerPodHealthy: Waiting for GenericInfraMachine to report spec.providerID\n" +
" * EtcdPodHealthy: Waiting for GenericInfraMachine to report spec.providerID",
" * Control plane components: Waiting for GenericInfraMachine to report spec.providerID",
},
expectedMachineV1Beta2Conditions: map[string][]metav1.Condition{
"m1": {
Expand Down Expand Up @@ -837,10 +834,7 @@ func TestUpdateStaticPodConditions(t *testing.T) {
Status: metav1.ConditionUnknown,
Reason: controlplanev1.KubeadmControlPlaneControlPlaneComponentsHealthUnknownV1Beta2Reason,
Message: "* Machine m1:\n" +
" * APIServerPodHealthy: Waiting for a Node with spec.providerID dummy-provider-id to exist\n" +
" * ControllerManagerPodHealthy: Waiting for a Node with spec.providerID dummy-provider-id to exist\n" +
" * SchedulerPodHealthy: Waiting for a Node with spec.providerID dummy-provider-id to exist\n" +
" * EtcdPodHealthy: Waiting for a Node with spec.providerID dummy-provider-id to exist",
" * Control plane components: Waiting for a Node with spec.providerID dummy-provider-id to exist",
},
expectedMachineV1Beta2Conditions: map[string][]metav1.Condition{
"m1": {
Expand Down Expand Up @@ -891,10 +885,7 @@ func TestUpdateStaticPodConditions(t *testing.T) {
Status: metav1.ConditionUnknown,
Reason: controlplanev1.KubeadmControlPlaneControlPlaneComponentsHealthUnknownV1Beta2Reason,
Message: "* Machine m1:\n" +
" * APIServerPodHealthy: Node n1 is unreachable\n" +
" * ControllerManagerPodHealthy: Node n1 is unreachable\n" +
" * SchedulerPodHealthy: Node n1 is unreachable\n" +
" * EtcdPodHealthy: Node n1 is unreachable",
" * Control plane components: Node n1 is unreachable",
},
expectedMachineV1Beta2Conditions: map[string][]metav1.Condition{
"m1": {
Expand Down Expand Up @@ -922,10 +913,7 @@ func TestUpdateStaticPodConditions(t *testing.T) {
Status: metav1.ConditionUnknown,
Reason: controlplanev1.KubeadmControlPlaneControlPlaneComponentsHealthUnknownV1Beta2Reason,
Message: "* Machine m1:\n" +
" * APIServerPodHealthy: Waiting for GenericInfraMachine to report spec.providerID\n" +
" * ControllerManagerPodHealthy: Waiting for GenericInfraMachine to report spec.providerID\n" +
" * SchedulerPodHealthy: Waiting for GenericInfraMachine to report spec.providerID\n" +
" * EtcdPodHealthy: Waiting for GenericInfraMachine to report spec.providerID",
" * Control plane components: Waiting for GenericInfraMachine to report spec.providerID",
},
expectedMachineV1Beta2Conditions: map[string][]metav1.Condition{
"m1": {
Expand Down Expand Up @@ -958,10 +946,7 @@ func TestUpdateStaticPodConditions(t *testing.T) {
Status: metav1.ConditionUnknown,
Reason: controlplanev1.KubeadmControlPlaneControlPlaneComponentsHealthUnknownV1Beta2Reason,
Message: "* Machine m1:\n" +
" * APIServerPodHealthy: Node n1 does not exist\n" +
" * ControllerManagerPodHealthy: Node n1 does not exist\n" +
" * SchedulerPodHealthy: Node n1 does not exist\n" +
" * EtcdPodHealthy: Node n1 does not exist",
" * Control plane components: gNode n1 does not exist",
},
expectedMachineV1Beta2Conditions: map[string][]metav1.Condition{
"m1": {
Expand Down

0 comments on commit a8cd67e

Please sign in to comment.