From 97872675cfe701ef3036e0d6561c753539af25ba Mon Sep 17 00:00:00 2001 From: lucasvuillier Date: Fri, 10 Jan 2025 19:31:28 +0100 Subject: [PATCH] Add volumeMounts to K8ssandraCluster.spec.medusa --- CHANGELOG/CHANGELOG-1.21.md | 3 +- apis/medusa/v1alpha1/medusa_types.go | 4 ++ apis/medusa/v1alpha1/zz_generated.deepcopy.go | 7 +++ .../crds/k8ssandra-operator-crds.yaml | 43 +++++++++++++++++++ .../bases/k8ssandra.io_k8ssandraclusters.yaml | 43 +++++++++++++++++++ pkg/medusa/reconcile.go | 11 +++-- pkg/medusa/reconcile_test.go | 28 ++++++++++++ 7 files changed, 134 insertions(+), 5 deletions(-) diff --git a/CHANGELOG/CHANGELOG-1.21.md b/CHANGELOG/CHANGELOG-1.21.md index 3e2a9a65c..c1a3ce7c7 100644 --- a/CHANGELOG/CHANGELOG-1.21.md +++ b/CHANGELOG/CHANGELOG-1.21.md @@ -22,4 +22,5 @@ When cutting a new release, update the `unreleased` heading to the tag being gen * [BUGFIX] [#1454](https://github.com/k8ssandra/k8ssandra-operator/issues/1454) Do not try to work out backup status if there are no pods * [BUGFIX] [#1383](https://github.com/k8ssandra/k8ssandra-operator/issues/1383) Do not create MedusaBackup if MedusaBakupJob did not fully succeed * [BUGFIX] [#1460](https://github.com/k8ssandra/k8ssandra-operator/issues/1460) Fix podName calculations in medusa's hostmap.go to account for unbalanced racks also -* [BUGFIX] [#1466](https://github.com/k8ssandra/k8ssandra-operator/issues/1466) Do not overwrite existing status fields or forget to write the changes. Also, add new ContextName for the Datacenter to know where it used to be. \ No newline at end of file +* [BUGFIX] [#1466](https://github.com/k8ssandra/k8ssandra-operator/issues/1466) Do not overwrite existing status fields or forget to write the changes. Also, add new ContextName for the Datacenter to know where it used to be. +* [ENHANCEMENT] [#1465](https://github.com/k8ssandra/k8ssandra/issues/1465) Add `volumeMounts` option to `K8ssandraCluster.spec.medusa` \ No newline at end of file diff --git a/apis/medusa/v1alpha1/medusa_types.go b/apis/medusa/v1alpha1/medusa_types.go index db88f7d8c..923572025 100644 --- a/apis/medusa/v1alpha1/medusa_types.go +++ b/apis/medusa/v1alpha1/medusa_types.go @@ -160,6 +160,10 @@ type MedusaClusterTemplate struct { // Provides all storage backend related properties for backups. StorageProperties Storage `json:"storageProperties,omitempty"` + // Volume mounts for Medusa container. + // +optional + VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty"` + // Certificates for Medusa if client encryption is enabled in Cassandra. // The secret must be in the same namespace as Cassandra and must contain three keys: "rootca.crt", "client.crt_signed" and "client.key". // See https://docs.datastax.com/en/developer/python-driver/latest/security/ for more information on the required files. diff --git a/apis/medusa/v1alpha1/zz_generated.deepcopy.go b/apis/medusa/v1alpha1/zz_generated.deepcopy.go index d9a9eaa22..f37f49459 100644 --- a/apis/medusa/v1alpha1/zz_generated.deepcopy.go +++ b/apis/medusa/v1alpha1/zz_generated.deepcopy.go @@ -383,6 +383,13 @@ func (in *MedusaClusterTemplate) DeepCopyInto(out *MedusaClusterTemplate) { } out.CassandraUserSecretRef = in.CassandraUserSecretRef in.StorageProperties.DeepCopyInto(&out.StorageProperties) + if in.VolumeMounts != nil { + in, out := &in.VolumeMounts, &out.VolumeMounts + *out = make([]v1.VolumeMount, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } out.CertificatesSecretRef = in.CertificatesSecretRef if in.InitContainerResources != nil { in, out := &in.InitContainerResources, &out.InitContainerResources diff --git a/charts/k8ssandra-operator/crds/k8ssandra-operator-crds.yaml b/charts/k8ssandra-operator/crds/k8ssandra-operator-crds.yaml index cfa308f26..8d90eb05d 100644 --- a/charts/k8ssandra-operator/crds/k8ssandra-operator-crds.yaml +++ b/charts/k8ssandra-operator/crds/k8ssandra-operator-crds.yaml @@ -26571,6 +26571,49 @@ spec: Defaults to 50 MB/s. type: string type: object + volumeMounts: + description: Volume mounts for Medusa container. + items: + description: VolumeMount describes a mounting of a Volume within + a container. + properties: + mountPath: + description: |- + Path within the container at which the volume should be mounted. Must + not contain ':'. + type: string + mountPropagation: + description: |- + mountPropagation determines how mounts are propagated from the host + to container and the other way around. + When not set, MountPropagationNone is used. + This field is beta in 1.10. + type: string + name: + description: This must match the Name of a Volume. + type: string + readOnly: + description: |- + Mounted read-only if true, read-write otherwise (false or unspecified). + Defaults to false. + type: boolean + subPath: + description: |- + Path within the volume from which the container's volume should be mounted. + Defaults to "" (volume's root). + type: string + subPathExpr: + description: |- + Expanded path within the volume from which the container's volume should be mounted. + Behaves similarly to SubPath but environment variable references $(VAR_NAME) are expanded using the container's environment. + Defaults to "" (volume's root). + SubPathExpr and SubPath are mutually exclusive. + type: string + required: + - mountPath + - name + type: object + type: array type: object reaper: description: |- diff --git a/config/crd/bases/k8ssandra.io_k8ssandraclusters.yaml b/config/crd/bases/k8ssandra.io_k8ssandraclusters.yaml index 9e05f1673..0979d5ae6 100644 --- a/config/crd/bases/k8ssandra.io_k8ssandraclusters.yaml +++ b/config/crd/bases/k8ssandra.io_k8ssandraclusters.yaml @@ -26509,6 +26509,49 @@ spec: Defaults to 50 MB/s. type: string type: object + volumeMounts: + description: Volume mounts for Medusa container. + items: + description: VolumeMount describes a mounting of a Volume within + a container. + properties: + mountPath: + description: |- + Path within the container at which the volume should be mounted. Must + not contain ':'. + type: string + mountPropagation: + description: |- + mountPropagation determines how mounts are propagated from the host + to container and the other way around. + When not set, MountPropagationNone is used. + This field is beta in 1.10. + type: string + name: + description: This must match the Name of a Volume. + type: string + readOnly: + description: |- + Mounted read-only if true, read-write otherwise (false or unspecified). + Defaults to false. + type: boolean + subPath: + description: |- + Path within the volume from which the container's volume should be mounted. + Defaults to "" (volume's root). + type: string + subPathExpr: + description: |- + Expanded path within the volume from which the container's volume should be mounted. + Behaves similarly to SubPath but environment variable references $(VAR_NAME) are expanded using the container's environment. + Defaults to "" (volume's root). + SubPathExpr and SubPath are mutually exclusive. + type: string + required: + - mountPath + - name + type: object + type: array type: object reaper: description: |- diff --git a/pkg/medusa/reconcile.go b/pkg/medusa/reconcile.go index 929c1459b..afbf6860e 100644 --- a/pkg/medusa/reconcile.go +++ b/pkg/medusa/reconcile.go @@ -8,18 +8,17 @@ import ( "text/template" "github.com/adutra/goalesce" + "github.com/go-logr/logr" cassdcapi "github.com/k8ssandra/cass-operator/apis/cassandra/v1beta1" k8ss "github.com/k8ssandra/k8ssandra-operator/apis/k8ssandra/v1alpha1" api "github.com/k8ssandra/k8ssandra-operator/apis/medusa/v1alpha1" + "github.com/k8ssandra/k8ssandra-operator/pkg/cassandra" "github.com/k8ssandra/k8ssandra-operator/pkg/images" batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" - "k8s.io/utils/ptr" - - "github.com/go-logr/logr" - "github.com/k8ssandra/k8ssandra-operator/pkg/cassandra" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/utils/ptr" ) const ( @@ -323,6 +322,10 @@ func medusaVolumeMounts(dcConfig *cassandra.DatacenterConfig, medusaSpec *api.Me }) } + if medusaSpec.VolumeMounts != nil { + volumeMounts = append(volumeMounts, medusaSpec.VolumeMounts...) + } + return volumeMounts } diff --git a/pkg/medusa/reconcile_test.go b/pkg/medusa/reconcile_test.go index 9d75d31cd..5fce2f8a6 100644 --- a/pkg/medusa/reconcile_test.go +++ b/pkg/medusa/reconcile_test.go @@ -706,3 +706,31 @@ func TestPurgeCronJobNameTooLong(t *testing.T) { _, err := PurgeCronJob(dcConfig, clusterName, namespace, logger) assert.NotNil(t, err) } + +func TestMedusaVolumeMounts(t *testing.T) { + mountName := "testMount" + mountPath := "/home/cassandra/test-mount" + + medusaSpec := &medusaapi.MedusaClusterTemplate{ + VolumeMounts: []corev1.VolumeMount{{ + Name: mountName, + MountPath: mountPath, + }}, + } + dcConfig := cassandra.DatacenterConfig{} + logger := logr.New(logr.Discard().GetSink()) + + medusaContainer, err := CreateMedusaMainContainer(&dcConfig, medusaSpec, true, "test", logger) + assert.NoError(t, err) + assert.NotEmpty(t, medusaContainer.VolumeMounts) + + mountFound := false + for _, mount := range medusaContainer.VolumeMounts { + if mount.Name == mountName && mount.MountPath == mountPath { + mountFound = true + break + } + } + + assert.True(t, mountFound) +}