Skip to content

Commit aff4594

Browse files
committed
fix: Result.Requeue Deprecation
With the update to controller-runtime v0.21.0, the `Result.Requeue` field is deprecated. This change updates all references of `Result.Requeue` to either have no value (do not requeue) or set its replacement `Result.RequeueAfter` to a 1-second delay. Assisted-by: Cursor Signed-off-by: Adam Kaplan <adam.kaplan@redhat.com>
1 parent 57f113e commit aff4594

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

controllers/result.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package controllers
22

33
import (
4+
"time"
5+
46
ctrl "sigs.k8s.io/controller-runtime"
57
)
68

79
// Requeue triggers a object requeue.
810
func Requeue() (ctrl.Result, error) {
9-
return ctrl.Result{Requeue: true}, nil
11+
return ctrl.Result{RequeueAfter: 1 * time.Second}, nil
1012
}
1113

1214
// RequeueOnError triggers requeue when error is not nil.
@@ -16,10 +18,10 @@ func RequeueOnError(err error) (ctrl.Result, error) {
1618

1719
// RequeueWithError triggers a object requeue because the informed error happend.
1820
func RequeueWithError(err error) (ctrl.Result, error) {
19-
return ctrl.Result{Requeue: true}, err
21+
return ctrl.Result{RequeueAfter: 1 * time.Second}, err
2022
}
2123

2224
// NoRequeue all done, the object does not need reconciliation anymore.
2325
func NoRequeue() (ctrl.Result, error) {
24-
return ctrl.Result{Requeue: false}, nil
26+
return ctrl.Result{}, nil
2527
}

controllers/shipwrightbuild_controller.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"context"
99
"fmt"
1010
"path/filepath"
11+
"time"
1112

1213
"github.com/go-logr/logr"
1314
"github.com/manifestival/manifestival"
@@ -180,7 +181,11 @@ func (r *ShipwrightBuildReconciler) Reconcile(ctx context.Context, req ctrl.Requ
180181
// ReconcileTekton
181182
_, requeue, err := tekton.ReconcileTekton(ctx, r.CRDClient, r.TektonOperatorClient)
182183
if err != nil {
183-
return ctrl.Result{Requeue: requeue}, err
184+
requeueInterval := 0 * time.Second
185+
if requeue {
186+
requeueInterval = 1 * time.Second
187+
}
188+
return ctrl.Result{RequeueAfter: requeueInterval}, err
184189
}
185190
if requeue {
186191
return Requeue()
@@ -261,7 +266,11 @@ func (r *ShipwrightBuildReconciler) Reconcile(ctx context.Context, req ctrl.Requ
261266
if common.BoolFromEnvVar(UseManagedWebhookCerts) {
262267
requeue, err = certmanager.ReconcileCertManager(ctx, r.CRDClient, r.Client, r.Logger, targetNamespace)
263268
if err != nil {
264-
return ctrl.Result{Requeue: requeue}, err
269+
requeueInterval := 0 * time.Second
270+
if requeue {
271+
requeueInterval = 1 * time.Second
272+
}
273+
return ctrl.Result{RequeueAfter: requeueInterval}, err
265274
}
266275
if requeue {
267276
return Requeue()

controllers/shipwrightbuild_controller_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func testShipwrightBuildReconcilerReconcile(t *testing.T, targetNamespace string
176176
// This makes testing brittle and unable to capture the behavior on a real cluster.
177177
// Requeue can return "true" because the tests think the CRD for ClusterBuildStrategies
178178
// do not exist yet.
179-
g.Expect(res.Requeue).To(o.BeTrue(), "checking requeue for Reconcile")
179+
g.Expect(res.RequeueAfter).NotTo(o.BeZero(), "checking requeue for Reconcile")
180180
err = c.Get(ctx, deploymentName, &appsv1.Deployment{})
181181
g.Expect(err).To(o.BeNil())
182182
err = c.Get(ctx, namespacedName, b)
@@ -199,7 +199,7 @@ func testShipwrightBuildReconcilerReconcile(t *testing.T, targetNamespace string
199199
// This makes testing brittle and unable to capture the behavior on a real cluster.
200200
// Requeue can return "true" because the tests think the CRD for ClusterBuildStrategies
201201
// do not exist yet.
202-
g.Expect(res.Requeue).To(o.BeTrue())
202+
g.Expect(res.RequeueAfter).NotTo(o.BeZero())
203203
err = c.Get(ctx, deploymentName, deployment)
204204
g.Expect(err).To(o.BeNil())
205205
containers := deployment.Spec.Template.Spec.Containers
@@ -229,7 +229,7 @@ func testShipwrightBuildReconcilerReconcile(t *testing.T, targetNamespace string
229229

230230
res, err := r.Reconcile(ctx, req)
231231
g.Expect(err).To(o.BeNil())
232-
g.Expect(res.Requeue).To(o.BeFalse())
232+
g.Expect(res.RequeueAfter).To(o.BeZero())
233233

234234
err = c.Get(ctx, deploymentName, &appsv1.Deployment{})
235235
g.Expect(errors.IsNotFound(err)).To(o.BeTrue())
@@ -342,7 +342,7 @@ func TestShipwrightBuildReconciler_OperandReadiness(t *testing.T) {
342342
req := reconcile.Request{NamespacedName: namespacedName}
343343
res, err := r.Reconcile(ctx, req)
344344
g.Expect(err).To(o.BeNil())
345-
g.Expect(res.Requeue).To(o.BeTrue(), "Reconciliation should requeue when TektonConfig is not ready")
345+
g.Expect(res.RequeueAfter).NotTo(o.BeZero(), "Reconciliation should requeue when TektonConfig is not ready")
346346

347347
// Verify that the ShipwrightBuild is marked as not ready
348348
updated := &v1alpha1.ShipwrightBuild{}
@@ -363,7 +363,7 @@ func TestShipwrightBuildReconciler_OperandReadiness(t *testing.T) {
363363
// Trigger reconciliation again
364364
res, err = r.Reconcile(ctx, req)
365365
g.Expect(err).To(o.BeNil())
366-
g.Expect(res.Requeue).To(o.BeFalse(), "Should not requeue after TektonConfig is ready")
366+
g.Expect(res.RequeueAfter).To(o.BeZero(), "Should not requeue after TektonConfig is ready")
367367

368368
// Fetch and verify ShipwrightBuild is now ready
369369
err = c.Get(ctx, req.NamespacedName, updated)

pkg/certmanager/cert_manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ func ReconcileCertManager(ctx context.Context, crdClient crdclientv1.Apiextensio
3636

3737
manifest, err := common.SetupManifestival(client, "certificates.yaml", false, logger)
3838
if err != nil {
39-
return true, fmt.Errorf("Error creating inital certificates manifest")
39+
return true, fmt.Errorf("error creating inital certificates manifest")
4040
}
4141
manifest, err = manifest.
4242
Filter(mf.Not(mf.ByKind("Namespace"))).
4343
Transform(mf.InjectNamespace(namespace), injectDnsNames(buildCertDomains(namespace)))
4444

4545
if err != nil {
46-
return true, fmt.Errorf("Error transorming manifest using target namespace")
46+
return true, fmt.Errorf("error transorming manifest using target namespace")
4747
}
4848

4949
if err = manifest.Apply(); err != nil {

0 commit comments

Comments
 (0)