Skip to content

Commit

Permalink
Merge pull request #36 from cybozu-go/kaizen/skip-mbc-reconciliation-…
Browse files Browse the repository at this point in the history
…if-secondary

skip reconciliation if role is secondary
  • Loading branch information
satoru-takeuchi authored Sep 3, 2024
2 parents 08d413d + 05a70f7 commit a18b772
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,14 @@ func setupReconcilers(mgr manager.Manager, primarySettings *controller.PrimarySe
setupLog.Error(err, "unable to create controller", "controller", "MantleRestore")
return err
}

if err := controller.NewMantleBackupConfigReconciler(
mgr.GetClient(),
mgr.GetScheme(),
managedCephClusterID,
expireOffset,
overwriteMBCSchedule,
role,
).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "MantleBackupConfig")
return err
Expand Down
16 changes: 14 additions & 2 deletions internal/controller/mantlebackupconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,18 @@ type MantleBackupConfigReconciler struct {
managedCephClusterID string
expireOffset string
overwriteMBCSchedule string
role string
}

func NewMantleBackupConfigReconciler(cli client.Client, scheme *runtime.Scheme, managedCephClusterID string, expireOffset string, overwriteMBCSchedule string) *MantleBackupConfigReconciler {
return &MantleBackupConfigReconciler{cli, scheme, managedCephClusterID, expireOffset, overwriteMBCSchedule}
func NewMantleBackupConfigReconciler(
cli client.Client,
scheme *runtime.Scheme,
managedCephClusterID string,
expireOffset string,
overwriteMBCSchedule string,
role string,
) *MantleBackupConfigReconciler {
return &MantleBackupConfigReconciler{cli, scheme, managedCephClusterID, expireOffset, overwriteMBCSchedule, role}
}

//+kubebuilder:rbac:groups=mantle.cybozu.io,resources=mantlebackupconfigs,verbs=get;list;watch;create;update;patch;delete
Expand All @@ -56,6 +64,10 @@ func NewMantleBackupConfigReconciler(cli client.Client, scheme *runtime.Scheme,
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.16.3/pkg/reconcile
func (r *MantleBackupConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
if r.role == RoleSecondary {
return ctrl.Result{}, nil
}

// Get the CronJob info to be created or updated
cronJobInfo, err := getCronJobInfo(ctx, r.Client)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/mantlebackupconfig_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ var _ = Describe("MantleBackupConfig controller", func() {
})
Expect(err).ToNot(HaveOccurred())

reconciler = NewMantleBackupConfigReconciler(k8sClient, mgr.GetScheme(), storageClassClusterID, "0s", "")
reconciler = NewMantleBackupConfigReconciler(k8sClient, mgr.GetScheme(), storageClassClusterID, "0s", "", RoleStandalone)
err = reconciler.SetupWithManager(mgr)
Expect(err).NotTo(HaveOccurred())

Expand Down

0 comments on commit a18b772

Please sign in to comment.