From 55e2646bc47c1483bd8b2830e72a06a8daa6aa48 Mon Sep 17 00:00:00 2001 From: Karol Szwaj Date: Mon, 27 Nov 2023 21:13:33 +0100 Subject: [PATCH] adjust webhook test Signed-off-by: Karol Szwaj --- apis/k8ssandra/v1alpha1/k8ssandracluster_webhook.go | 4 ++-- .../v1alpha1/k8ssandracluster_webhook_test.go | 11 ----------- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/apis/k8ssandra/v1alpha1/k8ssandracluster_webhook.go b/apis/k8ssandra/v1alpha1/k8ssandracluster_webhook.go index 4e96e6690..2d059ae0e 100644 --- a/apis/k8ssandra/v1alpha1/k8ssandracluster_webhook.go +++ b/apis/k8ssandra/v1alpha1/k8ssandracluster_webhook.go @@ -117,7 +117,7 @@ func (r *K8ssandraCluster) ValidateUpdate(old runtime.Object) error { newCassConfig := r.Spec.Cassandra.DatacenterOptions.CassandraConfig if oldCassConfig != nil && newCassConfig != nil { oldNumTokens, oldNumTokensExists := oldCassConfig.CassandraYaml["num_tokens"] - newNumTokens := newCassConfig.CassandraYaml["num_tokens"] + newNumTokens, newNumTokensExists := newCassConfig.CassandraYaml["num_tokens"] if !oldNumTokensExists { cassVersion, err := semver.NewVersion(oldCluster.Spec.Cassandra.ServerVersion) @@ -125,7 +125,7 @@ func (r *K8ssandraCluster) ValidateUpdate(old runtime.Object) error { return err } defaultNumTokens := oldCluster.DefaultNumTokens(cassVersion) - if int64(newNumTokens.(float64)) != defaultNumTokens { + if newNumTokensExists && int64(newNumTokens.(float64)) != defaultNumTokens { return ErrNumTokens } } else { diff --git a/apis/k8ssandra/v1alpha1/k8ssandracluster_webhook_test.go b/apis/k8ssandra/v1alpha1/k8ssandracluster_webhook_test.go index 79efe9c1c..cedcffeb4 100644 --- a/apis/k8ssandra/v1alpha1/k8ssandracluster_webhook_test.go +++ b/apis/k8ssandra/v1alpha1/k8ssandracluster_webhook_test.go @@ -176,17 +176,6 @@ func testNumTokensInUpdate(t *testing.T) { // This should be acceptable change, since 3.11.10 defaulted to 256 and so it is the same value err = k8sClient.Update(ctx, cluster) require.NoError(err) - - // However, not setting the num_tokens, when the defaults have changed should be rejected - otherwise the cluster will reject the update - cluster2 := createMinimalClusterObj("numtokens-test-update-2", "numtokensupdate-namespace") - cluster2.Spec.Cassandra.ServerVersion = "3.11.10" - cluster2.Spec.Cassandra.DatacenterOptions.CassandraConfig = &CassandraConfig{} - err = k8sClient.Create(ctx, cluster2) - require.NoError(err) - - cluster2.Spec.Cassandra.ServerVersion = "4.1.3" - err = k8sClient.Update(ctx, cluster2) - require.Error(err) } func testReaperKeyspaceValidation(t *testing.T) {