Skip to content

Commit a1ed1fc

Browse files
committed
source: GetRequeueAfter in place of GetInterval
The problem with `GetInterval()` was that the returned type was of `metav1.Duration`, while almost anywhere it was used, a type of `time.Duration` was requested. The result of this was that we had to call `GetInterval().Duration` all the time, which would become a bit cumbersome after awhile. To prevent this, we introduce a new `GetRequeueAfter() time.Duration` method, which both results the right type, and bears a name that is easier to remember where the value is used most; while setting the `Result.RequeueAfter` during reconcile operations. The introduced of this method deprecates `GetInterval()`, which should be removed in a future MINOR release. Signed-off-by: Hidde Beydals <[email protected]>
1 parent f1de98f commit a1ed1fc

9 files changed

+52
-15
lines changed

api/v1beta1/bucket_types.go

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

1919
import (
20+
"time"
21+
2022
"github.com/fluxcd/pkg/apis/meta"
2123
"github.com/fluxcd/pkg/runtime/conditions"
2224
apimeta "k8s.io/apimachinery/pkg/api/meta"
@@ -162,7 +164,13 @@ func (in *Bucket) SetConditions(conditions []metav1.Condition) {
162164
in.Status.Conditions = conditions
163165
}
164166

167+
// GetRequeueAfter returns the duration after which the source must be reconciled again.
168+
func (in Bucket) GetRequeueAfter() time.Duration {
169+
return in.Spec.Interval.Duration
170+
}
171+
165172
// GetInterval returns the interval at which the source is reconciled.
173+
// Deprecated: use GetRequeueAfter instead.
166174
func (in Bucket) GetInterval() metav1.Duration {
167175
return in.Spec.Interval
168176
}

api/v1beta1/gitrepository_types.go

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

1919
import (
20+
"time"
21+
2022
"github.com/fluxcd/pkg/apis/meta"
2123
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2224
)
@@ -211,7 +213,13 @@ func (in *GitRepository) SetConditions(conditions []metav1.Condition) {
211213
in.Status.Conditions = conditions
212214
}
213215

216+
// GetRequeueAfter returns the duration after which the source must be reconciled again.
217+
func (in GitRepository) GetRequeueAfter() time.Duration {
218+
return in.Spec.Interval.Duration
219+
}
220+
214221
// GetInterval returns the interval at which the source is reconciled.
222+
// Deprecated: use GetRequeueAfter instead.
215223
func (in GitRepository) GetInterval() metav1.Duration {
216224
return in.Spec.Interval
217225
}

api/v1beta1/helmchart_types.go

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

1919
import (
20+
"time"
21+
2022
"github.com/fluxcd/pkg/apis/meta"
2123
"github.com/fluxcd/pkg/runtime/conditions"
2224
apimeta "k8s.io/apimachinery/pkg/api/meta"
@@ -173,7 +175,13 @@ func (in *HelmChart) SetConditions(conditions []metav1.Condition) {
173175
in.Status.Conditions = conditions
174176
}
175177

178+
// GetRequeueAfter returns the duration after which the source must be reconciled again.
179+
func (in HelmChart) GetRequeueAfter() time.Duration {
180+
return in.Spec.Interval.Duration
181+
}
182+
176183
// GetInterval returns the interval at which the source is reconciled.
184+
// Deprecated: use GetRequeueAfter instead.
177185
func (in HelmChart) GetInterval() metav1.Duration {
178186
return in.Spec.Interval
179187
}

api/v1beta1/helmrepository_types.go

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

1919
import (
20+
"time"
21+
2022
"github.com/fluxcd/pkg/apis/meta"
2123
"github.com/fluxcd/pkg/runtime/conditions"
2224
apimeta "k8s.io/apimachinery/pkg/api/meta"
@@ -151,7 +153,13 @@ func (in *HelmRepository) SetConditions(conditions []metav1.Condition) {
151153
in.Status.Conditions = conditions
152154
}
153155

156+
// GetRequeueAfter returns the duration after which the source must be reconciled again.
157+
func (in HelmRepository) GetRequeueAfter() time.Duration {
158+
return in.Spec.Interval.Duration
159+
}
160+
154161
// GetInterval returns the interval at which the source is reconciled.
162+
// Deprecated: use GetRequeueAfter instead.
155163
func (in HelmRepository) GetInterval() metav1.Duration {
156164
return in.Spec.Interval
157165
}

api/v1beta1/source.go

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

1919
import (
20+
"time"
21+
2022
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2123
)
2224

@@ -29,9 +31,12 @@ const (
2931
// Source interface must be supported by all API types.
3032
// +k8s:deepcopy-gen=false
3133
type Source interface {
34+
// GetRequeueAfter returns the duration after which the source must be reconciled again.
35+
GetRequeueAfter() time.Duration
3236
// GetArtifact returns the latest artifact from the source if present in the
3337
// status sub-resource.
3438
GetArtifact() *Artifact
3539
// GetInterval returns the interval at which the source is updated.
40+
// Deprecated: use GetRequeueAfter instead.
3641
GetInterval() metav1.Duration
3742
}

controllers/bucket_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,10 @@ func (r *BucketReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
169169

170170
log.Info(fmt.Sprintf("Reconciliation finished in %s, next run in %s",
171171
time.Now().Sub(start).String(),
172-
bucket.GetInterval().Duration.String(),
172+
bucket.GetRequeueAfter().String(),
173173
))
174174

175-
return ctrl.Result{RequeueAfter: bucket.GetInterval().Duration}, nil
175+
return ctrl.Result{RequeueAfter: bucket.GetRequeueAfter()}, nil
176176
}
177177

178178
func (r *BucketReconciler) reconcile(ctx context.Context, bucket sourcev1.Bucket) (sourcev1.Bucket, error) {

controllers/gitrepository_controller.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func (r *GitRepositoryReconciler) reconcile(ctx context.Context, obj *sourcev1.G
217217
// Reconcile the source from upstream
218218
var artifact sourcev1.Artifact
219219
if result, err := r.reconcileSource(ctx, obj, &artifact, tmpDir); err != nil || result.IsZero() {
220-
return ctrl.Result{RequeueAfter: obj.Spec.Interval.Duration}, err
220+
return ctrl.Result{RequeueAfter: obj.GetRequeueAfter()}, err
221221
}
222222

223223
// Reconcile includes from the storage
@@ -231,7 +231,7 @@ func (r *GitRepositoryReconciler) reconcile(ctx context.Context, obj *sourcev1.G
231231
return result, err
232232
}
233233

234-
return ctrl.Result{RequeueAfter: obj.Spec.Interval.Duration}, nil
234+
return ctrl.Result{RequeueAfter: obj.GetRequeueAfter()}, nil
235235
}
236236

237237
// reconcileStorage ensures the current state of the storage matches the desired and previously observed state.
@@ -264,7 +264,7 @@ func (r *GitRepositoryReconciler) reconcileStorage(ctx context.Context, obj *sou
264264
r.Storage.SetArtifactURL(obj.GetArtifact())
265265
obj.Status.URL = r.Storage.SetHostname(obj.Status.URL)
266266

267-
return ctrl.Result{RequeueAfter: obj.Spec.Interval.Duration}, nil
267+
return ctrl.Result{RequeueAfter: obj.GetRequeueAfter()}, nil
268268
}
269269

270270
// reconcileSource ensures the upstream Git repository can be reached and checked out using the declared configuration,
@@ -364,7 +364,7 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
364364
if !obj.GetArtifact().HasRevision(revision) {
365365
conditions.MarkTrue(obj, sourcev1.ArtifactOutdatedCondition, "NewRevision", "New upstream revision '%s'", revision)
366366
}
367-
return ctrl.Result{RequeueAfter: obj.Spec.Interval.Duration}, nil
367+
return ctrl.Result{RequeueAfter: obj.GetRequeueAfter()}, nil
368368
}
369369

370370
// reconcileArtifact archives a new artifact to the storage, if the current observation on the object does not match the
@@ -394,7 +394,7 @@ func (r *GitRepositoryReconciler) reconcileArtifact(ctx context.Context, obj *so
394394
// The artifact is up-to-date
395395
if obj.GetArtifact().HasRevision(artifact.Revision) && !includes.Diff(obj.Status.IncludedArtifacts) {
396396
ctrl.LoggerFrom(ctx).Info("Artifact is up-to-date")
397-
return ctrl.Result{RequeueAfter: obj.GetInterval().Duration}, nil
397+
return ctrl.Result{RequeueAfter: obj.GetRequeueAfter()}, nil
398398
}
399399

400400
// Ensure target path exists and is a directory
@@ -453,7 +453,7 @@ func (r *GitRepositoryReconciler) reconcileArtifact(ctx context.Context, obj *so
453453
if url != "" {
454454
obj.Status.URL = url
455455
}
456-
return ctrl.Result{RequeueAfter: obj.Spec.Interval.Duration}, nil
456+
return ctrl.Result{RequeueAfter: obj.GetRequeueAfter()}, nil
457457
}
458458

459459
// reconcileInclude reconciles the declared includes from the object by copying their artifact (sub)contents to the
@@ -508,7 +508,7 @@ func (r *GitRepositoryReconciler) reconcileInclude(ctx context.Context, obj *sou
508508
if artifacts.Diff(obj.Status.IncludedArtifacts) {
509509
conditions.MarkTrue(obj, sourcev1.ArtifactOutdatedCondition, "IncludeChange", "Included artifacts differ from last observed includes")
510510
}
511-
return ctrl.Result{RequeueAfter: obj.Spec.Interval.Duration}, nil
511+
return ctrl.Result{RequeueAfter: obj.GetRequeueAfter()}, nil
512512
}
513513

514514
// reconcileDelete handles the delete of an object. It first garbage collects all artifacts for the object from the
@@ -532,7 +532,7 @@ func (r *GitRepositoryReconciler) verifyCommitSignature(ctx context.Context, obj
532532
// Check if there is a commit verification is configured and remove any old observations if there is none
533533
if obj.Spec.Verification == nil || obj.Spec.Verification.Mode == "" {
534534
conditions.Delete(obj, sourcev1.SourceVerifiedCondition)
535-
return ctrl.Result{RequeueAfter: obj.Spec.Interval.Duration}, nil
535+
return ctrl.Result{RequeueAfter: obj.GetRequeueAfter()}, nil
536536
}
537537

538538
// Get secret with GPG data
@@ -557,7 +557,7 @@ func (r *GitRepositoryReconciler) verifyCommitSignature(ctx context.Context, obj
557557

558558
conditions.MarkTrue(obj, sourcev1.SourceVerifiedCondition, meta.SucceededReason, "Verified signature of commit '%s'", commit.Hash())
559559
r.Eventf(ctx, obj, events.EventSeverityInfo, "VerifiedCommit", "Verified signature of commit '%s'", commit.Hash())
560-
return ctrl.Result{RequeueAfter: obj.Spec.Interval.Duration}, nil
560+
return ctrl.Result{RequeueAfter: obj.GetRequeueAfter()}, nil
561561
}
562562

563563
// garbageCollect performs a garbage collection for the given v1beta1.GitRepository. It removes all but the current

controllers/helmchart_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,9 @@ func (r *HelmChartReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
252252

253253
log.Info(fmt.Sprintf("Reconciliation finished in %s, next run in %s",
254254
time.Now().Sub(start).String(),
255-
chart.GetInterval().Duration.String(),
255+
chart.GetRequeueAfter().String(),
256256
))
257-
return ctrl.Result{RequeueAfter: chart.GetInterval().Duration}, nil
257+
return ctrl.Result{RequeueAfter: chart.GetRequeueAfter()}, nil
258258
}
259259

260260
type HelmChartReconcilerOptions struct {

controllers/helmrepository_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ func (r *HelmRepositoryReconciler) Reconcile(ctx context.Context, req ctrl.Reque
164164

165165
log.Info(fmt.Sprintf("Reconciliation finished in %s, next run in %s",
166166
time.Now().Sub(start).String(),
167-
repository.GetInterval().Duration.String(),
167+
repository.GetRequeueAfter().String(),
168168
))
169169

170-
return ctrl.Result{RequeueAfter: repository.GetInterval().Duration}, nil
170+
return ctrl.Result{RequeueAfter: repository.GetRequeueAfter()}, nil
171171
}
172172

173173
func (r *HelmRepositoryReconciler) reconcile(ctx context.Context, repository sourcev1.HelmRepository) (sourcev1.HelmRepository, error) {

0 commit comments

Comments
 (0)