Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions pkg/cluster-handler/controller/multigrescluster/constants.go

This file was deleted.

28 changes: 28 additions & 0 deletions pkg/cluster-handler/controller/multigrescluster/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Package multigrescluster implements the controller for the root MultigresCluster resource.
//
// The MultigresCluster controller acts as the central orchestrator for the database system.
// It is responsible for translating the high-level user intent into specific child resources.
// Its primary responsibilities include:
//
// 1. Global Component Management:
// It directly manages singleton resources defined at the cluster level, such as the
// Global TopoServer (via a child TopoServer CR) and the MultiAdmin deployment.
//
// 2. Resource Fan-Out (Child CR Management):
// It projects the configuration defined in the MultigresCluster spec (Cells and Databases)
// into discrete child Custom Resources (Cell and TableGroup). These child resources are
// then reconciled by their own respective controllers.
//
// 3. Template Resolution:
// It leverages the 'pkg/resolver' module to fetch CoreTemplates, CellTemplates, and
// ShardTemplates, merging them with user-defined overrides to produce the final
// specifications for child resources.
//
// 4. Status Aggregation:
// It continually observes the status of its child resources to produce a high-level
// summary of the cluster's health (e.g., "All cells ready", "Database X has Y/Z shards ready").
//
// 5. Lifecycle Management:
// It utilizes finalizers to ensure that all child resources are gracefully terminated
// and cleaned up before the parent MultigresCluster is removed.
package multigrescluster
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

multigresv1alpha1 "github.com/numtide/multigres-operator/api/v1alpha1"
"github.com/numtide/multigres-operator/pkg/cluster-handler/controller/multigrescluster"
"github.com/numtide/multigres-operator/pkg/resolver"
"github.com/numtide/multigres-operator/pkg/testutil"
)

Expand Down Expand Up @@ -124,8 +125,10 @@ func TestMultigresClusterReconciliation(t *testing.T) {
},
Spec: multigresv1alpha1.TopoServerSpec{
Etcd: &multigresv1alpha1.EtcdSpec{
Image: "etcd:latest",
Replicas: ptr.To(int32(3)), // Default from logic
Image: "etcd:latest",
Replicas: ptr.To(int32(3)), // Default from logic
Storage: multigresv1alpha1.StorageSpec{Size: resolver.DefaultEtcdStorageSize},
Resources: resolver.DefaultResourcesEtcd(),
},
},
},
Expand All @@ -149,8 +152,9 @@ func TestMultigresClusterReconciliation(t *testing.T) {
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "multiadmin",
Image: "admin:latest",
Name: "multiadmin",
Image: "admin:latest",
Resources: resolver.DefaultResourcesAdmin(),
},
},
},
Expand Down Expand Up @@ -278,18 +282,45 @@ func TestMultigresClusterReconciliation(t *testing.T) {
t.Fatalf("Failed to create controller, %v", err)
}

// 4. Create the Input
// 4. Create Defaults (Templates)
// The controller expects "default" templates to exist when TemplateDefaults are not specified.
// We create empty templates so the resolution succeeds and falls back to hardcoded defaults or inline specs.
emptyCore := &multigresv1alpha1.CoreTemplate{
ObjectMeta: metav1.ObjectMeta{Name: "default", Namespace: namespace},
Spec: multigresv1alpha1.CoreTemplateSpec{},
}
if err := k8sClient.Create(ctx, emptyCore); client.IgnoreAlreadyExists(err) != nil {
t.Fatalf("Failed to create default core template: %v", err)
}

emptyCell := &multigresv1alpha1.CellTemplate{
ObjectMeta: metav1.ObjectMeta{Name: "default", Namespace: namespace},
Spec: multigresv1alpha1.CellTemplateSpec{},
}
if err := k8sClient.Create(ctx, emptyCell); client.IgnoreAlreadyExists(err) != nil {
t.Fatalf("Failed to create default cell template: %v", err)
}

emptyShard := &multigresv1alpha1.ShardTemplate{
ObjectMeta: metav1.ObjectMeta{Name: "default", Namespace: namespace},
Spec: multigresv1alpha1.ShardTemplateSpec{},
}
if err := k8sClient.Create(ctx, emptyShard); client.IgnoreAlreadyExists(err) != nil {
t.Fatalf("Failed to create default shard template: %v", err)
}

// 5. Create the Input
if err := k8sClient.Create(ctx, tc.cluster); err != nil {
t.Fatalf("Failed to create the initial cluster, %v", err)
}

// 5. Assert Logic: Wait for Children
// 6. Assert Logic: Wait for Children
// This ensures the controller has run and reconciled at least once successfully
if err := watcher.WaitForMatch(tc.wantResources...); err != nil {
t.Errorf("Resources mismatch:\n%v", err)
}

// 6. Verify Parent Finalizer (Manual Check)
// 7. Verify Parent Finalizer (Manual Check)
// We check this manually to avoid fighting with status/spec diffs in the watcher
fetchedCluster := &multigresv1alpha1.MultigresCluster{}
if err := k8sClient.Get(ctx, client.ObjectKeyFromObject(tc.cluster), fetchedCluster); err != nil {
Expand Down
Loading