Skip to content

Commit

Permalink
More comments
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziopandini committed Oct 11, 2024
1 parent 82ee71d commit 7278f4a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 19 deletions.
4 changes: 2 additions & 2 deletions api/v1beta1/machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const (
MachineBootstrapConfigInvalidConditionReportedV1Beta2Reason = InvalidConditionReportedV1Beta2Reason

// MachineBootstrapConfigReadyNoReasonReportedV1Beta2Reason applies to a BootstrapConfig Ready condition (read from a bootstrap config object) that reports no reason.
MachineBootstrapConfigReadyNoReasonReportedV1Beta2Reason = NoV1Beta2ReasonReported
MachineBootstrapConfigReadyNoReasonReportedV1Beta2Reason = NoReasonReportedV1Beta2Reason

// MachineBootstrapConfigInternalErrorV1Beta2Reason surfaces unexpected failures when reading a BootstrapConfig object.
MachineBootstrapConfigInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason
Expand All @@ -169,7 +169,7 @@ const (
MachineInfrastructureInvalidConditionReportedV1Beta2Reason = InvalidConditionReportedV1Beta2Reason

// MachineInfrastructureReadyNoReasonReportedV1Beta2Reason applies to a infrastructure Ready condition (read from an infra machine object) that reports no reason.
MachineInfrastructureReadyNoReasonReportedV1Beta2Reason = NoV1Beta2ReasonReported
MachineInfrastructureReadyNoReasonReportedV1Beta2Reason = NoReasonReportedV1Beta2Reason

// MachineInfrastructureInternalErrorV1Beta2Reason surfaces unexpected failures when reading a infra machine object.
MachineInfrastructureInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason
Expand Down
4 changes: 2 additions & 2 deletions api/v1beta1/v1beta2_condition_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ const (
// (e.g. its status is missing).
InvalidConditionReportedV1Beta2Reason = "InvalidConditionReported"

// NoV1Beta2ReasonReported applies to a condition, usually read from an external object, that reports no reason.
// NoReasonReportedV1Beta2Reason applies to a condition, usually read from an external object, that reports no reason.
// Note: this could happen e.g. when an external object still uses Cluster API v1beta1 Conditions.
NoV1Beta2ReasonReported = "NoReasonReported"
NoReasonReportedV1Beta2Reason = "NoReasonReported"

// InternalErrorV1Beta2Reason surfaces unexpected errors reporting by controllers.
// In most cases, it will be required to look at controllers logs to properly triage those issues.
Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/machine/machine_controller_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func setNodeHealthyAndReadyConditions(ctx context.Context, machine *clusterv1.Ma
}
reason := condition.Reason
if reason == "" {
reason = clusterv1.NoV1Beta2ReasonReported
reason = clusterv1.NoReasonReportedV1Beta2Reason
}
nodeReady = &metav1.Condition{
Type: clusterv1.MachineNodeReadyV1Beta2Condition,
Expand Down Expand Up @@ -461,7 +461,7 @@ func (c machineConditionCustomMergeStrategy) Merge(conditions []v1beta2condition
}
// Note: MachineNodeReadyV1Beta2Condition is not relevant for the summary.
}
return v1beta2conditions.GetDefaultMergePriority(nil)(condition)
return v1beta2conditions.GetDefaultMergePriorityFunc(nil)(condition)
}).Merge(conditions, conditionTypes)
}

Expand Down
24 changes: 16 additions & 8 deletions internal/controllers/machine/machine_controller_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,12 @@ func TestSetBootstrapReadyCondition(t *testing.T) {
},
},
{
name: "Use status.BoostrapReady flag as a fallback Ready condition from bootstrap config is missing (ready true)",
machine: defaultMachine.DeepCopy(),
name: "Use status.BoostrapReady flag as a fallback Ready condition from bootstrap config is missing (ready true)",
machine: func() *clusterv1.Machine {
m := defaultMachine.DeepCopy()
m.Status.BootstrapReady = true
return m
}(),
bootstrapConfig: &unstructured.Unstructured{Object: map[string]interface{}{
"kind": "GenericBootstrapConfig",
"apiVersion": "bootstrap.cluster.x-k8s.io/v1beta1",
Expand All @@ -148,9 +152,9 @@ func TestSetBootstrapReadyCondition(t *testing.T) {
bootstrapConfigIsNotFound: false,
expectCondition: metav1.Condition{
Type: clusterv1.MachineBootstrapConfigReadyV1Beta2Condition,
Status: metav1.ConditionFalse,
Status: metav1.ConditionTrue,
Reason: clusterv1.MachineBootstrapConfigReadyNoReasonReportedV1Beta2Reason,
Message: "GenericBootstrapConfig status.ready is false",
Message: "GenericBootstrapConfig status.ready is true",
},
},
{
Expand Down Expand Up @@ -322,8 +326,12 @@ func TestSetInfrastructureReadyCondition(t *testing.T) {
},
},
{
name: "Use status.InfrastructureReady flag as a fallback Ready condition from infra machine is missing (ready true)",
machine: defaultMachine.DeepCopy(),
name: "Use status.InfrastructureReady flag as a fallback Ready condition from infra machine is missing (ready true)",
machine: func() *clusterv1.Machine {
m := defaultMachine.DeepCopy()
m.Status.InfrastructureReady = true
return m
}(),
infraMachine: &unstructured.Unstructured{Object: map[string]interface{}{
"kind": "GenericInfrastructureMachine",
"apiVersion": "infrastructure.cluster.x-k8s.io/v1beta1",
Expand All @@ -338,9 +346,9 @@ func TestSetInfrastructureReadyCondition(t *testing.T) {
infraMachineIsNotFound: false,
expectCondition: metav1.Condition{
Type: clusterv1.MachineInfrastructureReadyV1Beta2Condition,
Status: metav1.ConditionFalse,
Status: metav1.ConditionTrue,
Reason: clusterv1.MachineInfrastructureReadyNoReasonReportedV1Beta2Reason,
Message: "GenericInfrastructureMachine status.ready is false",
Message: "GenericInfrastructureMachine status.ready is true",
},
},
{
Expand Down
6 changes: 3 additions & 3 deletions util/conditions/v1beta2/merge_strategies.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,16 @@ func DefaultMergeStrategyWithCustomPriority(getPriorityFunc func(condition metav

func newDefaultMergeStrategy(negativePolarityConditionTypes sets.Set[string]) MergeStrategy {
return &defaultMergeStrategy{
getPriorityFunc: GetDefaultMergePriority(negativePolarityConditionTypes),
getPriorityFunc: GetDefaultMergePriorityFunc(negativePolarityConditionTypes),
}
}

// GetDefaultMergePriority returns the merge priority for each condition.
// GetDefaultMergePriorityFunc returns the merge priority for each condition.
// It assigns following priority values to conditions:
// - issues: conditions with positive polarity (normal True) and status False or conditions with negative polarity (normal False) and status True.
// - unknown: conditions with status unknown.
// - info: conditions with positive polarity (normal True) and status True or conditions with negative polarity (normal False) and status False.
func GetDefaultMergePriority(negativePolarityConditionTypes sets.Set[string]) func(condition metav1.Condition) MergePriority {
func GetDefaultMergePriorityFunc(negativePolarityConditionTypes sets.Set[string]) func(condition metav1.Condition) MergePriority {
return func(condition metav1.Condition) MergePriority {
switch condition.Status {
case metav1.ConditionTrue:
Expand Down
4 changes: 2 additions & 2 deletions util/conditions/v1beta2/merge_strategies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestSplitConditionsByPriority(t *testing.T) {
{OwnerResource: ConditionOwnerInfo{Name: "baz"}, Condition: metav1.Condition{Type: "!C", Status: metav1.ConditionFalse}}, // info
}

issueConditions, unknownConditions, infoConditions := splitConditionsByPriority(conditions, GetDefaultMergePriority(sets.New[string]("!C")))
issueConditions, unknownConditions, infoConditions := splitConditionsByPriority(conditions, GetDefaultMergePriorityFunc(sets.New[string]("!C")))

// Check condition are grouped as expected and order is preserved.

Expand Down Expand Up @@ -196,7 +196,7 @@ func TestDefaultMergePriority(t *testing.T) {
if tt.negativePolarity {
negativePolarityConditionTypes.Insert(tt.condition.Type)
}
gotPriority := GetDefaultMergePriority(negativePolarityConditionTypes)(tt.condition)
gotPriority := GetDefaultMergePriorityFunc(negativePolarityConditionTypes)(tt.condition)

g.Expect(gotPriority).To(Equal(tt.wantPriority))
})
Expand Down

0 comments on commit 7278f4a

Please sign in to comment.