Skip to content

Commit

Permalink
Allow k8ssandra.io labels and annotations in services config (fixes k…
Browse files Browse the repository at this point in the history
  • Loading branch information
olim7t committed Aug 26, 2024
1 parent 7199188 commit 0b8f3f6
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Changelog for Cass Operator, new PRs should update the `main / unreleased` secti

## unreleased

* [CHANGE] [#689]((https://github.com/k8ssandra/cass-operator/issues/689) Allow k8ssandra.io labels and annotations in services config

## v1.22.0

* [FEATURE] [#263]((https://github.com/k8ssandra/cass-operator/issues/263) Allow increasing the size of CassandraDataVolumeClaimSpec if the selected StorageClass supports it. This feature is currently behind a opt-in feature flag and requires an annotation ``cassandra.datastax.com/allow-storage-changes: true`` to be set in the CassandraDatacenter.
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(fmt.Sprintf("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
2 changes: 1 addition & 1 deletion apis/cassandra/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apis/config/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apis/control/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0b8f3f6

Please sign in to comment.