Skip to content

Commit 295c589

Browse files
author
Per Goncalves da Silva
committed
Move exported Mark* methods out of ClusterExtensionRevision API
Signed-off-by: Per Goncalves da Silva <pegoncal@redhat.com>
1 parent b0a0a48 commit 295c589

File tree

2 files changed

+50
-51
lines changed

2 files changed

+50
-51
lines changed

api/v1/clusterextensionrevision_types.go

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package v1
1818

1919
import (
20-
"k8s.io/apimachinery/pkg/api/meta"
2120
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2221
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2322
"k8s.io/apimachinery/pkg/types"
@@ -171,46 +170,6 @@ type ClusterExtensionRevision struct {
171170
Status ClusterExtensionRevisionStatus `json:"status,omitempty"`
172171
}
173172

174-
func (cer *ClusterExtensionRevision) MarkAsProgressing(reason, message string) {
175-
meta.SetStatusCondition(&cer.Status.Conditions, metav1.Condition{
176-
Type: ClusterExtensionRevisionTypeProgressing,
177-
Status: metav1.ConditionTrue,
178-
Reason: reason,
179-
Message: message,
180-
ObservedGeneration: cer.Generation,
181-
})
182-
}
183-
184-
func (cer *ClusterExtensionRevision) MarkAsNotProgressing(reason, message string) {
185-
meta.SetStatusCondition(&cer.Status.Conditions, metav1.Condition{
186-
Type: ClusterExtensionRevisionTypeProgressing,
187-
Status: metav1.ConditionFalse,
188-
Reason: reason,
189-
Message: message,
190-
ObservedGeneration: cer.Generation,
191-
})
192-
}
193-
194-
func (cer *ClusterExtensionRevision) MarkAsAvailable(reason, message string) {
195-
meta.SetStatusCondition(&cer.Status.Conditions, metav1.Condition{
196-
Type: ClusterExtensionRevisionTypeAvailable,
197-
Status: metav1.ConditionTrue,
198-
Reason: reason,
199-
Message: message,
200-
ObservedGeneration: cer.Generation,
201-
})
202-
}
203-
204-
func (cer *ClusterExtensionRevision) MarkAsUnavailable(reason, message string) {
205-
meta.SetStatusCondition(&cer.Status.Conditions, metav1.Condition{
206-
Type: ClusterExtensionRevisionTypeAvailable,
207-
Status: metav1.ConditionFalse,
208-
Reason: reason,
209-
Message: message,
210-
ObservedGeneration: cer.Generation,
211-
})
212-
}
213-
214173
// +kubebuilder:object:root=true
215174

216175
// ClusterExtensionRevisionList contains a list of ClusterExtensionRevision

internal/operator-controller/controllers/clusterextensionrevision_controller.go

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ func (c *ClusterExtensionRevisionReconciler) reconcile(ctx context.Context, rev
140140
if err := c.establishWatch(ctx, rev, revision); err != nil {
141141
werr := fmt.Errorf("establish watch: %v", err)
142142
// this error is very likely transient, so we should keep revision as progressing
143-
rev.MarkAsProgressing(ocv1.ClusterExtensionRevisionReasonReconcileFailure, werr.Error())
143+
markAsProgressing(rev, ocv1.ClusterExtensionRevisionReasonReconcileFailure, werr.Error())
144144
return ctrl.Result{}, werr
145145
}
146-
rev.MarkAsProgressing(ocv1.ClusterExtensionRevisionReasonRolloutInProgress, fmt.Sprintf("Revision %s is being rolled out.", revVersion))
146+
markAsProgressing(rev, ocv1.ClusterExtensionRevisionReasonRolloutInProgress, fmt.Sprintf("Revision %s is being rolled out.", revVersion))
147147
}
148148

149149
rres, err := c.RevisionEngine.Reconcile(ctx, *revision, opts...)
@@ -154,7 +154,7 @@ func (c *ClusterExtensionRevisionReconciler) reconcile(ctx context.Context, rev
154154
l.Error(err, "revision reconcile failed")
155155
}
156156
if inRollout {
157-
rev.MarkAsProgressing(ocv1.ClusterExtensionRevisionReasonRolloutError, err.Error())
157+
markAsProgressing(rev, ocv1.ClusterExtensionRevisionReasonRolloutError, err.Error())
158158
} else {
159159
// it is a probably transient error, and we do not know if the revision is available or not
160160
// perhaps we should not report it at all, hoping that it is going to be mitigated in the next reconcile?
@@ -178,7 +178,7 @@ func (c *ClusterExtensionRevisionReconciler) reconcile(ctx context.Context, rev
178178

179179
if inRollout {
180180
// given that we retry, we are going to keep Progressing condition True
181-
rev.MarkAsProgressing(ocv1.ClusterExtensionRevisionReasonRevisionValidationFailure, fmt.Sprintf("revision validation error: %s", verr))
181+
markAsProgressing(rev, ocv1.ClusterExtensionRevisionReasonRevisionValidationFailure, fmt.Sprintf("revision validation error: %s", verr))
182182
} else {
183183
// it is a probably transient error, and we do not know if the revision is available or not
184184
// perhaps we should not report it at all, hoping that it is going to be mitigated in the next reconcile?
@@ -199,7 +199,7 @@ func (c *ClusterExtensionRevisionReconciler) reconcile(ctx context.Context, rev
199199

200200
if inRollout {
201201
// given that we retry, we are going to keep Progressing condition True
202-
rev.MarkAsProgressing(ocv1.ClusterExtensionRevisionReasonPhaseValidationError, fmt.Sprintf("phase %d validation error: %s", i, verr))
202+
markAsProgressing(rev, ocv1.ClusterExtensionRevisionReasonPhaseValidationError, fmt.Sprintf("phase %d validation error: %s", i, verr))
203203
} else {
204204
// it is a probably transient error, and we do not know if the revision is available or not
205205
// perhaps we should not report it at all, hoping that it is going to be mitigated in the next reconcile?
@@ -226,7 +226,7 @@ func (c *ClusterExtensionRevisionReconciler) reconcile(ctx context.Context, rev
226226
// collisions are probably stickier than phase roll out probe failures - so we'd probably want to set
227227
// Progressing to false here due to the collision
228228
if inRollout {
229-
rev.MarkAsNotProgressing(ocv1.ClusterExtensionRevisionReasonObjectCollisions, fmt.Sprintf("revision object collisions in phase %d\n%s", i, strings.Join(collidingObjs, "\n\n")))
229+
markAsNotProgressing(rev, ocv1.ClusterExtensionRevisionReasonObjectCollisions, fmt.Sprintf("revision object collisions in phase %d\n%s", i, strings.Join(collidingObjs, "\n\n")))
230230

231231
// NOTE(pedjak): not sure if we want to retry here - collisions are probably not transient?
232232
return ctrl.Result{RequeueAfter: 10 * time.Second}, nil
@@ -236,7 +236,7 @@ func (c *ClusterExtensionRevisionReconciler) reconcile(ctx context.Context, rev
236236

237237
if !rres.InTransistion() {
238238
// we have rolled out all objects in all phases, not interested in probes here
239-
rev.MarkAsNotProgressing(ocv1.ClusterExtensionRevisionReasonRolledOut, fmt.Sprintf("Revision %s is rolled out.", revVersion))
239+
markAsNotProgressing(rev, ocv1.ClusterExtensionRevisionReasonRolledOut, fmt.Sprintf("Revision %s is rolled out.", revVersion))
240240
}
241241

242242
//nolint:nestif
@@ -254,7 +254,7 @@ func (c *ClusterExtensionRevisionReconciler) reconcile(ctx context.Context, rev
254254

255255
// It would be good to understand from Nico how we can distinguish between progression and availability probes
256256
// and how to best check that all Availability probes are passing
257-
rev.MarkAsAvailable(ocv1.ClusterExtensionRevisionReasonProbesSucceeded, "Objects are available and pass all probes.")
257+
markAsAvailable(rev, ocv1.ClusterExtensionRevisionReasonProbesSucceeded, "Objects are available and pass all probes.")
258258

259259
// We'll probably only want to remove this once we are done updating the ClusterExtension conditions
260260
// as its one of the interfaces between the revision and the extension. If we still have the Succeeded for now
@@ -293,9 +293,9 @@ func (c *ClusterExtensionRevisionReconciler) reconcile(ctx context.Context, rev
293293
}
294294
}
295295
if len(probeFailureMsgs) > 0 {
296-
rev.MarkAsUnavailable(ocv1.ClusterExtensionRevisionReasonProbeFailure, strings.Join(probeFailureMsgs, "\n"))
296+
markAsUnavailable(rev, ocv1.ClusterExtensionRevisionReasonProbeFailure, strings.Join(probeFailureMsgs, "\n"))
297297
} else {
298-
rev.MarkAsUnavailable(ocv1.ClusterExtensionRevisionReasonIncomplete, fmt.Sprintf("Revision %s has not been rolled out completely.", revVersion))
298+
markAsUnavailable(rev, ocv1.ClusterExtensionRevisionReasonIncomplete, fmt.Sprintf("Revision %s has not been rolled out completely.", revVersion))
299299
}
300300
}
301301

@@ -561,3 +561,43 @@ var (
561561
FieldB: ".status.replicas",
562562
}
563563
)
564+
565+
func markAsProgressing(cer *ocv1.ClusterExtensionRevision, reason, message string) {
566+
meta.SetStatusCondition(&cer.Status.Conditions, metav1.Condition{
567+
Type: ocv1.ClusterExtensionRevisionTypeProgressing,
568+
Status: metav1.ConditionTrue,
569+
Reason: reason,
570+
Message: message,
571+
ObservedGeneration: cer.Generation,
572+
})
573+
}
574+
575+
func markAsNotProgressing(cer *ocv1.ClusterExtensionRevision, reason, message string) {
576+
meta.SetStatusCondition(&cer.Status.Conditions, metav1.Condition{
577+
Type: ocv1.ClusterExtensionRevisionTypeProgressing,
578+
Status: metav1.ConditionFalse,
579+
Reason: reason,
580+
Message: message,
581+
ObservedGeneration: cer.Generation,
582+
})
583+
}
584+
585+
func markAsAvailable(cer *ocv1.ClusterExtensionRevision, reason, message string) {
586+
meta.SetStatusCondition(&cer.Status.Conditions, metav1.Condition{
587+
Type: ocv1.ClusterExtensionRevisionTypeAvailable,
588+
Status: metav1.ConditionTrue,
589+
Reason: reason,
590+
Message: message,
591+
ObservedGeneration: cer.Generation,
592+
})
593+
}
594+
595+
func markAsUnavailable(cer *ocv1.ClusterExtensionRevision, reason, message string) {
596+
meta.SetStatusCondition(&cer.Status.Conditions, metav1.Condition{
597+
Type: ocv1.ClusterExtensionRevisionTypeAvailable,
598+
Status: metav1.ConditionFalse,
599+
Reason: reason,
600+
Message: message,
601+
ObservedGeneration: cer.Generation,
602+
})
603+
}

0 commit comments

Comments
 (0)