Skip to content

Commit

Permalink
Optimize registration logic for snapshot compaction controller
Browse files Browse the repository at this point in the history
Refine the approach to registering snapshot compaction controller. Instead of always running the compaction-controller and checking the CLI flag `--enable-backup-compaction` just before deploying the compaction job, the updated logic registers the compaction-controller based on the CLI flag `--enable-backup-compaction`.
  • Loading branch information
seshachalam-yv committed Aug 29, 2023
1 parent 9a598d0 commit 234c2ee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
18 changes: 8 additions & 10 deletions controllers/compaction/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,15 @@ func (r *Reconciler) reconcileJob(ctx context.Context, logger logr.Logger, etcd
}, fmt.Errorf("error while fetching compaction job: %v", err)
}

if r.config.EnableBackupCompaction {
// Required job doesn't exist. Create new
logger.Info("Creating etcd compaction job", "namespace", etcd.Namespace, "name", etcd.GetCompactionJobName())
job, err = r.createCompactionJob(ctx, logger, etcd)
if err != nil {
return ctrl.Result{
RequeueAfter: 10 * time.Second,
}, fmt.Errorf("error during compaction job creation: %v", err)
}
metricJobsCurrent.With(prometheus.Labels{druidmetrics.EtcdNamespace: etcd.Namespace}).Set(1)
// Required job doesn't exist. Create new
logger.Info("Creating etcd compaction job", "namespace", etcd.Namespace, "name", etcd.GetCompactionJobName())
job, err = r.createCompactionJob(ctx, logger, etcd)
if err != nil {
return ctrl.Result{
RequeueAfter: 10 * time.Second,
}, fmt.Errorf("error during compaction job creation: %v", err)
}
metricJobsCurrent.With(prometheus.Labels{druidmetrics.EtcdNamespace: etcd.Namespace}).Set(1)
}

if !job.DeletionTimestamp.IsZero() {
Expand Down
16 changes: 9 additions & 7 deletions controllers/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,15 @@ func registerControllersWithManager(mgr ctrl.Manager, config *ManagerConfig) err
return err
}

// Add compaction reconciler to the manager
compactionReconciler, err := compaction.NewReconciler(mgr, config.CompactionControllerConfig)
if err != nil {
return err
}
if err = compactionReconciler.RegisterWithManager(mgr); err != nil {
return err
// Add compaction reconciler to the manager if the CLI flag enable-backup-compaction is true.
if config.CompactionControllerConfig.EnableBackupCompaction {
compactionReconciler, err := compaction.NewReconciler(mgr, config.CompactionControllerConfig)
if err != nil {
return err
}
if err = compactionReconciler.RegisterWithManager(mgr); err != nil {
return err
}
}

// Add etcd-copy-backups-task reconciler to the manager
Expand Down

0 comments on commit 234c2ee

Please sign in to comment.