Skip to content
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

Allow k8ssandra.io labels and annotations in services config (fixes #689) #690

Merged
merged 1 commit into from
Aug 27, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Changelog for Cass Operator, new PRs should update the `main / unreleased` secti
## unreleased

* [BUGFIX] [#687](https://github.com/k8ssandra/cass-operator/issues/687) Prevent a crash when when StorageClassName was not set in the CassandraDataVolumeClaimSpec
* [CHANGE] [#689](https://github.com/k8ssandra/cass-operator/issues/689) Allow k8ssandra.io labels and annotations in services config

## v1.22.0

Expand Down
7 changes: 3 additions & 4 deletions apis/cassandra/v1beta1/cassandradatacenter_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ import (
)

const (
datastaxPrefix string = "cassandra.datastax.com"
k8ssandraPrefix string = "k8ssandra.io"
datastaxPrefix string = "cassandra.datastax.com"
)

var log = logf.Log.WithName("api")
Expand Down Expand Up @@ -341,7 +340,7 @@ func ValidateServiceLabelsAndAnnotations(dc CassandraDatacenter) error {

for svcName, config := range services {
if containsReservedAnnotations(config) || containsReservedLabels(config) {
return attemptedTo(fmt.Sprintf("configure %s with reserved annotations and/or labels (prefixes %s and/or %s)", svcName, datastaxPrefix, k8ssandraPrefix))
return attemptedTo("configure %s with reserved annotations and/or labels (prefix %s)", svcName, datastaxPrefix)
}
}

Expand All @@ -365,7 +364,7 @@ func containsReservedLabels(config ServiceConfigAdditions) bool {

func containsReservedPrefixes(config map[string]string) bool {
for k := range config {
if strings.HasPrefix(k, datastaxPrefix) || strings.HasPrefix(k, k8ssandraPrefix) {
if strings.HasPrefix(k, datastaxPrefix) {
// reserved prefix found
return true
}
Expand Down
27 changes: 23 additions & 4 deletions apis/cassandra/v1beta1/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func Test_ValidateSingleDatacenter(t *testing.T) {
errString: "use multiple nodes per worker without cpu and memory requests and limits",
},
{
name: "Prevent user specified reserved Service labels and annotations",
name: "Prevent user specified cassandra.datastax.com Service labels and annotations",
dc: &CassandraDatacenter{
ObjectMeta: metav1.ObjectMeta{
Name: "exampleDC",
Expand All @@ -337,13 +337,32 @@ func Test_ValidateSingleDatacenter(t *testing.T) {
ServerVersion: "4.0.4",
AdditionalServiceConfig: ServiceConfig{
DatacenterService: ServiceConfigAdditions{
Labels: map[string]string{"k8ssandra.io/key1": "val1", "cassandra.datastax.com/key2": "val2"},
Annotations: map[string]string{"k8ssandra.io/key3": "val3", "cassandra.datastax.com/key4": "val4"},
Labels: map[string]string{"cassandra.datastax.com/key1": "val1"},
Annotations: map[string]string{"cassandra.datastax.com/key2": "val2"},
},
},
},
},
errString: "configure DatacenterService with reserved annotations and/or labels (prefixes cassandra.datastax.com and/or k8ssandra.io)",
errString: "configure DatacenterService with reserved annotations and/or labels (prefix cassandra.datastax.com)",
},
{
name: "Allow user specified k8ssandra.io Service labels and annotations",
dc: &CassandraDatacenter{
ObjectMeta: metav1.ObjectMeta{
Name: "exampleDC",
},
Spec: CassandraDatacenterSpec{
ServerType: "cassandra",
ServerVersion: "4.0.4",
AdditionalServiceConfig: ServiceConfig{
DatacenterService: ServiceConfigAdditions{
Labels: map[string]string{"k8ssandra.io/key1": "val1"},
Annotations: map[string]string{"k8ssandra.io/key2": "val2"},
},
},
},
},
errString: "",
},
{
name: "Allow upgrade should not accept invalid values",
Expand Down
Loading