Skip to content

Commit

Permalink
Avoid overwriting customizations made to the vector/system-logger con…
Browse files Browse the repository at this point in the history
…tainer (#1322)
  • Loading branch information
Miles-Garnsey committed May 23, 2024
1 parent 77763d2 commit 84bd89d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG/CHANGELOG-1.17.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ When cutting a new release, update the `unreleased` heading to the tag being gen
* [CHANGE] [1313](https://github.com/k8ssandra/k8ssandra-operator/issues/1313) upgrade controller-runtime to 1.17 series, Go to 1.21.
* [BUGFIX] [1317](https://github.com/k8ssandra/k8ssandra-operator/issues/1317) Fix issues with caches in cluster scoped deployments where they were continuing to use a multi-namespace scoped cache and not an informer cache.
* [BUGFIX] [1316](https://github.com/k8ssandra/k8ssandra-operator/issues/1316) Fix interchanged intervals and timeouts in tests.
* [BUGFIX] [1322](https://github.com/k8ssandra/k8ssandra-operator/issues/1322) Fix bug where server-system-logger customisations from the Containers field would be overwritten when vector was enabled.
* [FEATURE] Add support for HCD 1.0
27 changes: 26 additions & 1 deletion controllers/k8ssandra/k8ssandracluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2415,6 +2415,11 @@ func injectContainersAndVolumes(t *testing.T, ctx context.Context, f *framework.
Cassandra: &api.CassandraClusterTemplate{
DatacenterOptions: api.DatacenterOptions{
ServerVersion: serverVersion,
Telemetry: &telemetryapi.TelemetrySpec{
Vector: &telemetryapi.VectorSpec{
Enabled: ptr.To(true),
},
},
StorageConfig: &cassdcapi.StorageConfig{
CassandraDataVolumeClaimSpec: &corev1.PersistentVolumeClaimSpec{
StorageClassName: &defaultStorageClass,
Expand All @@ -2431,6 +2436,14 @@ func injectContainersAndVolumes(t *testing.T, ctx context.Context, f *framework.
},
},
},
{
Name: "server-system-logger",
Image: "test-vector",
SecurityContext: &corev1.SecurityContext{
RunAsUser: ptr.To[int64](9999),
ReadOnlyRootFilesystem: ptr.To(true),
},
},
},
ExtraVolumes: &api.K8ssandraVolumes{
PVCs: []cassdcapi.AdditionalVolumes{
Expand Down Expand Up @@ -2505,7 +2518,19 @@ func injectContainersAndVolumes(t *testing.T, ctx context.Context, f *framework.
_, foundMain := cassandra.FindContainer(dc.Spec.PodTemplateSpec, "injected-container")
require.True(foundMain, "failed to find injected-container")

require.Equal(2, len(dc.Spec.StorageConfig.AdditionalVolumes), "expected 2 additionals volumes")
vectorContainerIdx, foundVector := cassandra.FindContainer(dc.Spec.PodTemplateSpec, "server-system-logger")
require.True(foundVector, "failed to find injected-container")
require.Equal(ptr.To[int64](9999),
dc.Spec.PodTemplateSpec.Spec.Containers[vectorContainerIdx].SecurityContext.RunAsUser,
"server-system-logger RunAsUser is not set")
require.Equal(ptr.To(true),
dc.Spec.PodTemplateSpec.Spec.Containers[vectorContainerIdx].SecurityContext.ReadOnlyRootFilesystem,
"server-system-logger RunAsUser is not set")
require.Equal(ptr.To(true),
dc.Spec.PodTemplateSpec.Spec.Containers[vectorContainerIdx].SecurityContext.ReadOnlyRootFilesystem,
"server-system-logger RunAsUser is not set")

require.Equal(3, len(dc.Spec.StorageConfig.AdditionalVolumes), "expected 3 additionals volumes")
require.Equal("/etc/injected", dc.Spec.StorageConfig.AdditionalVolumes[0].MountPath, "expected injected-volume mount path")

t.Log("deleting K8ssandraCluster")
Expand Down
13 changes: 10 additions & 3 deletions pkg/telemetry/vector.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package telemetry

import (
"fmt"
"strings"

"github.com/k8ssandra/k8ssandra-operator/pkg/labels"
"github.com/k8ssandra/k8ssandra-operator/pkg/utils"
"sigs.k8s.io/controller-runtime/pkg/client"
"strings"

"github.com/go-logr/logr"
cassdcapi "github.com/k8ssandra/cass-operator/apis/cassandra/v1beta1"
Expand All @@ -22,8 +23,14 @@ import (
func InjectCassandraVectorAgentConfig(telemetrySpec *telemetry.TelemetrySpec, dcConfig *cassandra.DatacenterConfig, k8cName string, logger logr.Logger) error {
if telemetrySpec.IsVectorEnabled() {
logger.V(1).Info("Updating server-system-logger agent in Cassandra pods")
loggerContainer := corev1.Container{
Name: reconciliation.SystemLoggerContainerName,
originalContainerIdx, found := cassandra.FindContainer(&dcConfig.PodTemplateSpec, reconciliation.SystemLoggerContainerName)
var loggerContainer corev1.Container
if found {
loggerContainer = dcConfig.PodTemplateSpec.Spec.Containers[originalContainerIdx]
} else {
loggerContainer = corev1.Container{
Name: reconciliation.SystemLoggerContainerName,
}
}

loggerResources := vector.VectorContainerResources(telemetrySpec)
Expand Down

0 comments on commit 84bd89d

Please sign in to comment.