@@ -19,6 +19,7 @@ package v1beta1
1919import (
2020 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121 clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
22+ v1beta2conditions "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/conditions/v1beta2"
2223)
2324
2425// HCloudRemediationSpec defines the desired state of HCloudRemediation.
@@ -46,6 +47,21 @@ type HCloudRemediationStatus struct {
4647 // Conditions defines current service state of the HCloudRemediation.
4748 // +optional
4849 Conditions clusterv1beta1.Conditions `json:"conditions,omitempty"`
50+
51+ // v1beta2 groups all the fields that will be added or modified in HCloudRemediation's status with the V1Beta2 version.
52+ // +optional
53+ V1Beta2 * HCloudRemediationV1Beta2Status `json:"v1beta2,omitempty"`
54+ }
55+
56+ // HCloudRemediationV1Beta2Status groups all the fields that will be added or modified in HCloudRemediationStatus with the V1Beta2 version.
57+ type HCloudRemediationV1Beta2Status struct {
58+ // conditions represents the observations of a HCloudRemediation's current state.
59+ // Known condition types are Ready, HCloudTokenAvailable and HCloudRateLimitExceeded.
60+ // +optional
61+ // +listType=map
62+ // +listMapKey=type
63+ // +kubebuilder:validation:MaxItems=32
64+ Conditions []metav1.Condition `json:"conditions,omitempty"`
4965}
5066
5167// +kubebuilder:object:root=true
@@ -82,6 +98,22 @@ func (r *HCloudRemediation) SetConditions(conditions clusterv1beta1.Conditions)
8298 r .Status .Conditions = conditions
8399}
84100
101+ // GetV1Beta2Conditions returns the observations of the operational state of the HCloudRemediation resource.
102+ func (r * HCloudRemediation ) GetV1Beta2Conditions () []metav1.Condition {
103+ if r .Status .V1Beta2 == nil {
104+ return nil
105+ }
106+ return r .Status .V1Beta2 .Conditions
107+ }
108+
109+ // SetV1Beta2Conditions sets the underlying v1beta2 service state of the HCloudRemediation.
110+ func (r * HCloudRemediation ) SetV1Beta2Conditions (conditions []metav1.Condition ) {
111+ if r .Status .V1Beta2 == nil {
112+ r .Status .V1Beta2 = & HCloudRemediationV1Beta2Status {}
113+ }
114+ r .Status .V1Beta2 .Conditions = conditions
115+ }
116+
85117//+kubebuilder:object:root=true
86118
87119// HCloudRemediationList contains a list of HCloudRemediation.
@@ -92,6 +124,64 @@ type HCloudRemediationList struct {
92124 Items []HCloudRemediation `json:"items"`
93125}
94126
127+ // HCloudRemediationV1Beta2SummaryOpts returns the v1beta2 summary options for HCloudRemediation.
128+ // It is the single source of truth for which conditions contribute to the Ready summary,
129+ // used both by HCloudRemediationScope.Close() and by early-exit error paths that bypass the scope.
130+ //
131+ // The order of conditions in ForConditionTypes defines the priority for the Ready summary:
132+ // when multiple conditions are unhealthy, the summary lists all of them in priority order
133+ // (highest-priority first). The ordering reflects operational importance:
134+ // 1. HCloudTokenAvailable - invalid credentials block everything.
135+ // 2. HCloudRateLimitExceeded - rate-limit issues (negative polarity).
136+ // 3. RemediationSkipped - remediation was skipped due to an irrecoverable
137+ // machine state; surfaced for visibility (negative polarity).
138+ func HCloudRemediationV1Beta2SummaryOpts () []v1beta2conditions.SummaryOption {
139+ return []v1beta2conditions.SummaryOption {
140+ // ForConditionTypes lists every condition that contributes to Ready, in
141+ // priority order. When multiple conditions are unhealthy the summary
142+ // surfaces them in this order, so the most important issue is listed first.
143+ v1beta2conditions.ForConditionTypes {
144+ HCloudTokenAvailableV1Beta2Condition ,
145+ HCloudRateLimitExceededV1Beta2Condition ,
146+ HCloudRemediationSkippedV1Beta2Condition ,
147+ },
148+ // IgnoreTypesIfMissing tells the summary not to treat the absence of a
149+ // listed condition as Unknown. Some reconcile paths exit before every
150+ // condition has been set (for example, before the token is checked or
151+ // before remediation has been evaluated), and we don't want those early
152+ // exits to flip Ready to Unknown.
153+ v1beta2conditions.IgnoreTypesIfMissing {
154+ HCloudTokenAvailableV1Beta2Condition ,
155+ HCloudRateLimitExceededV1Beta2Condition ,
156+ HCloudRemediationSkippedV1Beta2Condition ,
157+ },
158+ // CustomMergeStrategy is used only to override the merge reasons, so
159+ // the Ready summary uses CAPI's standard Ready reasons (Ready /
160+ // NotReady / ReadyUnknown) instead of the generic merge defaults
161+ // (IssuesReported / UnknownReported / InfoReported).
162+ //
163+ // Negative polarity is passed directly into GetDefaultMergePriorityFunc
164+ // here. When a CustomMergeStrategy is provided, NewSummaryCondition
165+ // skips the path that wires up the NegativePolarityConditionTypes
166+ // SummaryOption into the default strategy, so the negative-polarity
167+ // types must be specified explicitly inside the strategy.
168+ v1beta2conditions.CustomMergeStrategy {
169+ MergeStrategy : v1beta2conditions .DefaultMergeStrategy (
170+ v1beta2conditions .GetPriorityFunc (v1beta2conditions .GetDefaultMergePriorityFunc (
171+ // conditions with negative polarity
172+ HCloudRateLimitExceededV1Beta2Condition ,
173+ HCloudRemediationSkippedV1Beta2Condition ,
174+ )),
175+ v1beta2conditions .ComputeReasonFunc (v1beta2conditions .GetDefaultComputeMergeReasonFunc (
176+ clusterv1beta1 .NotReadyV1Beta2Reason ,
177+ clusterv1beta1 .ReadyUnknownV1Beta2Reason ,
178+ clusterv1beta1 .ReadyV1Beta2Reason ,
179+ )),
180+ ),
181+ },
182+ }
183+ }
184+
95185func init () {
96186 objectTypes = append (objectTypes , & HCloudRemediation {}, & HCloudRemediationList {})
97187}
0 commit comments