diff --git a/cmd/provider/main.go b/cmd/provider/main.go index 8f6e2c94..d16b828a 100644 --- a/cmd/provider/main.go +++ b/cmd/provider/main.go @@ -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() @@ -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), diff --git a/internal/controller/providerconfig/backendmonitor/backendmonitor.go b/internal/controller/providerconfig/backendmonitor/backendmonitor.go index 0671292d..aeaf93cf 100644 --- a/internal/controller/providerconfig/backendmonitor/backendmonitor.go +++ b/internal/controller/providerconfig/backendmonitor/backendmonitor.go @@ -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 { @@ -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{}). diff --git a/internal/controller/providerconfig/backendmonitor/backendmonitor_controller.go b/internal/controller/providerconfig/backendmonitor/backendmonitor_controller.go index 03bccb74..d059595b 100644 --- a/internal/controller/providerconfig/backendmonitor/backendmonitor_controller.go +++ b/internal/controller/providerconfig/backendmonitor/backendmonitor_controller.go @@ -53,6 +53,7 @@ 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) @@ -60,15 +61,17 @@ func (c *Controller) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu 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 {