@@ -254,22 +254,31 @@ func setInfrastructureReadyCondition(_ context.Context, cluster *clusterv1.Clust
254
254
}
255
255
256
256
if infraCluster != nil {
257
- if err := v1beta2conditions .SetMirrorConditionFromUnstructured (
258
- infraCluster , cluster ,
257
+ ready , err := v1beta2conditions .NewMirrorConditionFromUnstructured (
258
+ infraCluster ,
259
259
contract .InfrastructureCluster ().ReadyConditionType (), v1beta2conditions .TargetConditionType (clusterv1 .ClusterInfrastructureReadyV1Beta2Condition ),
260
260
v1beta2conditions.FallbackCondition {
261
261
Status : v1beta2conditions .BoolToStatus (cluster .Status .InfrastructureReady ),
262
- Reason : clusterv1 .ClusterInfrastructureReadyNoReasonReportedV1Beta2Reason ,
262
+ Reason : fallbackReason ( cluster . Status . InfrastructureReady , clusterv1 .ClusterInfrastructureReadyV1Beta2Reason , clusterv1 . ClusterInfrastructureNotReadyV1Beta2Reason ) ,
263
263
Message : infrastructureReadyFallBackMessage (cluster .Spec .InfrastructureRef .Kind , cluster .Status .InfrastructureReady ),
264
264
},
265
- ); err != nil {
265
+ )
266
+ if err != nil {
266
267
v1beta2conditions .Set (cluster , metav1.Condition {
267
268
Type : clusterv1 .ClusterInfrastructureReadyV1Beta2Condition ,
268
269
Status : metav1 .ConditionUnknown ,
269
270
Reason : clusterv1 .ClusterInfrastructureInvalidConditionReportedV1Beta2Reason ,
270
271
Message : err .Error (),
271
272
})
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
272
280
}
281
+ v1beta2conditions .Set (cluster , * ready )
273
282
return
274
283
}
275
284
@@ -345,22 +354,31 @@ func setControlPlaneAvailableCondition(_ context.Context, cluster *clusterv1.Clu
345
354
}
346
355
347
356
if controlPlane != nil {
348
- if err := v1beta2conditions .SetMirrorConditionFromUnstructured (
349
- controlPlane , cluster ,
357
+ available , err := v1beta2conditions .NewMirrorConditionFromUnstructured (
358
+ controlPlane ,
350
359
contract .ControlPlane ().AvailableConditionType (), v1beta2conditions .TargetConditionType (clusterv1 .ClusterControlPlaneAvailableV1Beta2Condition ),
351
360
v1beta2conditions.FallbackCondition {
352
361
Status : v1beta2conditions .BoolToStatus (cluster .Status .ControlPlaneReady ),
353
- Reason : clusterv1 .ClusterControlPlaneAvailableNoReasonReportedV1Beta2Reason ,
362
+ Reason : fallbackReason ( cluster . Status . ControlPlaneReady , clusterv1 .ClusterControlPlaneAvailableV1Beta2Reason , clusterv1 . ClusterControlPlaneNotAvailableV1Beta2Reason ) ,
354
363
Message : controlPlaneAvailableFallBackMessage (cluster .Spec .ControlPlaneRef .Kind , cluster .Status .ControlPlaneReady ),
355
364
},
356
- ); err != nil {
365
+ )
366
+ if err != nil {
357
367
v1beta2conditions .Set (cluster , metav1.Condition {
358
368
Type : clusterv1 .ClusterControlPlaneAvailableV1Beta2Condition ,
359
369
Status : metav1 .ConditionUnknown ,
360
370
Reason : clusterv1 .ClusterControlPlaneInvalidConditionReportedV1Beta2Reason ,
361
371
Message : err .Error (),
362
372
})
373
+ return
363
374
}
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 )
364
382
return
365
383
}
366
384
@@ -971,21 +989,6 @@ func setAvailableCondition(ctx context.Context, cluster *clusterv1.Cluster) {
971
989
summaryOpts = append (summaryOpts , v1beta2conditions.IgnoreTypesIfMissing {clusterv1 .ClusterTopologyReconciledV1Beta2Condition })
972
990
}
973
991
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
-
989
992
availableCondition , err := v1beta2conditions .NewSummaryCondition (cluster , clusterv1 .ClusterAvailableV1Beta2Condition , summaryOpts ... )
990
993
991
994
if err != nil {
@@ -1003,63 +1006,25 @@ func setAvailableCondition(ctx context.Context, cluster *clusterv1.Cluster) {
1003
1006
v1beta2conditions .Set (cluster , * availableCondition )
1004
1007
}
1005
1008
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
1037
1012
}
1013
+ return falseReason
1038
1014
}
1039
1015
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 ""
1049
1019
}
1020
+ return fmt .Sprintf ("%s status.ready is %t" , kind , ready )
1021
+ }
1050
1022
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 ""
1062
1026
}
1027
+ return fmt .Sprintf ("%s status.ready is %t" , kind , ready )
1063
1028
}
1064
1029
1065
1030
func aggregateUnhealthyMachines (machines collections.Machines ) string {
0 commit comments