@@ -22,13 +22,21 @@ import (
22
22
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
23
23
)
24
24
25
+ var orderMap = map [string ]int {}
26
+
27
+ func init () {
28
+ for i , c := range order {
29
+ orderMap [c ] = i
30
+ }
31
+ }
32
+
25
33
// defaultSortLessFunc returns true if a condition is less than another with regards to the
26
34
// order of conditions designed for convenience of the consumer, i.e. kubectl get.
27
35
// According to this order the Available and the Ready condition always goes first, Deleting and Paused always goes last,
28
36
// and all the other conditions are sorted by Type.
29
37
func defaultSortLessFunc (i , j metav1.Condition ) bool {
30
- fi , oki := first [i .Type ]
31
- fj , okj := first [j .Type ]
38
+ fi , oki := orderMap [i .Type ]
39
+ fj , okj := orderMap [j .Type ]
32
40
switch {
33
41
case oki && ! okj :
34
42
return true
@@ -38,26 +46,90 @@ func defaultSortLessFunc(i, j metav1.Condition) bool {
38
46
return fi < fj
39
47
}
40
48
41
- li , oki := last [i .Type ]
42
- lj , okj := last [j .Type ]
43
- switch {
44
- case oki && ! okj :
45
- return false
46
- case ! oki && okj :
47
- return true
48
- case oki && okj :
49
- return li < lj
50
- }
51
-
52
49
return i .Type < j .Type
53
50
}
54
51
55
- var first = map [string ]int {
56
- clusterv1 .AvailableV1Beta2Condition : 0 ,
57
- clusterv1 .ReadyV1Beta2Condition : 1 ,
52
+ // The order array below leads to the following condition ordering:
53
+ //
54
+ // | Condition | Cluster | KCP | MD | MS | MP | Machine |
55
+ // |--------------------------------|---------|-----|:---|----|----|---------|
56
+ // | -- Availability conditions -- | | | | | | |
57
+ // | Available | x | x | x | | x | x |
58
+ // | Ready | | | | | | x |
59
+ // | UpToDate | | | | | | x |
60
+ // | RemoteConnectionProbe | x | | | | | |
61
+ // | BootstrapConfigReady | | | | | x | x |
62
+ // | InfrastructureReady | x | | | | x | x |
63
+ // | ControlPlaneInitialized | x | | | | | |
64
+ // | ControlPlaneAvailable | x | | | | | |
65
+ // | WorkersAvailable | x | | | | | |
66
+ // | CertificatesAvailable | | x | | | | |
67
+ // | Initialized | | x | | | | |
68
+ // | EtcdClusterHealthy | | x | | | | |
69
+ // | ControlPlaneComponentsHealthy | | x | | | | |
70
+ // | NodeHealthy | | | | | | x |
71
+ // | NodeReady | | | | | | x |
72
+ // | EtcdPodHealthy | | | | | | x |
73
+ // | EtcdMemberHealthy | | | | | | x |
74
+ // | APIServerPodHealthy | | | | | | x |
75
+ // | ControllerManagerPodHealthy | | | | | | x |
76
+ // | SchedulerPodHealthy | | | | | | x |
77
+ // | HealthCheckSucceeded | | | | | | x |
78
+ // | OwnerRemediated | | | | | | x |
79
+ // | -- Operations -- | | | | | | |
80
+ // | TopologyReconciled | x | | | | | |
81
+ // | Remediating | x | x | x | x | x | |
82
+ // | ScalingDown | x | x | x | x | x | |
83
+ // | ScalingUp | x | x | x | x | x | |
84
+ // | -- Aggregated from Machines -- | | | | | | |
85
+ // | MachinesReady | x | x | x | x | x | |
86
+ // | MachinesUpToDate | x | x | x | x | x | |
87
+ // | -- Misc -- | | | | | | |
88
+ // | Paused | x | x | x | x | x | x |
89
+ // | Deleting | x | x | x | x | x | x |
90
+ // .
91
+ var order = []string {
92
+ clusterv1 .AvailableV1Beta2Condition ,
93
+ clusterv1 .ReadyV1Beta2Condition ,
94
+ clusterv1 .MachineUpToDateV1Beta2Condition ,
95
+ clusterv1 .ClusterRemoteConnectionProbeV1Beta2Condition ,
96
+ clusterv1 .BootstrapConfigReadyV1Beta2Condition ,
97
+ clusterv1 .InfrastructureReadyV1Beta2Condition ,
98
+ clusterv1 .ClusterControlPlaneInitializedV1Beta2Condition ,
99
+ clusterv1 .ClusterControlPlaneAvailableV1Beta2Condition ,
100
+ clusterv1 .ClusterWorkersAvailableV1Beta2Condition ,
101
+ kubeadmControlPlaneCertificatesAvailableV1Beta2Condition ,
102
+ kubeadmControlPlaneInitializedV1Beta2Condition ,
103
+ kubeadmControlPlaneEtcdClusterHealthyV1Beta2Condition ,
104
+ kubeadmControlPlaneControlPlaneComponentsHealthyV1Beta2Condition ,
105
+ clusterv1 .MachineNodeHealthyV1Beta2Condition ,
106
+ clusterv1 .MachineNodeReadyV1Beta2Condition ,
107
+ kubeadmControlPlaneMachineEtcdPodHealthyV1Beta2Condition ,
108
+ kubeadmControlPlaneMachineEtcdMemberHealthyV1Beta2Condition ,
109
+ kubeadmControlPlaneMachineAPIServerPodHealthyV1Beta2Condition ,
110
+ kubeadmControlPlaneMachineControllerManagerPodHealthyV1Beta2Condition ,
111
+ kubeadmControlPlaneMachineSchedulerPodHealthyV1Beta2Condition ,
112
+ clusterv1 .MachineHealthCheckSucceededV1Beta2Condition ,
113
+ clusterv1 .MachineOwnerRemediatedV1Beta2Condition ,
114
+ clusterv1 .ClusterTopologyReconciledV1Beta2Condition ,
115
+ clusterv1 .RemediatingV1Beta2Condition ,
116
+ clusterv1 .ScalingDownV1Beta2Condition ,
117
+ clusterv1 .ScalingUpV1Beta2Condition ,
118
+ clusterv1 .MachinesReadyV1Beta2Condition ,
119
+ clusterv1 .MachinesUpToDateV1Beta2Condition ,
120
+ clusterv1 .PausedV1Beta2Condition ,
121
+ clusterv1 .DeletingV1Beta2Condition ,
58
122
}
59
123
60
- var last = map [string ]int {
61
- clusterv1 .PausedV1Beta2Condition : 0 ,
62
- clusterv1 .DeletingV1Beta2Condition : 1 ,
63
- }
124
+ // Constants inlined for ordering (we want to avoid importing the KCP API package).
125
+ const (
126
+ kubeadmControlPlaneCertificatesAvailableV1Beta2Condition = "CertificatesAvailable"
127
+ kubeadmControlPlaneInitializedV1Beta2Condition = "Initialized"
128
+ kubeadmControlPlaneEtcdClusterHealthyV1Beta2Condition = "EtcdClusterHealthy"
129
+ kubeadmControlPlaneControlPlaneComponentsHealthyV1Beta2Condition = "ControlPlaneComponentsHealthy"
130
+ kubeadmControlPlaneMachineAPIServerPodHealthyV1Beta2Condition = "APIServerPodHealthy"
131
+ kubeadmControlPlaneMachineControllerManagerPodHealthyV1Beta2Condition = "ControllerManagerPodHealthy"
132
+ kubeadmControlPlaneMachineSchedulerPodHealthyV1Beta2Condition = "SchedulerPodHealthy"
133
+ kubeadmControlPlaneMachineEtcdPodHealthyV1Beta2Condition = "EtcdPodHealthy"
134
+ kubeadmControlPlaneMachineEtcdMemberHealthyV1Beta2Condition = "EtcdMemberHealthy"
135
+ )
0 commit comments