Skip to content

Commit

Permalink
Add flag for backend monitor controller requeue timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
cnolan committed Oct 14, 2024
1 parent cdea4ae commit 2da0431
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
2 changes: 2 additions & 0 deletions cmd/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func main() {

syncInterval = app.Flag("sync", "How often all resources will be double-checked for drift from the desired state.").Short('s').Default("1h").Duration()
syncTimeout = app.Flag("sync-timeout", "Cache sync timeout.").Default("10s").Duration()
backendMonitorInterval = app.Flag("backend-monitor-interval", "Interval between backend monitor controller reconciliations.").Default("60s").Duration()
pollInterval = app.Flag("poll", "How often individual resources will be checked for drift from the desired state").Short('p').Default("30m").Duration()
pollStateMetricInterval = app.Flag("poll-state-metric", "State metric recording interval").Default("5s").Duration()
bucketExistsCache = app.Flag("bucket-exists-cache", "How long the provider caches bucket exists result").Short('c').Default("5s").Duration()
Expand Down Expand Up @@ -320,6 +321,7 @@ func main() {
backendmonitor.WithKubeClient(mgr.GetClient()),
backendmonitor.WithBackendStore(backendStore),
backendmonitor.WithS3Timeout(*s3Timeout),
backendmonitor.WithRequeueInterval(*backendMonitorInterval),
backendmonitor.WithLogger(o.Logger)),
healthcheck.NewController(
healthcheck.WithAutoPause(autoPauseBucket),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import (
)

type Controller struct {
kubeClient client.Client
backendStore *backendstore.BackendStore
log logging.Logger
s3Timeout time.Duration
kubeClient client.Client
backendStore *backendstore.BackendStore
log logging.Logger
s3Timeout time.Duration
requeueInterval time.Duration
}

func NewController(options ...func(*Controller)) *Controller {
Expand Down Expand Up @@ -51,6 +52,12 @@ func WithS3Timeout(t time.Duration) func(*Controller) {
}
}

func WithRequeueInterval(t time.Duration) func(*Controller) {
return func(r *Controller) {
r.requeueInterval = t
}
}

func (c *Controller) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&apisv1alpha1.ProviderConfig{}).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,25 @@ func (c *Controller) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
c.backendStore.ToggleBackendActiveStatus(req.Name, false)
c.backendStore.SetBackendHealthStatus(req.Name, apisv1alpha1.HealthStatusUnknown)

// The ProviderConfig no longer exists so there is no need to requeue the reconcile key.
return ctrl.Result{}, nil
}
err = errors.Wrap(err, errGetProviderConfig)
traces.SetAndRecordError(span, err)

return ctrl.Result{}, err
}
// ProviderConfig has been created or updated, add or
// update its backend in the backend store.

if err := c.addOrUpdateBackend(ctx, providerConfig); err != nil {
traces.SetAndRecordError(span, err)

return ctrl.Result{}, err
}

return ctrl.Result{}, nil
// Requeue the reconcile key after the interval. We do this because we need to
// ensure that if a ProviderConfig's referenced Secret is updated, we also update
// the client in the backend store with the new credentials.
return ctrl.Result{RequeueAfter: c.requeueInterval}, nil
}

func (c *Controller) addOrUpdateBackend(ctx context.Context, pc *apisv1alpha1.ProviderConfig) error {
Expand Down

0 comments on commit 2da0431

Please sign in to comment.