Skip to content

refactor(cluster-handler): implement Server-Side Apply for all controllers#123

Merged
fernando-villalba merged 1 commit intomainfrom
ssa-cluster-handler
Jan 17, 2026
Merged

refactor(cluster-handler): implement Server-Side Apply for all controllers#123
fernando-villalba merged 1 commit intomainfrom
ssa-cluster-handler

Conversation

@fernando-villalba
Copy link
Collaborator

Refactors MultigresCluster and TableGroup controllers to use Server-Side Apply (SSA) for resource management, replacing the legacy Get/Create/Update pattern.

Changes:

  • Replaced client.Create/Update calls with client.Patch(..., client.Apply) in reconcile_global, reconcile_cells, reconcile_databases, and tablegroup_controller.
  • Standardized FieldOwner to "multigres-operator" for clear ownership.
  • Removed unnecessary Get checks and "IsNew" logic, simplifying the reconciliation loop.
  • Standardized eventing to emit "Applied" for all successful operations, removing ambiguous "Created"/"Updated" distinction.
  • Added safety check for EventRecorder in tablegroup_controller to prevent panics in test environments.
  • Updated unit and integration tests to reflect SSA behavior and removed obsolete test cases (e.g., Get failures).

Benefits:

  • Atomicity: Reduces race conditions by handling creation and updates in a single atomic operation.
  • Efficiency: Reduces API server round-trips by removing read-before-write checks.
  • Robustness: Simplifies error handling and conflict resolution.
  • 100% Test Coverage maintained across the module.

…llers

Refactors `MultigresCluster` and TableGroup controllers to use Server-Side Apply (SSA) for resource management, replacing the legacy Get/Create/Update pattern.

Changes:
- Replaced client.Create/Update calls with `client.Patch(..., client.Apply)` in `reconcile_global`, `reconcile_cells`, `reconcile_databases`, and `tablegroup_controller`.
- Standardized FieldOwner to "multigres-operator" for clear ownership.
- Removed unnecessary `Get` checks and "IsNew" logic, simplifying the reconciliation loop.
- Standardized eventing to emit "Applied" for all successful operations, removing ambiguous "Created"/"Updated" distinction.
- Added safety check for `EventRecorder` in `tablegroup_controller` to prevent panics in test environments.
- Updated unit and integration tests to reflect SSA behavior and removed obsolete test cases (e.g., Get failures).

Benefits:
- Atomicity: Reduces race conditions by handling creation and updates in a single atomic operation.
- Efficiency: Reduces API server round-trips by removing read-before-write checks.
- Robustness: Simplifies error handling and conflict resolution.
- 100% Test Coverage maintained across the module.
Base automatically changed from pure-resource-builders-ch to main January 17, 2026 10:33
@github-actions
Copy link

🔬 Go Test Coverage Report

Summary

Coverage Type Result
Threshold 0%
Previous Test Coverage 0.0%
New Test Coverage 100.0%

Status

✅ PASS

Detail

Show New Coverage
github.com/numtide/multigres-operator/pkg/cluster-handler/controller/multigrescluster/builders_cell.go:14:			BuildCell			100.0%
github.com/numtide/multigres-operator/pkg/cluster-handler/controller/multigrescluster/builders_global.go:17:			BuildGlobalTopoServer		100.0%
github.com/numtide/multigres-operator/pkg/cluster-handler/controller/multigrescluster/builders_global.go:57:			BuildMultiAdminDeployment	100.0%
github.com/numtide/multigres-operator/pkg/cluster-handler/controller/multigrescluster/builders_tablegroup.go:14:		BuildTableGroup			100.0%
github.com/numtide/multigres-operator/pkg/cluster-handler/controller/multigrescluster/multigrescluster_controller.go:42:	Reconcile			100.0%
github.com/numtide/multigres-operator/pkg/cluster-handler/controller/multigrescluster/multigrescluster_controller.go:100:	handleDelete			100.0%
github.com/numtide/multigres-operator/pkg/cluster-handler/controller/multigrescluster/multigrescluster_controller.go:123:	checkChildrenDeleted		100.0%
github.com/numtide/multigres-operator/pkg/cluster-handler/controller/multigrescluster/multigrescluster_controller.go:195:	SetupWithManager		100.0%
github.com/numtide/multigres-operator/pkg/cluster-handler/controller/multigrescluster/reconcile_cells.go:13:			reconcileCells			100.0%
github.com/numtide/multigres-operator/pkg/cluster-handler/controller/multigrescluster/reconcile_databases.go:14:		reconcileDatabases		100.0%
github.com/numtide/multigres-operator/pkg/cluster-handler/controller/multigrescluster/reconcile_global.go:14:			reconcileGlobalComponents	100.0%
github.com/numtide/multigres-operator/pkg/cluster-handler/controller/multigrescluster/reconcile_global.go:29:			reconcileGlobalTopoServer	100.0%
github.com/numtide/multigres-operator/pkg/cluster-handler/controller/multigrescluster/reconcile_global.go:74:			reconcileMultiAdmin		100.0%
github.com/numtide/multigres-operator/pkg/cluster-handler/controller/multigrescluster/reconcile_global.go:114:			getGlobalTopoRef		100.0%
github.com/numtide/multigres-operator/pkg/cluster-handler/controller/multigrescluster/status.go:14:				updateStatus			100.0%
github.com/numtide/multigres-operator/pkg/cluster-handler/controller/tablegroup/builders.go:14:					BuildShard			100.0%
github.com/numtide/multigres-operator/pkg/cluster-handler/controller/tablegroup/tablegroup_controller.go:39:			Reconcile			100.0%
github.com/numtide/multigres-operator/pkg/cluster-handler/controller/tablegroup/tablegroup_controller.go:169:			handleDelete			100.0%
github.com/numtide/multigres-operator/pkg/cluster-handler/controller/tablegroup/tablegroup_controller.go:222:			SetupWithManager		100.0%
github.com/numtide/multigres-operator/pkg/webhook/cert/generator.go:46:								GenerateCA			100.0%
github.com/numtide/multigres-operator/pkg/webhook/cert/generator.go:102:							GenerateServerCert		100.0%
github.com/numtide/multigres-operator/pkg/webhook/cert/generator.go:163:							ParseCA				100.0%
github.com/numtide/multigres-operator/pkg/webhook/cert/manager.go:54:								NewManager			100.0%
github.com/numtide/multigres-operator/pkg/webhook/cert/manager.go:63:								Bootstrap			100.0%
github.com/numtide/multigres-operator/pkg/webhook/cert/manager.go:74:								Start				100.0%
github.com/numtide/multigres-operator/pkg/webhook/cert/manager.go:101:								reconcilePKI			100.0%
github.com/numtide/multigres-operator/pkg/webhook/cert/manager.go:119:								ensureCA			100.0%
github.com/numtide/multigres-operator/pkg/webhook/cert/manager.go:177:								ensureServerCert		100.0%
github.com/numtide/multigres-operator/pkg/webhook/cert/manager.go:265:								waitForKubelet			100.0%
github.com/numtide/multigres-operator/pkg/webhook/cert/manager.go:293:								setOwner			100.0%
github.com/numtide/multigres-operator/pkg/webhook/cert/manager.go:308:								findOperatorDeployment		100.0%
github.com/numtide/multigres-operator/pkg/webhook/cert/manager.go:338:								patchWebhooks			100.0%
github.com/numtide/multigres-operator/pkg/webhook/cert/manager.go:374:								recorderEvent			100.0%
github.com/numtide/multigres-operator/pkg/webhook/handlers/defaulter.go:24:							NewMultigresClusterDefaulter	100.0%
github.com/numtide/multigres-operator/pkg/webhook/handlers/defaulter.go:31:							Default				100.0%
github.com/numtide/multigres-operator/pkg/webhook/handlers/validator.go:31:							NewMultigresClusterValidator	100.0%
github.com/numtide/multigres-operator/pkg/webhook/handlers/validator.go:35:							ValidateCreate			100.0%
github.com/numtide/multigres-operator/pkg/webhook/handlers/validator.go:42:							ValidateUpdate			100.0%
github.com/numtide/multigres-operator/pkg/webhook/handlers/validator.go:49:							ValidateDelete			100.0%
github.com/numtide/multigres-operator/pkg/webhook/handlers/validator.go:56:							validate			100.0%
github.com/numtide/multigres-operator/pkg/webhook/handlers/validator.go:73:							validateTemplatesExist		100.0%
github.com/numtide/multigres-operator/pkg/webhook/handlers/validator.go:134:							NewTemplateValidator		100.0%
github.com/numtide/multigres-operator/pkg/webhook/handlers/validator.go:138:							ValidateCreate			100.0%
github.com/numtide/multigres-operator/pkg/webhook/handlers/validator.go:145:							ValidateUpdate			100.0%
github.com/numtide/multigres-operator/pkg/webhook/handlers/validator.go:152:							ValidateDelete			100.0%
github.com/numtide/multigres-operator/pkg/webhook/handlers/validator.go:181:							isTemplateInUse			100.0%
github.com/numtide/multigres-operator/pkg/webhook/handlers/validator.go:235:							NewChildResourceValidator	100.0%
github.com/numtide/multigres-operator/pkg/webhook/handlers/validator.go:241:							ValidateCreate			100.0%
github.com/numtide/multigres-operator/pkg/webhook/handlers/validator.go:248:							ValidateUpdate			100.0%
github.com/numtide/multigres-operator/pkg/webhook/handlers/validator.go:255:							ValidateDelete			100.0%
github.com/numtide/multigres-operator/pkg/webhook/handlers/validator.go:262:							validate			100.0%
github.com/numtide/multigres-operator/pkg/webhook/setup.go:24:									Setup				100.0%
total:																(statements)			100.0%

@fernando-villalba fernando-villalba merged commit e385213 into main Jan 17, 2026
5 of 6 checks passed
@fernando-villalba fernando-villalba deleted the ssa-cluster-handler branch January 17, 2026 10:53
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.

1 participant