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 18, 2024
1 parent a21faa0 commit ebcca99
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
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(" * %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",
" * 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",
" * 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",
" * 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",
" * 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",
" * Node n1 does not exist",
},
expectedMachineV1Beta2Conditions: map[string][]metav1.Condition{
"m1": {
Expand Down

0 comments on commit ebcca99

Please sign in to comment.