From 19c0ab7c33ae1083fc7283c5040777bff325f232 Mon Sep 17 00:00:00 2001 From: Maciej Zimnoch Date: Tue, 29 Dec 2020 16:58:15 +0100 Subject: [PATCH] cluster: allow to mount volumes in agent container (#299) Fixes #299 --- .../scylla.scylladb.com_scyllaclusters.yaml | 30 ++++++++++++++++++- examples/common/operator.yaml | 30 ++++++++++++++++++- examples/generic/cluster.yaml | 2 +- pkg/api/v1alpha1/cluster_types.go | 8 +++-- pkg/api/v1alpha1/zz_generated.deepcopy.go | 7 +++++ pkg/controllers/cluster/resource/resource.go | 8 ++++- 6 files changed, 78 insertions(+), 7 deletions(-) diff --git a/config/operator/crd/bases/scylla.scylladb.com_scyllaclusters.yaml b/config/operator/crd/bases/scylla.scylladb.com_scyllaclusters.yaml index 71317a69cb..03aa83c2cb 100644 --- a/config/operator/crd/bases/scylla.scylladb.com_scyllaclusters.yaml +++ b/config/operator/crd/bases/scylla.scylladb.com_scyllaclusters.yaml @@ -143,6 +143,34 @@ spec: description: 'Requests describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/' type: object type: object + agentVolumeMounts: + description: AgentVolumeMounts to be added to Agent 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 members: description: Members is the number of Scylla instances in this rack. format: int32 @@ -582,7 +610,7 @@ spec: type: object type: array volumes: - description: Volumes added to Scylla container. + description: Volumes added to Scylla Pod. items: description: Volume represents a named volume in a pod that may be accessed by any container in the pod. properties: diff --git a/examples/common/operator.yaml b/examples/common/operator.yaml index 55c3b1bfee..d895fdc1a2 100644 --- a/examples/common/operator.yaml +++ b/examples/common/operator.yaml @@ -158,6 +158,34 @@ spec: description: 'Requests describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/' type: object type: object + agentVolumeMounts: + description: AgentVolumeMounts to be added to Agent 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 members: description: Members is the number of Scylla instances in this rack. format: int32 @@ -597,7 +625,7 @@ spec: type: object type: array volumes: - description: Volumes added to Scylla container. + description: Volumes added to Scylla Pod. items: description: Volume represents a named volume in a pod that may be accessed by any container in the pod. properties: diff --git a/examples/generic/cluster.yaml b/examples/generic/cluster.yaml index fd9a1a2483..5871557688 100644 --- a/examples/generic/cluster.yaml +++ b/examples/generic/cluster.yaml @@ -104,6 +104,6 @@ spec: - name: coredumpfs hostPath: path: /tmp/coredumps - volumeMounts: + agentVolumeMounts: - mountPath: /tmp/coredumps name: coredumpfs \ No newline at end of file diff --git a/pkg/api/v1alpha1/cluster_types.go b/pkg/api/v1alpha1/cluster_types.go index 88e99662f2..9bfea71056 100644 --- a/pkg/api/v1alpha1/cluster_types.go +++ b/pkg/api/v1alpha1/cluster_types.go @@ -196,10 +196,12 @@ type RackSpec struct { Resources corev1.ResourceRequirements `json:"resources"` // AgentResources which Agent container will use. AgentResources corev1.ResourceRequirements `json:"agentResources,omitempty"` - // Volumes added to Scylla container. - Volumes []corev1.Volume `json:"volumes,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"name" protobuf:"bytes,1,rep,name=volumes"` + // Volumes added to Scylla Pod. + Volumes []corev1.Volume `json:"volumes,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"name"` // VolumeMounts to be added to Scylla container. - VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty" patchStrategy:"merge" patchMergeKey:"mountPath" protobuf:"bytes,9,rep,name=volumeMounts"` + VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty" patchStrategy:"merge" patchMergeKey:"mountPath"` + // AgentVolumeMounts to be added to Agent container. + AgentVolumeMounts []corev1.VolumeMount `json:"agentVolumeMounts,omitempty" patchStrategy:"merge" patchMergeKey:"mountPath"` // Scylla config map name to customize scylla.yaml ScyllaConfig string `json:"scyllaConfig"` // Scylla config map name to customize scylla manager agent diff --git a/pkg/api/v1alpha1/zz_generated.deepcopy.go b/pkg/api/v1alpha1/zz_generated.deepcopy.go index 3d942f5eb2..4cb34be3f4 100644 --- a/pkg/api/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/api/v1alpha1/zz_generated.deepcopy.go @@ -364,6 +364,13 @@ func (in *RackSpec) DeepCopyInto(out *RackSpec) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.AgentVolumeMounts != nil { + in, out := &in.AgentVolumeMounts, &out.AgentVolumeMounts + *out = make([]corev1.VolumeMount, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RackSpec. diff --git a/pkg/controllers/cluster/resource/resource.go b/pkg/controllers/cluster/resource/resource.go index 38da9044d9..146a239c99 100644 --- a/pkg/controllers/cluster/resource/resource.go +++ b/pkg/controllers/cluster/resource/resource.go @@ -437,7 +437,7 @@ func sysctlInitContainer(sysctls []string) *corev1.Container { } func agentContainer(r scyllav1alpha1.RackSpec, c *scyllav1alpha1.ScyllaCluster) corev1.Container { - return corev1.Container{ + cnt := corev1.Container{ Name: "scylla-manager-agent", Image: agentImageForCluster(c), ImagePullPolicy: "IfNotPresent", @@ -466,6 +466,12 @@ func agentContainer(r scyllav1alpha1.RackSpec, c *scyllav1alpha1.ScyllaCluster) }, Resources: r.AgentResources, } + + for _, vm := range r.AgentVolumeMounts { + cnt.VolumeMounts = append(cnt.VolumeMounts, *vm.DeepCopy()) + } + + return cnt } func ImageForCluster(c *scyllav1alpha1.ScyllaCluster) string {