Skip to content

Commit 5262291

Browse files
Refine v1beta2 mirror conditions
# Conflicts: # internal/controllers/cluster/cluster_controller_status.go # internal/controllers/cluster/cluster_controller_status_test.go
1 parent 5bd7ded commit 5262291

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
@@ -241,22 +241,31 @@ func setInfrastructureReadyCondition(_ context.Context, cluster *clusterv1.Clust
241241
}
242242

243243
if infraCluster != nil {
244-
if err := v1beta2conditions.SetMirrorConditionFromUnstructured(
245-
infraCluster, cluster,
244+
ready, err := v1beta2conditions.NewMirrorConditionFromUnstructured(
245+
infraCluster,
246246
contract.InfrastructureCluster().ReadyConditionType(), v1beta2conditions.TargetConditionType(clusterv1.ClusterInfrastructureReadyV1Beta2Condition),
247247
v1beta2conditions.FallbackCondition{
248248
Status: v1beta2conditions.BoolToStatus(cluster.Status.InfrastructureReady),
249-
Reason: clusterv1.ClusterInfrastructureReadyNoReasonReportedV1Beta2Reason,
249+
Reason: fallbackReason(cluster.Status.InfrastructureReady, clusterv1.ClusterInfrastructureReadyV1Beta2Reason, clusterv1.ClusterInfrastructureNotReadyV1Beta2Reason),
250250
Message: infrastructureReadyFallBackMessage(cluster.Spec.InfrastructureRef.Kind, cluster.Status.InfrastructureReady),
251251
},
252-
); err != nil {
252+
)
253+
if err != nil {
253254
v1beta2conditions.Set(cluster, metav1.Condition{
254255
Type: clusterv1.ClusterInfrastructureReadyV1Beta2Condition,
255256
Status: metav1.ConditionUnknown,
256257
Reason: clusterv1.ClusterInfrastructureInvalidConditionReportedV1Beta2Reason,
257258
Message: err.Error(),
258259
})
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
259267
}
268+
v1beta2conditions.Set(cluster, *ready)
260269
return
261270
}
262271

@@ -332,22 +341,31 @@ func setControlPlaneAvailableCondition(_ context.Context, cluster *clusterv1.Clu
332341
}
333342

334343
if controlPlane != nil {
335-
if err := v1beta2conditions.SetMirrorConditionFromUnstructured(
336-
controlPlane, cluster,
344+
available, err := v1beta2conditions.NewMirrorConditionFromUnstructured(
345+
controlPlane,
337346
contract.ControlPlane().AvailableConditionType(), v1beta2conditions.TargetConditionType(clusterv1.ClusterControlPlaneAvailableV1Beta2Condition),
338347
v1beta2conditions.FallbackCondition{
339348
Status: v1beta2conditions.BoolToStatus(cluster.Status.ControlPlaneReady),
340-
Reason: clusterv1.ClusterControlPlaneAvailableNoReasonReportedV1Beta2Reason,
349+
Reason: fallbackReason(cluster.Status.ControlPlaneReady, clusterv1.ClusterControlPlaneAvailableV1Beta2Reason, clusterv1.ClusterControlPlaneNotAvailableV1Beta2Reason),
341350
Message: controlPlaneAvailableFallBackMessage(cluster.Spec.ControlPlaneRef.Kind, cluster.Status.ControlPlaneReady),
342351
},
343-
); err != nil {
352+
)
353+
if err != nil {
344354
v1beta2conditions.Set(cluster, metav1.Condition{
345355
Type: clusterv1.ClusterControlPlaneAvailableV1Beta2Condition,
346356
Status: metav1.ConditionUnknown,
347357
Reason: clusterv1.ClusterControlPlaneInvalidConditionReportedV1Beta2Reason,
348358
Message: err.Error(),
349359
})
360+
return
350361
}
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)
351369
return
352370
}
353371

@@ -958,21 +976,6 @@ func setAvailableCondition(ctx context.Context, cluster *clusterv1.Cluster) {
958976
summaryOpts = append(summaryOpts, v1beta2conditions.IgnoreTypesIfMissing{clusterv1.ClusterTopologyReconciledV1Beta2Condition})
959977
}
960978

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-
976979
availableCondition, err := v1beta2conditions.NewSummaryCondition(cluster, clusterv1.ClusterAvailableV1Beta2Condition, summaryOpts...)
977980

978981
if err != nil {
@@ -990,63 +993,25 @@ func setAvailableCondition(ctx context.Context, cluster *clusterv1.Cluster) {
990993
v1beta2conditions.Set(cluster, *availableCondition)
991994
}
992995

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
1024999
}
1000+
return falseReason
10251001
}
10261002

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 ""
10361006
}
1007+
return fmt.Sprintf("%s status.ready is %t", kind, ready)
1008+
}
10371009

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 ""
10491013
}
1014+
return fmt.Sprintf("%s status.ready is %t", kind, ready)
10501015
}
10511016

10521017
func aggregateUnhealthyMachines(machines collections.Machines) string {

0 commit comments

Comments
 (0)