Skip to content

Commit 029b8c9

Browse files
authored
Merge pull request #11419 from fabriziopandini/refine-v1beta2-mirror-conditions
🌱 Refine v1beta2 mirror conditions
2 parents fd388dd + 5262291 commit 029b8c9

File tree

7 files changed

+224
-303
lines changed

7 files changed

+224
-303
lines changed

api/v1beta1/cluster_types.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,16 @@ const (
126126
// ClusterInfrastructureReadyV1Beta2Condition mirrors Cluster's infrastructure Ready condition.
127127
ClusterInfrastructureReadyV1Beta2Condition = InfrastructureReadyV1Beta2Condition
128128

129+
// ClusterInfrastructureReadyV1Beta2Reason surfaces when the cluster infrastructure is ready.
130+
ClusterInfrastructureReadyV1Beta2Reason = ReadyV1Beta2Reason
131+
132+
// ClusterInfrastructureNotReadyV1Beta2Reason surfaces when the cluster infrastructure is not ready.
133+
ClusterInfrastructureNotReadyV1Beta2Reason = NotReadyV1Beta2Reason
134+
129135
// ClusterInfrastructureInvalidConditionReportedV1Beta2Reason surfaces a infrastructure Ready condition (read from an infra cluster object) which is invalid
130136
// (e.g. its status is missing).
131137
ClusterInfrastructureInvalidConditionReportedV1Beta2Reason = InvalidConditionReportedV1Beta2Reason
132138

133-
// ClusterInfrastructureReadyNoReasonReportedV1Beta2Reason applies to a infrastructure Ready condition (read from an infra cluster object) that reports no reason.
134-
ClusterInfrastructureReadyNoReasonReportedV1Beta2Reason = NoReasonReportedV1Beta2Reason
135-
136139
// ClusterInfrastructureInternalErrorV1Beta2Reason surfaces unexpected failures when reading an infra cluster object.
137140
ClusterInfrastructureInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason
138141

@@ -170,13 +173,16 @@ const (
170173
// ClusterControlPlaneAvailableV1Beta2Condition is a mirror of Cluster's control plane Available condition.
171174
ClusterControlPlaneAvailableV1Beta2Condition = "ControlPlaneAvailable"
172175

176+
// ClusterControlPlaneAvailableV1Beta2Reason surfaces when the cluster control plane is available.
177+
ClusterControlPlaneAvailableV1Beta2Reason = AvailableV1Beta2Reason
178+
179+
// ClusterControlPlaneNotAvailableV1Beta2Reason surfaces when the cluster control plane is not available.
180+
ClusterControlPlaneNotAvailableV1Beta2Reason = NotAvailableV1Beta2Reason
181+
173182
// ClusterControlPlaneInvalidConditionReportedV1Beta2Reason surfaces a control plane Available condition (read from a control plane object) which is invalid.
174183
// (e.g. its status is missing).
175184
ClusterControlPlaneInvalidConditionReportedV1Beta2Reason = InvalidConditionReportedV1Beta2Reason
176185

177-
// ClusterControlPlaneAvailableNoReasonReportedV1Beta2Reason applies to a control plane Available condition (read from a control plane object) that reports no reason.
178-
ClusterControlPlaneAvailableNoReasonReportedV1Beta2Reason = NoReasonReportedV1Beta2Reason
179-
180186
// ClusterControlPlaneInternalErrorV1Beta2Reason surfaces unexpected failures when reading a control plane object.
181187
ClusterControlPlaneInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason
182188

api/v1beta1/machine_types.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,16 @@ const (
152152
// from a BoostrapConfig object referenced from the machine).
153153
MachineBootstrapDataSecretProvidedV1Beta2Reason = "DataSecretProvided"
154154

155+
// MachineBootstrapConfigReadyV1Beta2Reason surfaces when the machine bootstrap config is ready.
156+
MachineBootstrapConfigReadyV1Beta2Reason = ReadyV1Beta2Reason
157+
158+
// MachineBootstrapConfigNotReadyV1Beta2Reason surfaces when the machine bootstrap config is not ready.
159+
MachineBootstrapConfigNotReadyV1Beta2Reason = NotReadyV1Beta2Reason
160+
155161
// MachineBootstrapConfigInvalidConditionReportedV1Beta2Reason surfaces a BootstrapConfig Ready condition (read from a bootstrap config object) which is invalid.
156162
// (e.g. its status is missing).
157163
MachineBootstrapConfigInvalidConditionReportedV1Beta2Reason = InvalidConditionReportedV1Beta2Reason
158164

159-
// MachineBootstrapConfigReadyNoReasonReportedV1Beta2Reason applies to a BootstrapConfig Ready condition (read from a bootstrap config object) that reports no reason.
160-
MachineBootstrapConfigReadyNoReasonReportedV1Beta2Reason = NoReasonReportedV1Beta2Reason
161-
162165
// MachineBootstrapConfigInternalErrorV1Beta2Reason surfaces unexpected failures when reading a BootstrapConfig object.
163166
MachineBootstrapConfigInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason
164167

@@ -175,16 +178,19 @@ const (
175178
// Machine's InfrastructureReady condition and corresponding reasons that will be used in v1Beta2 API version.
176179
// Note: when possible, InfrastructureReady condition will use reasons surfaced from the underlying infra machine object.
177180
const (
178-
// MachineInfrastructureReadyV1Beta2Condition mirrors the corresponding Ready condition from the Machine's Infrastructure resource.
181+
// MachineInfrastructureReadyV1Beta2Condition mirrors the corresponding Ready condition from the Machine's infrastructure resource.
179182
MachineInfrastructureReadyV1Beta2Condition = InfrastructureReadyV1Beta2Condition
180183

184+
// MachineInfrastructureReadyV1Beta2Reason surfaces when the machine infrastructure is ready.
185+
MachineInfrastructureReadyV1Beta2Reason = ReadyV1Beta2Reason
186+
187+
// MachineInfrastructureNotReadyV1Beta2Reason surfaces when the machine infrastructure is not ready.
188+
MachineInfrastructureNotReadyV1Beta2Reason = NotReadyV1Beta2Reason
189+
181190
// MachineInfrastructureInvalidConditionReportedV1Beta2Reason surfaces a infrastructure Ready condition (read from an infra machine object) which is invalid.
182191
// (e.g. its status is missing).
183192
MachineInfrastructureInvalidConditionReportedV1Beta2Reason = InvalidConditionReportedV1Beta2Reason
184193

185-
// MachineInfrastructureReadyNoReasonReportedV1Beta2Reason applies to a infrastructure Ready condition (read from an infra machine object) that reports no reason.
186-
MachineInfrastructureReadyNoReasonReportedV1Beta2Reason = NoReasonReportedV1Beta2Reason
187-
188194
// MachineInfrastructureInternalErrorV1Beta2Reason surfaces unexpected failures when reading an infra machine object.
189195
MachineInfrastructureInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason
190196

internal/controllers/cluster/cluster_controller_status.go

Lines changed: 39 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -254,22 +254,31 @@ func setInfrastructureReadyCondition(_ context.Context, cluster *clusterv1.Clust
254254
}
255255

256256
if infraCluster != nil {
257-
if err := v1beta2conditions.SetMirrorConditionFromUnstructured(
258-
infraCluster, cluster,
257+
ready, err := v1beta2conditions.NewMirrorConditionFromUnstructured(
258+
infraCluster,
259259
contract.InfrastructureCluster().ReadyConditionType(), v1beta2conditions.TargetConditionType(clusterv1.ClusterInfrastructureReadyV1Beta2Condition),
260260
v1beta2conditions.FallbackCondition{
261261
Status: v1beta2conditions.BoolToStatus(cluster.Status.InfrastructureReady),
262-
Reason: clusterv1.ClusterInfrastructureReadyNoReasonReportedV1Beta2Reason,
262+
Reason: fallbackReason(cluster.Status.InfrastructureReady, clusterv1.ClusterInfrastructureReadyV1Beta2Reason, clusterv1.ClusterInfrastructureNotReadyV1Beta2Reason),
263263
Message: infrastructureReadyFallBackMessage(cluster.Spec.InfrastructureRef.Kind, cluster.Status.InfrastructureReady),
264264
},
265-
); err != nil {
265+
)
266+
if err != nil {
266267
v1beta2conditions.Set(cluster, metav1.Condition{
267268
Type: clusterv1.ClusterInfrastructureReadyV1Beta2Condition,
268269
Status: metav1.ConditionUnknown,
269270
Reason: clusterv1.ClusterInfrastructureInvalidConditionReportedV1Beta2Reason,
270271
Message: err.Error(),
271272
})
273+
return
274+
}
275+
276+
// In case condition has NoReasonReported and status true, we assume it is a v1beta1 condition
277+
// and replace the reason with something less confusing.
278+
if ready.Reason == v1beta2conditions.NoReasonReported && ready.Status == metav1.ConditionTrue {
279+
ready.Reason = clusterv1.ClusterInfrastructureReadyV1Beta2Reason
272280
}
281+
v1beta2conditions.Set(cluster, *ready)
273282
return
274283
}
275284

@@ -345,22 +354,31 @@ func setControlPlaneAvailableCondition(_ context.Context, cluster *clusterv1.Clu
345354
}
346355

347356
if controlPlane != nil {
348-
if err := v1beta2conditions.SetMirrorConditionFromUnstructured(
349-
controlPlane, cluster,
357+
available, err := v1beta2conditions.NewMirrorConditionFromUnstructured(
358+
controlPlane,
350359
contract.ControlPlane().AvailableConditionType(), v1beta2conditions.TargetConditionType(clusterv1.ClusterControlPlaneAvailableV1Beta2Condition),
351360
v1beta2conditions.FallbackCondition{
352361
Status: v1beta2conditions.BoolToStatus(cluster.Status.ControlPlaneReady),
353-
Reason: clusterv1.ClusterControlPlaneAvailableNoReasonReportedV1Beta2Reason,
362+
Reason: fallbackReason(cluster.Status.ControlPlaneReady, clusterv1.ClusterControlPlaneAvailableV1Beta2Reason, clusterv1.ClusterControlPlaneNotAvailableV1Beta2Reason),
354363
Message: controlPlaneAvailableFallBackMessage(cluster.Spec.ControlPlaneRef.Kind, cluster.Status.ControlPlaneReady),
355364
},
356-
); err != nil {
365+
)
366+
if err != nil {
357367
v1beta2conditions.Set(cluster, metav1.Condition{
358368
Type: clusterv1.ClusterControlPlaneAvailableV1Beta2Condition,
359369
Status: metav1.ConditionUnknown,
360370
Reason: clusterv1.ClusterControlPlaneInvalidConditionReportedV1Beta2Reason,
361371
Message: err.Error(),
362372
})
373+
return
363374
}
375+
376+
// In case condition has NoReasonReported and status true, we assume it is a v1beta1 condition
377+
// and replace the reason with something less confusing.
378+
if available.Reason == v1beta2conditions.NoReasonReported && available.Status == metav1.ConditionTrue {
379+
available.Reason = clusterv1.ClusterControlPlaneAvailableV1Beta2Reason
380+
}
381+
v1beta2conditions.Set(cluster, *available)
364382
return
365383
}
366384

@@ -971,21 +989,6 @@ func setAvailableCondition(ctx context.Context, cluster *clusterv1.Cluster) {
971989
summaryOpts = append(summaryOpts, v1beta2conditions.IgnoreTypesIfMissing{clusterv1.ClusterTopologyReconciledV1Beta2Condition})
972990
}
973991

974-
// Add overrides for conditions we want to surface in the Available condition with slightly different messages.
975-
var overrideConditions v1beta2conditions.OverrideConditions
976-
977-
if infrastructureReadyCondition := calculateInfrastructureReadyForSummary(cluster); infrastructureReadyCondition != nil {
978-
overrideConditions = append(overrideConditions, *infrastructureReadyCondition)
979-
}
980-
981-
if controlPlaneAvailableCondition := calculateControlPlaneAvailableForSummary(cluster); controlPlaneAvailableCondition != nil {
982-
overrideConditions = append(overrideConditions, *controlPlaneAvailableCondition)
983-
}
984-
985-
if len(overrideConditions) > 0 {
986-
summaryOpts = append(summaryOpts, overrideConditions)
987-
}
988-
989992
availableCondition, err := v1beta2conditions.NewSummaryCondition(cluster, clusterv1.ClusterAvailableV1Beta2Condition, summaryOpts...)
990993

991994
if err != nil {
@@ -1003,63 +1006,25 @@ func setAvailableCondition(ctx context.Context, cluster *clusterv1.Cluster) {
10031006
v1beta2conditions.Set(cluster, *availableCondition)
10041007
}
10051008

1006-
func infrastructureReadyFallBackMessage(kind string, ready bool) string {
1007-
return fmt.Sprintf("%s status.ready is %t", kind, ready)
1008-
}
1009-
1010-
func controlPlaneAvailableFallBackMessage(kind string, ready bool) string {
1011-
return fmt.Sprintf("%s status.ready is %t", kind, ready)
1012-
}
1013-
1014-
func calculateInfrastructureReadyForSummary(cluster *clusterv1.Cluster) *v1beta2conditions.ConditionWithOwnerInfo {
1015-
infrastructureReadyCondition := v1beta2conditions.Get(cluster, clusterv1.ClusterInfrastructureReadyV1Beta2Condition)
1016-
1017-
if infrastructureReadyCondition == nil {
1018-
return nil
1019-
}
1020-
1021-
message := infrastructureReadyCondition.Message
1022-
if infrastructureReadyCondition.Status == metav1.ConditionTrue && cluster.Spec.InfrastructureRef != nil && infrastructureReadyCondition.Message == infrastructureReadyFallBackMessage(cluster.Spec.InfrastructureRef.Kind, cluster.Status.InfrastructureReady) {
1023-
message = ""
1024-
}
1025-
1026-
return &v1beta2conditions.ConditionWithOwnerInfo{
1027-
OwnerResource: v1beta2conditions.ConditionOwnerInfo{
1028-
Kind: "Cluster",
1029-
Name: cluster.Name,
1030-
},
1031-
Condition: metav1.Condition{
1032-
Type: infrastructureReadyCondition.Type,
1033-
Status: infrastructureReadyCondition.Status,
1034-
Reason: infrastructureReadyCondition.Reason,
1035-
Message: message,
1036-
},
1009+
func fallbackReason(status bool, trueReason, falseReason string) string {
1010+
if status {
1011+
return trueReason
10371012
}
1013+
return falseReason
10381014
}
10391015

1040-
func calculateControlPlaneAvailableForSummary(cluster *clusterv1.Cluster) *v1beta2conditions.ConditionWithOwnerInfo {
1041-
controlPlaneAvailableCondition := v1beta2conditions.Get(cluster, clusterv1.ClusterControlPlaneAvailableV1Beta2Condition)
1042-
if controlPlaneAvailableCondition == nil {
1043-
return nil
1044-
}
1045-
1046-
message := controlPlaneAvailableCondition.Message
1047-
if controlPlaneAvailableCondition.Status == metav1.ConditionTrue && cluster.Spec.ControlPlaneRef != nil && controlPlaneAvailableCondition.Message == controlPlaneAvailableFallBackMessage(cluster.Spec.ControlPlaneRef.Kind, cluster.Status.ControlPlaneReady) {
1048-
message = ""
1016+
func infrastructureReadyFallBackMessage(kind string, ready bool) string {
1017+
if ready {
1018+
return ""
10491019
}
1020+
return fmt.Sprintf("%s status.ready is %t", kind, ready)
1021+
}
10501022

1051-
return &v1beta2conditions.ConditionWithOwnerInfo{
1052-
OwnerResource: v1beta2conditions.ConditionOwnerInfo{
1053-
Kind: "Cluster",
1054-
Name: cluster.Name,
1055-
},
1056-
Condition: metav1.Condition{
1057-
Type: controlPlaneAvailableCondition.Type,
1058-
Status: controlPlaneAvailableCondition.Status,
1059-
Reason: controlPlaneAvailableCondition.Reason,
1060-
Message: message,
1061-
},
1023+
func controlPlaneAvailableFallBackMessage(kind string, ready bool) string {
1024+
if ready {
1025+
return ""
10621026
}
1027+
return fmt.Sprintf("%s status.ready is %t", kind, ready)
10631028
}
10641029

10651030
func aggregateUnhealthyMachines(machines collections.Machines) string {

0 commit comments

Comments
 (0)