-
Notifications
You must be signed in to change notification settings - Fork 1
fix: Weave-Clickhouse #325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
43550f7
f7261fc
33543da
99d8421
a808792
43b8856
1f68cb1
b66e3d6
fffe81c
bd054b6
9ea8b27
b226bda
8e3406d
080e91d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| package reconciler | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Use a Conventional Commit PR title.
As per coding guidelines, “PR titles and squash commits must use Conventional Commits with an allowed type, and the subject must start with an uppercase letter.” 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| apiv2 "github.com/wandb/operator/api/v2" | ||
| "github.com/wandb/operator/internal/controller/infra/managed/clickhouse/altinity" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| "k8s.io/client-go/tools/record" | ||
| "sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
| ) | ||
|
Comment on lines
+1
to
+13
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win Use the configured Ginkgo/Gomega test suite. This new file uses As per coding guidelines, “Use Ginkgo/Gomega for tests; test suites are configured through 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
|
|
||
| func replicationTestCR(replicas int32) *apiv2.WeightsAndBiases { | ||
| return &apiv2.WeightsAndBiases{ | ||
| TypeMeta: metav1.TypeMeta{APIVersion: apiv2.GroupVersion.String(), Kind: "WeightsAndBiases"}, | ||
| ObjectMeta: metav1.ObjectMeta{Name: "wandb", Namespace: "wandb"}, | ||
| Spec: apiv2.WeightsAndBiasesSpec{ | ||
| ClickHouse: map[string]apiv2.ClickHouseSpec{ | ||
| apiv2.DefaultInstanceName: { | ||
| ManagedClickHouse: &apiv2.ManagedClickHouseSpec{ | ||
| Name: "wandb-chi", | ||
| Namespace: "wandb", | ||
| Replicas: replicas, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| // inferManagedClickHouseStatus runs the managed status path and returns the | ||
| // published ClickHouse status for the default instance. | ||
| func inferManagedClickHouseStatus(t *testing.T, replicas int32) apiv2.ClickHouseInfraStatus { | ||
| t.Helper() | ||
|
|
||
| scheme := runtime.NewScheme() | ||
| if err := apiv2.AddToScheme(scheme); err != nil { | ||
| t.Fatalf("add apiv2 to scheme: %v", err) | ||
| } | ||
|
|
||
| wandb := replicationTestCR(replicas) | ||
| client := fake.NewClientBuilder(). | ||
| WithScheme(scheme). | ||
| WithObjects(wandb). | ||
| WithStatusSubresource(wandb). | ||
| Build() | ||
|
|
||
| wandb.Status.ClickHouseStatus = map[string]apiv2.ClickHouseInfraStatus{} | ||
| if _, err := managedClickHouseInferStatus( | ||
| context.Background(), client, record.NewFakeRecorder(10), | ||
| wandb, apiv2.DefaultInstanceName, nil, &apiv2.ClickHouseConnection{}, | ||
| ); err != nil { | ||
| t.Fatalf("managedClickHouseInferStatus: %v", err) | ||
| } | ||
| return wandb.Status.ClickHouseStatus[apiv2.DefaultInstanceName] | ||
| } | ||
|
|
||
| // Weave creates ReplicatedMergeTree tables only when told the cluster is | ||
| // replicated; without this the operator provisions replicas that never receive | ||
| // writes. | ||
| func TestManagedClickHouseStatusPublishesReplication(t *testing.T) { | ||
| for _, tc := range []struct { | ||
| name string | ||
| replicas int32 | ||
| replicated bool | ||
| }{ | ||
| {"single replica is not replicated", 1, false}, | ||
| {"two replicas are replicated", 2, true}, | ||
| {"three replicas are replicated", 3, true}, | ||
| } { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| status := inferManagedClickHouseStatus(t, tc.replicas) | ||
| if status.Replicated != tc.replicated { | ||
| t.Fatalf("expected Replicated=%t for %d replicas, got %t", | ||
| tc.replicated, tc.replicas, status.Replicated) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // The published name is used verbatim as `ON CLUSTER <name>`, so it has to be | ||
| // the cluster the CHI declares — not the Service-name derivation. | ||
| func TestManagedClickHouseStatusPublishesCHIClusterName(t *testing.T) { | ||
| status := inferManagedClickHouseStatus(t, 2) | ||
|
|
||
| if status.ClusterName != altinity.CHIClusterName() { | ||
| t.Fatalf("expected ClusterName=%q, got %q", altinity.CHIClusterName(), status.ClusterName) | ||
| } | ||
| if status.ClusterName == altinity.ClusterName("wandb-chi") { | ||
| t.Fatal("published the Service-name derivation instead of the CHI cluster name") | ||
| } | ||
| } | ||
|
|
||
| // External ClickHouse topology is unknown to the operator: the fields must stay | ||
| // zero so the server manifest's defaultValue applies. | ||
| func TestExternalClickHouseStatusLeavesReplicationUnset(t *testing.T) { | ||
| scheme := runtime.NewScheme() | ||
| if err := apiv2.AddToScheme(scheme); err != nil { | ||
| t.Fatalf("add apiv2 to scheme: %v", err) | ||
| } | ||
|
|
||
| wandb := &apiv2.WeightsAndBiases{ | ||
| TypeMeta: metav1.TypeMeta{APIVersion: apiv2.GroupVersion.String(), Kind: "WeightsAndBiases"}, | ||
| ObjectMeta: metav1.ObjectMeta{Name: "wandb", Namespace: "wandb"}, | ||
| Spec: apiv2.WeightsAndBiasesSpec{ | ||
| ClickHouse: map[string]apiv2.ClickHouseSpec{ | ||
| apiv2.DefaultInstanceName: {ExternalClickHouse: &apiv2.ClickHouseConnection{}}, | ||
| }, | ||
| }, | ||
| } | ||
| client := fake.NewClientBuilder(). | ||
| WithScheme(scheme). | ||
| WithObjects(wandb). | ||
| WithStatusSubresource(wandb). | ||
| Build() | ||
|
|
||
| wandb.Status.ClickHouseStatus = map[string]apiv2.ClickHouseInfraStatus{} | ||
| if _, err := externalClickHouseInferStatus( | ||
| context.Background(), client, wandb, apiv2.DefaultInstanceName, | ||
| nil, &apiv2.ClickHouseConnection{}, | ||
| ); err != nil { | ||
| t.Fatalf("externalClickHouseInferStatus: %v", err) | ||
| } | ||
|
|
||
| status := wandb.Status.ClickHouseStatus[apiv2.DefaultInstanceName] | ||
| if status.Replicated { | ||
| t.Error("external ClickHouse must not be reported as replicated") | ||
| } | ||
| if status.ClusterName != "" { | ||
| t.Errorf("expected an empty ClusterName for external ClickHouse, got %q", status.ClusterName) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
Repository: wandb/operator
Length of output: 18184
🏁 Script executed:
Repository: wandb/operator
Length of output: 50371
🏁 Script executed:
Repository: wandb/operator
Length of output: 50370
🏁 Script executed:
Repository: wandb/operator
Length of output: 17814
🏁 Script executed:
Repository: wandb/operator
Length of output: 199
🏁 Script executed:
Repository: wandb/operator
Length of output: 50370
Preserve
falsefor managed single-replica ClickHouse.boolwithomitemptyomits the managedfalsevalue. Use*bool; set it for managed ClickHouse and leave itnilfor external ClickHouse. Regenerate deepcopy and CRD artifacts, and add JSON tests forfalse,true, and omitted values.🤖 Prompt for AI Agents