Skip to content

refactor(controller): move MBC provision logic to domain/usecase/infra layers#277

Merged
satoru-takeuchi merged 1 commit into
mainfrom
implement-new-mbc-controller
May 28, 2026
Merged

refactor(controller): move MBC provision logic to domain/usecase/infra layers#277
satoru-takeuchi merged 1 commit into
mainfrom
implement-new-mbc-controller

Conversation

@ushitora-anqou

@ushitora-anqou ushitora-anqou commented May 8, 2026

Copy link
Copy Markdown
Contributor

Move the MantleBackupConfig provision logic (PVC cluster ID lookup, finalizer/annotation setup, metrics export, CronJob create-or-update) from the controller package into the domain/usecase/infra layers, following the same architecture established in PRs #250 and #252.

Remove the ErrNotImplemented fallback pattern and the duplicated createOrUpdateCronJob/getMBCCronJobName from the controller.

Add unit tests for domain.Provision and integration tests for the provision path in the usecase layer.

@ushitora-anqou ushitora-anqou force-pushed the implement-new-mbc-controller branch 2 times, most recently from 22be1d7 to 29b58dc Compare May 11, 2026 09:05
@ushitora-anqou ushitora-anqou requested a review from Copilot May 21, 2026 08:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the MantleBackupConfig (MBC) “provision” reconciliation path to follow the domain/usecase/infra architecture introduced in #250 and #252, moving controller-owned provisioning logic (PVC/StorageClass cluster-ID responsibility check, finalizer/annotation handling, metrics export, and CronJob create-or-update) out of the controller layer.

Changes:

  • Implement domain.MBCPrimaryReconciler.Provision(...) and represent CronJob create/update as a reconciler operation dispatched by the infra Kubernetes client.
  • Update the primary MBC usecase to orchestrate provision/finalize, including PVC → StorageClass resolution and operation application.
  • Add/expand unit tests for the domain provision logic and envtest-based integration tests for the usecase provision lifecycle; make test unique-name generation concurrency-safe.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/util/util.go Makes GetUniqueName safe under parallel test execution by using sync.Map.
internal/controller/usecase/reconcile_mbc_primary.go Moves provision orchestration into the usecase (PVC/SC lookup, calling domain provision, applying operations).
internal/controller/usecase/reconcile_mbc_primary_test.go Adds integration tests for full provision lifecycle, cronjob updates, and “not responsible” cases.
internal/controller/mantlebackupconfig_controller.go Removes controller-side provisioning fallback and wires the expanded usecase constructor args.
internal/controller/infra/kubernetes_client.go Adds infra handling for a new “create or update MBC CronJob” domain operation.
internal/controller/domain/mbc_primary_reconciler.go Implements domain-level provision logic and introduces CreateOrUpdateMBCCronJobOperation.
internal/controller/domain/mbc_primary_reconciler_test.go Adds unit tests covering responsibility filtering, finalizer/annotation setup, cronjob op creation, and schedule override.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/controller/mantlebackupconfig_controller.go Outdated
@ushitora-anqou ushitora-anqou marked this pull request as ready for review May 21, 2026 08:11
@ushitora-anqou ushitora-anqou requested a review from a team as a code owner May 21, 2026 08:11
// - 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) {
logger := log.FromContext(ctx)
_ = log.FromContext(ctx)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this line since we doesn't use the return value.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

…a layers

Move the MantleBackupConfig provision logic (PVC cluster ID lookup,
finalizer/annotation setup, metrics export, CronJob create-or-update)
from the controller package into the domain/usecase/infra layers,
following the same architecture established in PRs #250 and #252.

Remove the ErrNotImplemented fallback pattern and the duplicated
createOrUpdateCronJob/getMBCCronJobName from the controller.

Add unit tests for domain.Provision and integration tests for the
provision path in the usecase layer.
@ushitora-anqou ushitora-anqou force-pushed the implement-new-mbc-controller branch from 29b58dc to 3b40e66 Compare May 27, 2026 08:18
@satoru-takeuchi satoru-takeuchi merged commit 8cb91fe into main May 28, 2026
15 checks passed
@satoru-takeuchi satoru-takeuchi deleted the implement-new-mbc-controller branch May 28, 2026 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants