Skip to content

Commit cde0544

Browse files
Merge pull request #112 from numtide/fix/controller-deletion-and-refactor
refactor(multigrescluster): split controller, fix deletion, and update API Refactors the MultigresCluster controller for better maintainability and fixes critical issues with deletion and default resolution. Key Changes: - **Controller Refactor:** Split the monolithic `MultigresCluster` controller into logical files (`reconcile_global.go`, `reconcile_cells.go`, `reconcile_databases.go`, `status.go`). - **Active Deletion:** Implemented "Active Deletion" logic in `checkChildrenDeleted`. The controller now explicitly deletes child resources (`Cells`, `TableGroups`) instead of relying solely on Garbage Collection. This fixes hanging tests in `envtest` environments. - **Smart Defaulting Fix:** Updated `PopulateClusterDefaults` in the Resolver to propagate the Cluster's `Cells` to the default Shard's `MultiOrch` spec. This resolves the "MultiOrch has no cells" error in minimal configurations. - **API Update:** Changed `GlobalTopoServer` and `MultiAdmin` fields in `MultigresClusterSpec` to pointers. This allows proper detection of "missing" vs "empty" fields for lazy configuration. - **Tests:** Split unit and integration tests into focused files matching the controller structure. Updated test expectations to align with the new active deletion error messages and default injection logic. - **Build:** Updated `Makefile` to use `kubectl apply --server-side` for installing CRDs to avoid size limit issues.
2 parents e2b8632 + 419b2d4 commit cde0544

26 files changed

+2746
-1417
lines changed

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ endif
378378

379379
.PHONY: install
380380
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
381-
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
381+
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply --server-side -f -
382382

383383
.PHONY: uninstall
384384
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
@@ -387,7 +387,7 @@ uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified
387387
.PHONY: deploy
388388
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
389389
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
390-
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -
390+
$(KUSTOMIZE) build config/default | $(KUBECTL) apply --server-side -f -
391391

392392
.PHONY: undeploy
393393
undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
@@ -420,12 +420,12 @@ kind-load: container ## Build and load image into kind cluster
420420
.PHONY: kind-deploy
421421
kind-deploy: kind-up manifests kustomize kind-load ## Deploy operator to kind cluster
422422
@echo "==> Installing CRDs..."
423-
KUBECONFIG=$(KIND_KUBECONFIG) $(KUSTOMIZE) build config/crd | KUBECONFIG=$(KIND_KUBECONFIG) $(KUBECTL) apply -f -
423+
KUBECONFIG=$(KIND_KUBECONFIG) $(KUSTOMIZE) build config/crd | KUBECONFIG=$(KIND_KUBECONFIG) $(KUBECTL) apply --server-side -f -
424424
@echo "==> Deploying operator..."
425425
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
426-
KUBECONFIG=$(KIND_KUBECONFIG) $(KUSTOMIZE) build config/default | KUBECONFIG=$(KIND_KUBECONFIG) $(KUBECTL) apply -f -
426+
KUBECONFIG=$(KIND_KUBECONFIG) $(KUSTOMIZE) build config/default | KUBECONFIG=$(KIND_KUBECONFIG) $(KUBECTL) apply --server-side -f -
427427
@echo "==> Deployment complete!"
428-
@echo "Check status: KUBECONFIG=$(KIND_KUBECONFIG) kubectl get pods -n multigres-operator-system"
428+
@echo "Check status: KUBECONFIG=$(KIND_KUBECONFIG) kubectl get pods -n multigres-operator"
429429

430430
.PHONY: kind-redeploy
431431
kind-redeploy: kind-load ## Rebuild image, reload to kind, and restart pods

api/v1alpha1/multigrescluster_types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ type MultigresClusterSpec struct {
5454

5555
// GlobalTopoServer defines the cluster-wide global topology server.
5656
// +optional
57-
GlobalTopoServer GlobalTopoServerSpec `json:"globalTopoServer,omitempty"`
57+
GlobalTopoServer *GlobalTopoServerSpec `json:"globalTopoServer,omitempty"`
5858

5959
// MultiAdmin defines the configuration for the MultiAdmin component.
6060
// +optional
61-
MultiAdmin MultiAdminConfig `json:"multiadmin,omitempty"`
61+
MultiAdmin *MultiAdminConfig `json:"multiadmin,omitempty"`
6262

6363
// Cells defines the list of cells (failure domains) in the cluster.
6464
// +optional
@@ -239,7 +239,7 @@ type DatabaseConfig struct {
239239
}
240240

241241
// TableGroupConfig defines a table group within a database.
242-
// +kubebuilder:validation:XValidation:rule="!self.default || self.name == 'default'",message="the default tablegroup must be named 'default'"
242+
// +kubebuilder:validation:XValidation:rule="!has(self.default) || !self.default || self.name == 'default'",message="the default tablegroup must be named 'default'"
243243
type TableGroupConfig struct {
244244
// Name is the logical name of the table group.
245245
// +kubebuilder:validation:MinLength=1

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 10 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/multigres.com_multigresclusters.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6866,7 +6866,8 @@ spec:
68666866
type: object
68676867
x-kubernetes-validations:
68686868
- message: the default tablegroup must be named 'default'
6869-
rule: '!self.default || self.name == ''default'''
6869+
rule: '!has(self.default) || !self.default || self.name
6870+
== ''default'''
68706871
maxItems: 20
68716872
type: array
68726873
x-kubernetes-list-map-keys:

config/manager/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ kind: Kustomization
55
images:
66
- name: controller
77
newName: ghcr.io/numtide/multigres-operator
8-
newTag: 9d6dd13-dirty
8+
newTag: e2b8632-dirty

0 commit comments

Comments
 (0)