Skip to content

Commit d1e2209

Browse files
authored
Change regexp to allow wider version ranges (#906)
* Change regexp to allow wider version ranges, including HCD 2.0.x and only verify the ServerVersion structure, not specific versions
1 parent 8b8e400 commit d1e2209

10 files changed

Lines changed: 6 additions & 152 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ Changelog for Cass Operator, new PRs should update the `main / unreleased` secti
1111

1212
## unreleased
1313

14+
* [CHANGE] [#905](https://github.com/k8ssandra/cass-operator/issues/905) Relax the ServerVersion checks to structure only without separating OSS/DSE/HCD.
1415
* [FEATURE] [#893](https://github.com/k8ssandra/cass-operator/issues/893) Add support for maxUnavailable (Kubernetes 1.35 and up). This allows to make changes to the Cassandra pods in parallel, thus speeding up changes in larger clusters. Allows integer or percentage setting, but will never target more than one rack at a time.
1516
* [ENHANCEMENT] [#888](https://github.com/k8ssandra/cass-operator/issues/888) Add new metrics around all calls to the mgmt-api. This allows to track if some calls are taking longer to execute than expected.
17+
* [ENHANCEMENT] [#873](https://github.com/k8ssandra/cass-operator/issues/873) Allow replacing multiple previously bootstrapped nodes in parallel. Also, the CassandraTask to replace pod accepts RackName as alternative to PodName as filtering rule.
1618

1719
## v1.29.1
1820

1921
* [BUGFIX] [#899](https://github.com/k8ssandra/cass-operator/issues/899) Skip webhook startup when the manager is launched without `--webhook-cert-path` (Helm chart behavior).
2022
* [BUGFIX] [#887](https://github.com/k8ssandra/cass-operator/issues/887) Prevents infinite loop when seed refresh times out during node failures, allowing the operator to recover.
21-
* [ENHANCEMENT] [#873](https://github.com/k8ssandra/cass-operator/issues/873) Allow replacing multiple previously bootstrapped nodes in parallel. Also, the CassandraTask to replace pod accepts RackName as alternative to PodName as filtering rule.
2223

2324
## v1.29.0
2425

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ CONTROLLER_TOOLS_VERSION ?= v0.19.0
275275
OPERATOR_SDK_VERSION ?= 1.42.0
276276
HELM_VERSION ?= 3.19.4
277277
OPM_VERSION ?= 1.61.0
278-
GOLANGCI_LINT_VERSION ?= v2.10.1
278+
GOLANGCI_LINT_VERSION ?= v2.11.3
279279
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
280280
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
281281

apis/cassandra/v1beta1/cassandradatacenter_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ type CassandraDatacenterSpec struct {
121121

122122
// Version string for config builder,
123123
// used to generate Cassandra server configuration
124-
// +kubebuilder:validation:Pattern=(6\.[89]\.\d+)|(3\.11\.\d+)|(4\.\d+\.\d+)|(5\.\d+\.\d+)|(1\.\d+\.\d+)
124+
// +kubebuilder:validation:Pattern=(\d+\.\d+\.\d+)
125125
ServerVersion string `json:"serverVersion"`
126126

127127
// Cassandra server image name. Use of ImageConfig to match ServerVersion is recommended instead of this value.

config/crd/bases/cassandra.datastax.com_cassandradatacenters.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9883,7 +9883,7 @@ spec:
98839883
description: |-
98849884
Version string for config builder,
98859885
used to generate Cassandra server configuration
9886-
pattern: (6\.[89]\.\d+)|(3\.11\.\d+)|(4\.\d+\.\d+)|(5\.\d+\.\d+)|(1\.\d+\.\d+)
9886+
pattern: (\d+\.\d+\.\d+)
98879887
type: string
98889888
serviceAccount:
98899889
description: Deprecated DeprecatedServiceAccount Use ServiceAccountName

internal/webhooks/cassandra/v1beta1/cassandradatacenter_webhook.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919

2020
"github.com/google/go-cmp/cmp"
2121
api "github.com/k8ssandra/cass-operator/apis/cassandra/v1beta1"
22-
"github.com/k8ssandra/cass-operator/pkg/images"
2322
)
2423

2524
// log is for logging in this package.
@@ -104,32 +103,12 @@ func (v *CassandraDatacenterCustomValidator) ValidateDelete(ctx context.Context,
104103

105104
// ValidateSingleDatacenter checks that no values are improperly set on a CassandraDatacenter
106105
func ValidateSingleDatacenter(dc *api.CassandraDatacenter) error {
107-
// Ensure serverVersion and serverType are compatible
108-
109-
if dc.Spec.ServerType == "dse" {
110-
if !images.IsDseVersionSupported(dc.Spec.ServerVersion) {
111-
return attemptedTo("use unsupported DSE version '%s'", dc.Spec.ServerVersion)
112-
}
113-
}
114-
115-
if dc.Spec.ServerType == "hcd" {
116-
if !images.IsHCDVersionSupported(dc.Spec.ServerVersion) {
117-
return attemptedTo("use unsupported HCD version '%s'", dc.Spec.ServerVersion)
118-
}
119-
}
120-
121106
if dc.Spec.ServerType == "cassandra" && dc.Spec.DseWorkloads != nil {
122107
if dc.Spec.DseWorkloads.AnalyticsEnabled || dc.Spec.DseWorkloads.GraphEnabled || dc.Spec.DseWorkloads.SearchEnabled {
123108
return attemptedTo("enable DSE workloads if server type is Cassandra")
124109
}
125110
}
126111

127-
if dc.Spec.ServerType == "cassandra" {
128-
if !images.IsOssVersionSupported(dc.Spec.ServerVersion) {
129-
return attemptedTo("use unsupported Cassandra version '%s'", dc.Spec.ServerVersion)
130-
}
131-
}
132-
133112
isDse := dc.Spec.ServerType == "dse"
134113
isCassandra3 := dc.Spec.ServerType == "cassandra" && strings.HasPrefix(dc.Spec.ServerVersion, "3.")
135114

internal/webhooks/cassandra/v1beta1/cassandradatacenter_webhook_test.go

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -75,45 +75,6 @@ func Test_ValidateSingleDatacenter(t *testing.T) {
7575
},
7676
errString: "",
7777
},
78-
{
79-
name: "DSE 7.0.0 invalid",
80-
dc: &api.CassandraDatacenter{
81-
ObjectMeta: metav1.ObjectMeta{
82-
Name: "exampleDC",
83-
},
84-
Spec: api.CassandraDatacenterSpec{
85-
ServerType: "dse",
86-
ServerVersion: "7.0.0",
87-
},
88-
},
89-
errString: "use unsupported DSE version '7.0.0'",
90-
},
91-
{
92-
name: "DSE Invalid",
93-
dc: &api.CassandraDatacenter{
94-
ObjectMeta: metav1.ObjectMeta{
95-
Name: "exampleDC",
96-
},
97-
Spec: api.CassandraDatacenterSpec{
98-
ServerType: "dse",
99-
ServerVersion: "4.8.0",
100-
},
101-
},
102-
errString: "use unsupported DSE version '4.8.0'",
103-
},
104-
{
105-
name: "DSE 5 Invalid",
106-
dc: &api.CassandraDatacenter{
107-
ObjectMeta: metav1.ObjectMeta{
108-
Name: "exampleDC",
109-
},
110-
Spec: api.CassandraDatacenterSpec{
111-
ServerType: "dse",
112-
ServerVersion: "5.0.0",
113-
},
114-
},
115-
errString: "use unsupported DSE version '5.0.0'",
116-
},
11778
{
11879
name: "Cassandra valid",
11980
dc: &api.CassandraDatacenter{
@@ -166,32 +127,6 @@ func Test_ValidateSingleDatacenter(t *testing.T) {
166127
},
167128
errString: "",
168129
},
169-
{
170-
name: "Cassandra Invalid",
171-
dc: &api.CassandraDatacenter{
172-
ObjectMeta: metav1.ObjectMeta{
173-
Name: "exampleDC",
174-
},
175-
Spec: api.CassandraDatacenterSpec{
176-
ServerType: "cassandra",
177-
ServerVersion: "6.8.0",
178-
},
179-
},
180-
errString: "use unsupported Cassandra version '6.8.0'",
181-
},
182-
{
183-
name: "Cassandra Invalid too",
184-
dc: &api.CassandraDatacenter{
185-
ObjectMeta: metav1.ObjectMeta{
186-
Name: "exampleDC",
187-
},
188-
Spec: api.CassandraDatacenterSpec{
189-
ServerType: "cassandra",
190-
ServerVersion: "7.0.0",
191-
},
192-
},
193-
errString: "use unsupported Cassandra version '7.0.0'",
194-
},
195130
{
196131
name: "Dse Workloads in Cassandra Invalid",
197132
dc: &api.CassandraDatacenter{

pkg/images/images.go

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package images
66
import (
77
"fmt"
88
"os"
9-
"regexp"
109
"strings"
1110

1211
corev1 "k8s.io/api/core/v1"
@@ -27,9 +26,6 @@ type imageRegistry struct {
2726
}
2827

2928
const (
30-
ValidDseVersionRegexp = "(6\\.[89]\\.\\d+)"
31-
ValidHcdVersionRegexp = "(1\\.\\d+\\.\\d+)"
32-
ValidOssVersionRegexp = "(3\\.11\\.\\d+)|(4\\.\\d+\\.\\d+)|(5\\.\\d+\\.\\d+)"
3329
DefaultCassandraRepository = "k8ssandra/cass-management-api"
3430
DefaultDSERepository = "datastax/dse-mgmtapi-6_8"
3531
DefaultHCDRepository = "datastax/hcd"
@@ -73,21 +69,6 @@ func (i *imageRegistry) loadImageConfig(content []byte) (*configv1beta1.ImageCon
7369
return parsedImageConfig, nil
7470
}
7571

76-
func IsDseVersionSupported(version string) bool {
77-
validVersions := regexp.MustCompile(ValidDseVersionRegexp)
78-
return validVersions.MatchString(version)
79-
}
80-
81-
func IsOssVersionSupported(version string) bool {
82-
validVersions := regexp.MustCompile(ValidOssVersionRegexp)
83-
return validVersions.MatchString(version)
84-
}
85-
86-
func IsHCDVersionSupported(version string) bool {
87-
validVersions := regexp.MustCompile(ValidHcdVersionRegexp)
88-
return validVersions.MatchString(version)
89-
}
90-
9172
func (i *imageRegistry) splitRegistry(image string) (registry string, imageNoRegistry string) {
9273
comps := strings.Split(image, "/")
9374

@@ -230,17 +211,9 @@ func (i *imageRegistry) GetCassandraImage(serverType, version string) (string, e
230211

231212
switch serverType {
232213
case "dse":
233-
if !IsDseVersionSupported(version) {
234-
return "", fmt.Errorf("server 'dse' and version '%s' do not work together", version)
235-
}
236214
case "cassandra":
237-
if !IsOssVersionSupported(version) {
238-
return "", fmt.Errorf("server 'cassandra' and version '%s' do not work together", version)
239-
}
240215
case "hcd":
241-
if !IsHCDVersionSupported(version) {
242-
return "", fmt.Errorf("server 'hcd' and version '%s' do not work together", version)
243-
}
216+
break
244217
default:
245218
return "", fmt.Errorf("server type '%s' is not supported", serverType)
246219
}

pkg/images/images_test.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,6 @@ func TestDefaultRepositories(t *testing.T) {
168168
assert.Equal("datastax/dse-mgmtapi-6_8:6.8.17", path)
169169
}
170170

171-
func TestOssValidVersions(t *testing.T) {
172-
assert := assert.New(t)
173-
assert.True(IsOssVersionSupported("4.0.0"))
174-
assert.True(IsOssVersionSupported("4.1.0"))
175-
assert.False(IsOssVersionSupported("4.0"))
176-
assert.False(IsOssVersionSupported("4.1"))
177-
assert.False(IsOssVersionSupported("6.8.0"))
178-
}
179-
180171
func TestPullPolicyOverride(t *testing.T) {
181172
assert := require.New(t)
182173
imageConfigFile := filepath.Join("..", "..", "tests", "testdata", "image_config_parsing.yaml")

pkg/reconciliation/construct_podtemplatespec_test.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,26 +1580,6 @@ func Test_makeImage(t *testing.T) {
15801580
want: "datastax.jfrog.io/secret-debug-image/dse-server:6.8.0-test123",
15811581
errString: "",
15821582
},
1583-
{
1584-
name: "test unknown dse version",
1585-
args: args{
1586-
serverImage: "",
1587-
serverType: "dse",
1588-
serverVersion: "6.7.0",
1589-
},
1590-
want: "",
1591-
errString: "server 'dse' and version '6.7.0' do not work together",
1592-
},
1593-
{
1594-
name: "test unknown cassandra version",
1595-
args: args{
1596-
serverImage: "",
1597-
serverType: "cassandra",
1598-
serverVersion: "3.10.0",
1599-
},
1600-
want: "",
1601-
errString: "server 'cassandra' and version '3.10.0' do not work together",
1602-
},
16031583
{
16041584
name: "test fallback",
16051585
args: args{

tests/webhook_validation/webhook_validation_suite_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@ var _ = Describe(testName, func() {
8181
FormatOutput(json)
8282
ns.WaitForOutputAndLog(step, k, "Ready", 30)
8383

84-
step = "attempt to use invalid dse version"
85-
json = "{\"spec\": {\"serverType\": \"dse\", \"serverVersion\": \"6.7.0\"}}"
86-
k = kubectl.PatchMerge(dcResource, json)
87-
ns.ExecAndLogAndExpectErrorString(step, k,
88-
`spec.serverVersion: Invalid value: "6.7.0": spec.serverVersion in body should match '(6\.[89]\.\d+)|(3\.11\.\d+)|(4\.\d+\.\d+)|(5\.\d+\.\d+)|(1\.\d+\.\d+)'`)
8984
step = "attempt to change the cluster name"
9085
json = "{\"spec\": {\"clusterName\": \"NewName\"}}"
9186
k = kubectl.PatchMerge(dcResource, json)

0 commit comments

Comments
 (0)