Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#11424 from fabriziopandini/refine-…
Browse files Browse the repository at this point in the history
…v1beta2-condition-order

🌱 Refine v1beta2 condition order
  • Loading branch information
k8s-ci-robot authored Nov 15, 2024
2 parents f496ad9 + 3c47543 commit a9fef8e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
4 changes: 2 additions & 2 deletions internal/controllers/cluster/cluster_controller_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -960,12 +960,12 @@ func setAvailableCondition(ctx context.Context, cluster *clusterv1.Cluster) {
log := ctrl.LoggerFrom(ctx)

forConditionTypes := v1beta2conditions.ForConditionTypes{
clusterv1.ClusterDeletingV1Beta2Condition,
clusterv1.ClusterRemoteConnectionProbeV1Beta2Condition,
clusterv1.ClusterInfrastructureReadyV1Beta2Condition,
clusterv1.ClusterControlPlaneAvailableV1Beta2Condition,
clusterv1.ClusterWorkersAvailableV1Beta2Condition,
clusterv1.ClusterRemoteConnectionProbeV1Beta2Condition,
clusterv1.ClusterTopologyReconciledV1Beta2Condition,
clusterv1.ClusterDeletingV1Beta2Condition,
}
for _, g := range cluster.Spec.AvailabilityGates {
forConditionTypes = append(forConditionTypes, g.ConditionType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1763,11 +1763,11 @@ func TestSetAvailableCondition(t *testing.T) {
Type: clusterv1.ClusterAvailableV1Beta2Condition,
Status: metav1.ConditionUnknown,
Reason: clusterv1.ClusterAvailableUnknownV1Beta2Reason,
Message: "* InfrastructureReady: Condition not yet reported\n" +
"* ControlPlaneAvailable: Condition not yet reported\n" +
"* WorkersAvailable: Condition not yet reported\n" +
Message: "* Deleting: Condition not yet reported\n" +
"* RemoteConnectionProbe: Condition not yet reported\n" +
"* Deleting: Condition not yet reported",
"* InfrastructureReady: Condition not yet reported\n" +
"* ControlPlaneAvailable: Condition not yet reported\n" +
"* WorkersAvailable: Condition not yet reported",
},
},
{
Expand Down
24 changes: 15 additions & 9 deletions util/conditions/v1beta2/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,15 @@ func init() {
// and all the other conditions are sorted by Type.
func defaultSortLessFunc(i, j metav1.Condition) bool {
fi, oki := orderMap[i.Type]
if !oki {
fi = orderMap[readinessAndAvailabilityGates]
}
fj, okj := orderMap[j.Type]
switch {
case oki && !okj:
return true
case !oki && okj:
return false
case oki && okj:
return fi < fj
if !okj {
fj = orderMap[readinessAndAvailabilityGates]
}

return i.Type < j.Type
return fi < fj ||
(fi == fj && i.Type < j.Type)
}

// The order array below leads to the following condition ordering:
Expand Down Expand Up @@ -84,6 +82,8 @@ func defaultSortLessFunc(i, j metav1.Condition) bool {
// | -- Aggregated from Machines -- | | | | | | |
// | MachinesReady | x | x | x | x | x | |
// | MachinesUpToDate | x | x | x | x | x | |
// | -- From other controllers -- | | | | | | |
// | Readiness/Availability gates | x | | | | | x |
// | -- Misc -- | | | | | | |
// | Paused | x | x | x | x | x | x |
// | Deleting | x | x | x | x | x | x |
Expand Down Expand Up @@ -117,10 +117,16 @@ var order = []string{
clusterv1.ScalingUpV1Beta2Condition,
clusterv1.MachinesReadyV1Beta2Condition,
clusterv1.MachinesUpToDateV1Beta2Condition,
readinessAndAvailabilityGates,
clusterv1.PausedV1Beta2Condition,
clusterv1.DeletingV1Beta2Condition,
}

// Constants defining a placeholder for readiness and availability gates.
const (
readinessAndAvailabilityGates = ""
)

// Constants inlined for ordering (we want to avoid importing the KCP API package).
const (
kubeadmControlPlaneCertificatesAvailableV1Beta2Condition = "CertificatesAvailable"
Expand Down
4 changes: 2 additions & 2 deletions util/conditions/v1beta2/sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ func TestDefaultSortLessFunc(t *testing.T) {
g.Expect(conditions).To(Equal([]metav1.Condition{
{Type: clusterv1.AvailableV1Beta2Condition},
{Type: clusterv1.ReadyV1Beta2Condition},
{Type: clusterv1.PausedV1Beta2Condition},
{Type: clusterv1.DeletingV1Beta2Condition},
{Type: "A"},
{Type: "B"},
{Type: "C!"},
{Type: clusterv1.PausedV1Beta2Condition},
{Type: clusterv1.DeletingV1Beta2Condition},
}))
}

0 comments on commit a9fef8e

Please sign in to comment.