Skip to content

Commit a9fef8e

Browse files
authored
Merge pull request #11424 from fabriziopandini/refine-v1beta2-condition-order
🌱 Refine v1beta2 condition order
2 parents f496ad9 + 3c47543 commit a9fef8e

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

internal/controllers/cluster/cluster_controller_status.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -960,12 +960,12 @@ func setAvailableCondition(ctx context.Context, cluster *clusterv1.Cluster) {
960960
log := ctrl.LoggerFrom(ctx)
961961

962962
forConditionTypes := v1beta2conditions.ForConditionTypes{
963+
clusterv1.ClusterDeletingV1Beta2Condition,
964+
clusterv1.ClusterRemoteConnectionProbeV1Beta2Condition,
963965
clusterv1.ClusterInfrastructureReadyV1Beta2Condition,
964966
clusterv1.ClusterControlPlaneAvailableV1Beta2Condition,
965967
clusterv1.ClusterWorkersAvailableV1Beta2Condition,
966-
clusterv1.ClusterRemoteConnectionProbeV1Beta2Condition,
967968
clusterv1.ClusterTopologyReconciledV1Beta2Condition,
968-
clusterv1.ClusterDeletingV1Beta2Condition,
969969
}
970970
for _, g := range cluster.Spec.AvailabilityGates {
971971
forConditionTypes = append(forConditionTypes, g.ConditionType)

internal/controllers/cluster/cluster_controller_status_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1763,11 +1763,11 @@ func TestSetAvailableCondition(t *testing.T) {
17631763
Type: clusterv1.ClusterAvailableV1Beta2Condition,
17641764
Status: metav1.ConditionUnknown,
17651765
Reason: clusterv1.ClusterAvailableUnknownV1Beta2Reason,
1766-
Message: "* InfrastructureReady: Condition not yet reported\n" +
1767-
"* ControlPlaneAvailable: Condition not yet reported\n" +
1768-
"* WorkersAvailable: Condition not yet reported\n" +
1766+
Message: "* Deleting: Condition not yet reported\n" +
17691767
"* RemoteConnectionProbe: Condition not yet reported\n" +
1770-
"* Deleting: Condition not yet reported",
1768+
"* InfrastructureReady: Condition not yet reported\n" +
1769+
"* ControlPlaneAvailable: Condition not yet reported\n" +
1770+
"* WorkersAvailable: Condition not yet reported",
17711771
},
17721772
},
17731773
{

util/conditions/v1beta2/sort.go

+15-9
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,15 @@ func init() {
3636
// and all the other conditions are sorted by Type.
3737
func defaultSortLessFunc(i, j metav1.Condition) bool {
3838
fi, oki := orderMap[i.Type]
39+
if !oki {
40+
fi = orderMap[readinessAndAvailabilityGates]
41+
}
3942
fj, okj := orderMap[j.Type]
40-
switch {
41-
case oki && !okj:
42-
return true
43-
case !oki && okj:
44-
return false
45-
case oki && okj:
46-
return fi < fj
43+
if !okj {
44+
fj = orderMap[readinessAndAvailabilityGates]
4745
}
48-
49-
return i.Type < j.Type
46+
return fi < fj ||
47+
(fi == fj && i.Type < j.Type)
5048
}
5149

5250
// The order array below leads to the following condition ordering:
@@ -84,6 +82,8 @@ func defaultSortLessFunc(i, j metav1.Condition) bool {
8482
// | -- Aggregated from Machines -- | | | | | | |
8583
// | MachinesReady | x | x | x | x | x | |
8684
// | MachinesUpToDate | x | x | x | x | x | |
85+
// | -- From other controllers -- | | | | | | |
86+
// | Readiness/Availability gates | x | | | | | x |
8787
// | -- Misc -- | | | | | | |
8888
// | Paused | x | x | x | x | x | x |
8989
// | Deleting | x | x | x | x | x | x |
@@ -117,10 +117,16 @@ var order = []string{
117117
clusterv1.ScalingUpV1Beta2Condition,
118118
clusterv1.MachinesReadyV1Beta2Condition,
119119
clusterv1.MachinesUpToDateV1Beta2Condition,
120+
readinessAndAvailabilityGates,
120121
clusterv1.PausedV1Beta2Condition,
121122
clusterv1.DeletingV1Beta2Condition,
122123
}
123124

125+
// Constants defining a placeholder for readiness and availability gates.
126+
const (
127+
readinessAndAvailabilityGates = ""
128+
)
129+
124130
// Constants inlined for ordering (we want to avoid importing the KCP API package).
125131
const (
126132
kubeadmControlPlaneCertificatesAvailableV1Beta2Condition = "CertificatesAvailable"

util/conditions/v1beta2/sort_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ func TestDefaultSortLessFunc(t *testing.T) {
4646
g.Expect(conditions).To(Equal([]metav1.Condition{
4747
{Type: clusterv1.AvailableV1Beta2Condition},
4848
{Type: clusterv1.ReadyV1Beta2Condition},
49-
{Type: clusterv1.PausedV1Beta2Condition},
50-
{Type: clusterv1.DeletingV1Beta2Condition},
5149
{Type: "A"},
5250
{Type: "B"},
5351
{Type: "C!"},
52+
{Type: clusterv1.PausedV1Beta2Condition},
53+
{Type: clusterv1.DeletingV1Beta2Condition},
5454
}))
5555
}

0 commit comments

Comments
 (0)