@@ -241,22 +241,31 @@ func setInfrastructureReadyCondition(_ context.Context, cluster *clusterv1.Clust
241
241
}
242
242
243
243
if infraCluster != nil {
244
- if err := v1beta2conditions .SetMirrorConditionFromUnstructured (
245
- infraCluster , cluster ,
244
+ ready , err := v1beta2conditions .NewMirrorConditionFromUnstructured (
245
+ infraCluster ,
246
246
contract .InfrastructureCluster ().ReadyConditionType (), v1beta2conditions .TargetConditionType (clusterv1 .ClusterInfrastructureReadyV1Beta2Condition ),
247
247
v1beta2conditions.FallbackCondition {
248
248
Status : v1beta2conditions .BoolToStatus (cluster .Status .InfrastructureReady ),
249
- Reason : clusterv1 .ClusterInfrastructureReadyNoReasonReportedV1Beta2Reason ,
249
+ Reason : fallbackReason ( cluster . Status . InfrastructureReady , clusterv1 .ClusterInfrastructureReadyV1Beta2Reason , clusterv1 . ClusterInfrastructureNotReadyV1Beta2Reason ) ,
250
250
Message : infrastructureReadyFallBackMessage (cluster .Spec .InfrastructureRef .Kind , cluster .Status .InfrastructureReady ),
251
251
},
252
- ); err != nil {
252
+ )
253
+ if err != nil {
253
254
v1beta2conditions .Set (cluster , metav1.Condition {
254
255
Type : clusterv1 .ClusterInfrastructureReadyV1Beta2Condition ,
255
256
Status : metav1 .ConditionUnknown ,
256
257
Reason : clusterv1 .ClusterInfrastructureInvalidConditionReportedV1Beta2Reason ,
257
258
Message : err .Error (),
258
259
})
260
+ return
261
+ }
262
+
263
+ // In case condition has NoReasonReported and status true, we assume it is a v1beta1 condition
264
+ // and replace the reason with something less confusing.
265
+ if ready .Reason == v1beta2conditions .NoReasonReported && ready .Status == metav1 .ConditionTrue {
266
+ ready .Reason = clusterv1 .ClusterInfrastructureReadyV1Beta2Reason
259
267
}
268
+ v1beta2conditions .Set (cluster , * ready )
260
269
return
261
270
}
262
271
@@ -332,22 +341,31 @@ func setControlPlaneAvailableCondition(_ context.Context, cluster *clusterv1.Clu
332
341
}
333
342
334
343
if controlPlane != nil {
335
- if err := v1beta2conditions .SetMirrorConditionFromUnstructured (
336
- controlPlane , cluster ,
344
+ available , err := v1beta2conditions .NewMirrorConditionFromUnstructured (
345
+ controlPlane ,
337
346
contract .ControlPlane ().AvailableConditionType (), v1beta2conditions .TargetConditionType (clusterv1 .ClusterControlPlaneAvailableV1Beta2Condition ),
338
347
v1beta2conditions.FallbackCondition {
339
348
Status : v1beta2conditions .BoolToStatus (cluster .Status .ControlPlaneReady ),
340
- Reason : clusterv1 .ClusterControlPlaneAvailableNoReasonReportedV1Beta2Reason ,
349
+ Reason : fallbackReason ( cluster . Status . ControlPlaneReady , clusterv1 .ClusterControlPlaneAvailableV1Beta2Reason , clusterv1 . ClusterControlPlaneNotAvailableV1Beta2Reason ) ,
341
350
Message : controlPlaneAvailableFallBackMessage (cluster .Spec .ControlPlaneRef .Kind , cluster .Status .ControlPlaneReady ),
342
351
},
343
- ); err != nil {
352
+ )
353
+ if err != nil {
344
354
v1beta2conditions .Set (cluster , metav1.Condition {
345
355
Type : clusterv1 .ClusterControlPlaneAvailableV1Beta2Condition ,
346
356
Status : metav1 .ConditionUnknown ,
347
357
Reason : clusterv1 .ClusterControlPlaneInvalidConditionReportedV1Beta2Reason ,
348
358
Message : err .Error (),
349
359
})
360
+ return
350
361
}
362
+
363
+ // In case condition has NoReasonReported and status true, we assume it is a v1beta1 condition
364
+ // and replace the reason with something less confusing.
365
+ if available .Reason == v1beta2conditions .NoReasonReported && available .Status == metav1 .ConditionTrue {
366
+ available .Reason = clusterv1 .ClusterControlPlaneAvailableV1Beta2Reason
367
+ }
368
+ v1beta2conditions .Set (cluster , * available )
351
369
return
352
370
}
353
371
@@ -958,21 +976,6 @@ func setAvailableCondition(ctx context.Context, cluster *clusterv1.Cluster) {
958
976
summaryOpts = append (summaryOpts , v1beta2conditions.IgnoreTypesIfMissing {clusterv1 .ClusterTopologyReconciledV1Beta2Condition })
959
977
}
960
978
961
- // Add overrides for conditions we want to surface in the Available condition with slightly different messages.
962
- var overrideConditions v1beta2conditions.OverrideConditions
963
-
964
- if infrastructureReadyCondition := calculateInfrastructureReadyForSummary (cluster ); infrastructureReadyCondition != nil {
965
- overrideConditions = append (overrideConditions , * infrastructureReadyCondition )
966
- }
967
-
968
- if controlPlaneAvailableCondition := calculateControlPlaneAvailableForSummary (cluster ); controlPlaneAvailableCondition != nil {
969
- overrideConditions = append (overrideConditions , * controlPlaneAvailableCondition )
970
- }
971
-
972
- if len (overrideConditions ) > 0 {
973
- summaryOpts = append (summaryOpts , overrideConditions )
974
- }
975
-
976
979
availableCondition , err := v1beta2conditions .NewSummaryCondition (cluster , clusterv1 .ClusterAvailableV1Beta2Condition , summaryOpts ... )
977
980
978
981
if err != nil {
@@ -990,63 +993,25 @@ func setAvailableCondition(ctx context.Context, cluster *clusterv1.Cluster) {
990
993
v1beta2conditions .Set (cluster , * availableCondition )
991
994
}
992
995
993
- func infrastructureReadyFallBackMessage (kind string , ready bool ) string {
994
- return fmt .Sprintf ("%s status.ready is %t" , kind , ready )
995
- }
996
-
997
- func controlPlaneAvailableFallBackMessage (kind string , ready bool ) string {
998
- return fmt .Sprintf ("%s status.ready is %t" , kind , ready )
999
- }
1000
-
1001
- func calculateInfrastructureReadyForSummary (cluster * clusterv1.Cluster ) * v1beta2conditions.ConditionWithOwnerInfo {
1002
- infrastructureReadyCondition := v1beta2conditions .Get (cluster , clusterv1 .ClusterInfrastructureReadyV1Beta2Condition )
1003
-
1004
- if infrastructureReadyCondition == nil {
1005
- return nil
1006
- }
1007
-
1008
- message := infrastructureReadyCondition .Message
1009
- if infrastructureReadyCondition .Status == metav1 .ConditionTrue && cluster .Spec .InfrastructureRef != nil && infrastructureReadyCondition .Message == infrastructureReadyFallBackMessage (cluster .Spec .InfrastructureRef .Kind , cluster .Status .InfrastructureReady ) {
1010
- message = ""
1011
- }
1012
-
1013
- return & v1beta2conditions.ConditionWithOwnerInfo {
1014
- OwnerResource : v1beta2conditions.ConditionOwnerInfo {
1015
- Kind : "Cluster" ,
1016
- Name : cluster .Name ,
1017
- },
1018
- Condition : metav1.Condition {
1019
- Type : infrastructureReadyCondition .Type ,
1020
- Status : infrastructureReadyCondition .Status ,
1021
- Reason : infrastructureReadyCondition .Reason ,
1022
- Message : message ,
1023
- },
996
+ func fallbackReason (status bool , trueReason , falseReason string ) string {
997
+ if status {
998
+ return trueReason
1024
999
}
1000
+ return falseReason
1025
1001
}
1026
1002
1027
- func calculateControlPlaneAvailableForSummary (cluster * clusterv1.Cluster ) * v1beta2conditions.ConditionWithOwnerInfo {
1028
- controlPlaneAvailableCondition := v1beta2conditions .Get (cluster , clusterv1 .ClusterControlPlaneAvailableV1Beta2Condition )
1029
- if controlPlaneAvailableCondition == nil {
1030
- return nil
1031
- }
1032
-
1033
- message := controlPlaneAvailableCondition .Message
1034
- if controlPlaneAvailableCondition .Status == metav1 .ConditionTrue && cluster .Spec .ControlPlaneRef != nil && controlPlaneAvailableCondition .Message == controlPlaneAvailableFallBackMessage (cluster .Spec .ControlPlaneRef .Kind , cluster .Status .ControlPlaneReady ) {
1035
- message = ""
1003
+ func infrastructureReadyFallBackMessage (kind string , ready bool ) string {
1004
+ if ready {
1005
+ return ""
1036
1006
}
1007
+ return fmt .Sprintf ("%s status.ready is %t" , kind , ready )
1008
+ }
1037
1009
1038
- return & v1beta2conditions.ConditionWithOwnerInfo {
1039
- OwnerResource : v1beta2conditions.ConditionOwnerInfo {
1040
- Kind : "Cluster" ,
1041
- Name : cluster .Name ,
1042
- },
1043
- Condition : metav1.Condition {
1044
- Type : controlPlaneAvailableCondition .Type ,
1045
- Status : controlPlaneAvailableCondition .Status ,
1046
- Reason : controlPlaneAvailableCondition .Reason ,
1047
- Message : message ,
1048
- },
1010
+ func controlPlaneAvailableFallBackMessage (kind string , ready bool ) string {
1011
+ if ready {
1012
+ return ""
1049
1013
}
1014
+ return fmt .Sprintf ("%s status.ready is %t" , kind , ready )
1050
1015
}
1051
1016
1052
1017
func aggregateUnhealthyMachines (machines collections.Machines ) string {
0 commit comments