From e835c519568d05b21b0fa92bde1cf27c5a24b7a1 Mon Sep 17 00:00:00 2001 From: Alexander Dejanovski Date: Wed, 22 May 2024 11:51:22 +0200 Subject: [PATCH] Add initial support for HCD --- .../v1alpha1/k8ssandracluster_types.go | 18 +++++-- .../crds/k8ssandra-operator-crds.yaml | 5 +- .../bases/k8ssandra.io_k8ssandraclusters.yaml | 5 +- controllers/k8ssandra/dcconfigs.go | 4 +- pkg/cassandra/config_test.go | 50 +++++++++++++++++++ 5 files changed, 73 insertions(+), 9 deletions(-) diff --git a/apis/k8ssandra/v1alpha1/k8ssandracluster_types.go b/apis/k8ssandra/v1alpha1/k8ssandracluster_types.go index 4006e6402..31911c416 100644 --- a/apis/k8ssandra/v1alpha1/k8ssandracluster_types.go +++ b/apis/k8ssandra/v1alpha1/k8ssandracluster_types.go @@ -263,7 +263,7 @@ type CassandraClusterTemplate struct { ClusterName string `json:"clusterName,omitempty"` // Server type: "cassandra" or "dse". - // +kubebuilder:validation:Enum=cassandra;dse + // +kubebuilder:validation:Enum=cassandra;dse;hcd // +kubebuilder:default=cassandra ServerType ServerDistribution `json:"serverType,omitempty"` } @@ -318,7 +318,7 @@ type DatacenterOptions struct { // ServerVersion is the Cassandra or DSE version. The following versions are supported: // - Cassandra: 3.11.X, 4.X.X and 5.X.X // - DSE: 6.8.X, 7.x.x - // +kubebuilder:validation:Pattern=(6\.8\.\d+)|(3\.11\.\d+)|(4\.\d+\.\d+)|(5\.\d+\.\d+)|(7\.\d+\.\d+) + // - HCD: 1.0.x ServerVersion string `json:"serverVersion,omitempty"` // ServerImage is the image for the cassandra container. Note that this should be a @@ -530,12 +530,24 @@ type ServerDistribution string const ( ServerDistributionCassandra = ServerDistribution("cassandra") ServerDistributionDse = ServerDistribution("dse") + ServerDistributionHcd = ServerDistribution("hcd") ) +func (sd *ServerDistribution) IsCassandra() bool { + return *sd == ServerDistributionCassandra || *sd == ServerDistributionHcd +} + +func (sd *ServerDistribution) IsDse() bool { + return *sd == ServerDistributionDse +} + func (kc *K8ssandraCluster) DefaultNumTokens(serverVersion *semver.Version) float64 { - if kc.Spec.Cassandra.ServerType == ServerDistributionCassandra && serverVersion.Major() == 3 { + if kc.Spec.Cassandra.ServerType.IsCassandra() && serverVersion.Major() == 3 { return float64(256) } + if kc.Spec.Cassandra.ServerType.IsCassandra() { + return float64(8) + } return float64(16) } diff --git a/charts/k8ssandra-operator/crds/k8ssandra-operator-crds.yaml b/charts/k8ssandra-operator/crds/k8ssandra-operator-crds.yaml index 599955f17..5d915dede 100644 --- a/charts/k8ssandra-operator/crds/k8ssandra-operator-crds.yaml +++ b/charts/k8ssandra-operator/crds/k8ssandra-operator-crds.yaml @@ -10258,7 +10258,7 @@ spec: ServerVersion is the Cassandra or DSE version. The following versions are supported: - Cassandra: 3.11.X, 4.X.X and 5.X.X - DSE: 6.8.X, 7.x.x - pattern: (6\.8\.\d+)|(3\.11\.\d+)|(4\.\d+\.\d+)|(5\.\d+\.\d+)|(7\.\d+\.\d+) + - HCD: 1.0.x type: string serviceAccount: description: The k8s service account to use for the Cassandra @@ -22129,13 +22129,14 @@ spec: enum: - cassandra - dse + - hcd type: string serverVersion: description: |- ServerVersion is the Cassandra or DSE version. The following versions are supported: - Cassandra: 3.11.X, 4.X.X and 5.X.X - DSE: 6.8.X, 7.x.x - pattern: (6\.8\.\d+)|(3\.11\.\d+)|(4\.\d+\.\d+)|(5\.\d+\.\d+)|(7\.\d+\.\d+) + - HCD: 1.0.x type: string serviceAccount: description: The k8s service account to use for the Cassandra diff --git a/config/crd/bases/k8ssandra.io_k8ssandraclusters.yaml b/config/crd/bases/k8ssandra.io_k8ssandraclusters.yaml index d22595b54..5de0f46c8 100644 --- a/config/crd/bases/k8ssandra.io_k8ssandraclusters.yaml +++ b/config/crd/bases/k8ssandra.io_k8ssandraclusters.yaml @@ -10196,7 +10196,7 @@ spec: ServerVersion is the Cassandra or DSE version. The following versions are supported: - Cassandra: 3.11.X, 4.X.X and 5.X.X - DSE: 6.8.X, 7.x.x - pattern: (6\.8\.\d+)|(3\.11\.\d+)|(4\.\d+\.\d+)|(5\.\d+\.\d+)|(7\.\d+\.\d+) + - HCD: 1.0.x type: string serviceAccount: description: The k8s service account to use for the Cassandra @@ -22067,13 +22067,14 @@ spec: enum: - cassandra - dse + - hcd type: string serverVersion: description: |- ServerVersion is the Cassandra or DSE version. The following versions are supported: - Cassandra: 3.11.X, 4.X.X and 5.X.X - DSE: 6.8.X, 7.x.x - pattern: (6\.8\.\d+)|(3\.11\.\d+)|(4\.\d+\.\d+)|(5\.\d+\.\d+)|(7\.\d+\.\d+) + - HCD: 1.0.x type: string serviceAccount: description: The k8s service account to use for the Cassandra diff --git a/controllers/k8ssandra/dcconfigs.go b/controllers/k8ssandra/dcconfigs.go index 01272e7f9..8709edac0 100644 --- a/controllers/k8ssandra/dcconfigs.go +++ b/controllers/k8ssandra/dcconfigs.go @@ -59,7 +59,7 @@ func (r *K8ssandraClusterReconciler) createDatacenterConfigs( // which is why we're doing this for Cassandra only. // We only set this for the first DC. For subsequent DCs, the replication will be altered and a rebuild // triggered. - if kc.Spec.Cassandra.ServerType == api.ServerDistributionCassandra && len(dcConfigs) == 0 { + if kc.Spec.Cassandra.ServerType.IsCassandra() && len(dcConfigs) == 0 { cassandra.ApplySystemReplication(dcConfig, systemReplication) } @@ -67,7 +67,7 @@ func (r *K8ssandraClusterReconciler) createDatacenterConfigs( // set (see https://github.com/stargate/stargate/issues/1274). // Set the option preemptively (we don't check `kc.HasStargates()` explicitly, because that causes the operator // to restart the whole DC whenever Stargate is added or removed). - if kc.Spec.Cassandra.ServerType == api.ServerDistributionCassandra && dcConfig.ServerVersion.Major() != 3 { + if kc.Spec.Cassandra.ServerType.IsCassandra() && dcConfig.ServerVersion.Major() != 3 { cassandra.AllowAlterRfDuringRangeMovement(dcConfig) } diff --git a/pkg/cassandra/config_test.go b/pkg/cassandra/config_test.go index 02695ca90..db9186e31 100644 --- a/pkg/cassandra/config_test.go +++ b/pkg/cassandra/config_test.go @@ -142,6 +142,27 @@ func TestCreateJsonConfig(t *testing.T) { "concurrent_writes": 16, "concurrent_counter_writes": 4 } + }`, + }, + { + name: "HCD [1.0.0] simple", + serverVersion: semver.MustParse("1.0.0"), + serverType: api.ServerDistributionHcd, + cassandraConfig: api.CassandraConfig{ + CassandraYaml: unstructured.Unstructured{ + "num_tokens": 16, + "concurrent_reads": 8, + "concurrent_writes": 16, + "concurrent_counter_writes": 4, + }, + }, + want: `{ + "cassandra-yaml": { + "num_tokens": 16, + "concurrent_reads": 8, + "concurrent_writes": 16, + "concurrent_counter_writes": 4 + } }`, }, { @@ -161,6 +182,25 @@ func TestCreateJsonConfig(t *testing.T) { "-Dcassandra.system_distributed_replication=dc1:3,dc2:3,dc3:3" ] } + }`, + }, + { + name: "HCD [1.0.0] system replication", + serverVersion: semver.MustParse("1.0.0"), + serverType: api.ServerDistributionHcd, + cassandraConfig: api.CassandraConfig{ + JvmOptions: api.JvmOptions{ + AdditionalOptions: []string{ + SystemReplicationFactorStrategy + "=dc1:3,dc2:3,dc3:3", + }, + }, + }, + want: `{ + "cassandra-env-sh": { + "additional-jvm-opts": [ + "-Dcassandra.system_distributed_replication=dc1:3,dc2:3,dc3:3" + ] + } }`, }, { @@ -305,3 +345,13 @@ func TestSmartTokenAllocCassandra(t *testing.T) { _, exists := dcConfig.CassandraConfig.CassandraYaml["allocate_tokens_for_local_replication_factor"] assert.False(t, exists, "allocate_tokens_for_local_replication_factor should not be set for Cassandra") } + +func TestSmartTokenAllocHcd(t *testing.T) { + dcConfig := &DatacenterConfig{ + ServerType: api.ServerDistributionHcd, + } + + EnableSmartTokenAllocation(dcConfig) + _, exists := dcConfig.CassandraConfig.CassandraYaml["allocate_tokens_for_local_replication_factor"] + assert.False(t, exists, "allocate_tokens_for_local_replication_factor should not be set for HCD") +}