diff --git a/charts/opensearch-operator/files/opensearch.opster.io_opensearchclusters.yaml b/charts/opensearch-operator/files/opensearch.opster.io_opensearchclusters.yaml index 40c42040..774f7eb0 100644 --- a/charts/opensearch-operator/files/opensearch.opster.io_opensearchclusters.yaml +++ b/charts/opensearch-operator/files/opensearch.opster.io_opensearchclusters.yaml @@ -1042,6 +1042,16 @@ spec: additionalVolumes: items: properties: + emptyDir: + description: emptyDir to use to populate the volume + type: object + properties: + sizeLimit: + description: Total amount of local storage required for this EmptyDir volume + type: string + medium: + description: hat type of storage medium should back this directory + type: string configMap: description: ConfigMap to use to populate the volume properties: @@ -2727,6 +2737,16 @@ spec: description: Additional volumes to mount to all pods in the cluster items: properties: + emptyDir: + description: emptyDir to use to populate the volume + properties: + sizeLimit: + description: Total amount of local storage required for this EmptyDir volume + type: string + medium: + description: hat type of storage medium should back this directory + type: string + type: object configMap: description: ConfigMap to use to populate the volume properties: diff --git a/docs/designs/crd.md b/docs/designs/crd.md index c5b1b567..b28bd6fc 100644 --- a/docs/designs/crd.md +++ b/docs/designs/crd.md @@ -221,6 +221,12 @@ GeneralConfig defines global Opensearch cluster configuration Snapshot Repo settings false - + + additionalVolumes + []object + List of additional volume mounts + false + - @@ -676,3 +682,51 @@ Every Keystore Value defines a secret to pull secrets from. + +

+ AdditionalVolume +

+ +AdditionalVolume object define additional volume and volumeMount + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
namestringDefines name for additional volumetrue-
pathstringDefines mount path for additional volumetrue-
restartPodsboolDefines if pod should restar or not in case of change in VolumeSource objectfalsefalse
emptyDircorev1.EmptyDirVolumeSourceDefines emptyDir object to be moutedfalse-
configMapcorev1.ConfigMapVolumeSourceDefines ConfgMap object to be mountedfalse-
secretcorev1.SecretVolumeSourceDefines Secret object to be mountedfalse-
+ diff --git a/docs/userguide/main.md b/docs/userguide/main.md index 2601ce2f..108a29fc 100644 --- a/docs/userguide/main.md +++ b/docs/userguide/main.md @@ -694,7 +694,7 @@ spec: ### Additional Volumes -Sometimes it is neccessary to mount ConfigMaps or Secrets into the Opensearch pods as volumes to provide additional configuration (e.g. plugin config files). This can be achieved by providing an array of additional volumes to mount to the custom resource. This option is located in either `spec.general.additionalVolumes` or `spec.dashboards.additionalVolumes`. The format is as follows: +Sometimes it is neccessary to mount ConfigMaps, Secrets or emptyDir into the Opensearch pods as volumes to provide additional configuration (e.g. plugin config files). This can be achieved by providing an array of additional volumes to mount to the custom resource. This option is located in either `spec.general.additionalVolumes` or `spec.dashboards.additionalVolumes`. The format is as follows: ```yaml spec: @@ -705,6 +705,9 @@ spec: configMap: name: config-map-name restartPods: true #set this to true to restart the pods when the content of the configMap changes + - name: temp + path: /tmp + emptyDir: {} dashboards: additionalVolumes: - name: example-secret diff --git a/opensearch-operator/api/v1/opensearch_types.go b/opensearch-operator/api/v1/opensearch_types.go index f3b07d41..2f24eff6 100644 --- a/opensearch-operator/api/v1/opensearch_types.go +++ b/opensearch-operator/api/v1/opensearch_types.go @@ -240,6 +240,8 @@ type AdditionalVolume struct { Secret *corev1.SecretVolumeSource `json:"secret,omitempty"` // ConfigMap to use to populate the volume ConfigMap *corev1.ConfigMapVolumeSource `json:"configMap,omitempty"` + // EmptyDir to use to populate the volume + EmptyDir *corev1.EmptyDirVolumeSource `json:"emptyDir,omitempty"` // Whether to restart the pods on content change RestartPods bool `json:"restartPods,omitempty"` } diff --git a/opensearch-operator/api/v1/zz_generated.deepcopy.go b/opensearch-operator/api/v1/zz_generated.deepcopy.go index a2912738..1fcaa7b9 100644 --- a/opensearch-operator/api/v1/zz_generated.deepcopy.go +++ b/opensearch-operator/api/v1/zz_generated.deepcopy.go @@ -40,6 +40,11 @@ func (in *AdditionalVolume) DeepCopyInto(out *AdditionalVolume) { *out = new(corev1.ConfigMapVolumeSource) (*in).DeepCopyInto(*out) } + if in.EmptyDir != nil { + in, out := &in.EmptyDir, &out.EmptyDir + *out = new(corev1.EmptyDirVolumeSource) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AdditionalVolume. diff --git a/opensearch-operator/config/crd/bases/opensearch.opster.io_opensearchclusters.yaml b/opensearch-operator/config/crd/bases/opensearch.opster.io_opensearchclusters.yaml index 40c42040..175216c1 100644 --- a/opensearch-operator/config/crd/bases/opensearch.opster.io_opensearchclusters.yaml +++ b/opensearch-operator/config/crd/bases/opensearch.opster.io_opensearchclusters.yaml @@ -1042,6 +1042,16 @@ spec: additionalVolumes: items: properties: + emptyDir: + description: emptyDir to use to populate the volume + type: object + properties: + sizeLimit: + description: Total amount of local storage required for this EmptyDir volume + type: string + medium: + description: hat type of storage medium should back this directory + type: string configMap: description: ConfigMap to use to populate the volume properties: @@ -2727,6 +2737,16 @@ spec: description: Additional volumes to mount to all pods in the cluster items: properties: + emptyDir: + description: emptyDir to use to populate the volume + type: object + properties: + sizeLimit: + description: Total amount of local storage required for this EmptyDir volume + type: string + medium: + description: hat type of storage medium should back this directory + type: string configMap: description: ConfigMap to use to populate the volume properties: diff --git a/opensearch-operator/controllers/cluster_test.go b/opensearch-operator/controllers/cluster_test.go index a4298f38..749d59f3 100644 --- a/opensearch-operator/controllers/cluster_test.go +++ b/opensearch-operator/controllers/cluster_test.go @@ -172,6 +172,7 @@ var _ = Describe("Cluster Reconciler", func() { HaveVolumeMounts( "test-secret", "test-cm", + "test-emptydir", ), )), HaveMatchingVolume(And( @@ -182,6 +183,10 @@ var _ = Describe("Cluster Reconciler", func() { HaveName("test-cm"), HaveVolumeSource("ConfigMap"), )), + HaveMatchingVolume(And( + HaveName("test-emptydir"), + HaveVolumeSource("EmptyDir"), + )), )) }(nodePool) } diff --git a/opensearch-operator/controllers/suite_test_helpers.go b/opensearch-operator/controllers/suite_test_helpers.go index cdc28671..3b42cf2d 100644 --- a/opensearch-operator/controllers/suite_test_helpers.go +++ b/opensearch-operator/controllers/suite_test_helpers.go @@ -123,6 +123,12 @@ func ComposeOpensearchCrd(clusterName string, namespace string) opsterv1.OpenSea }, RestartPods: false, }, + { + Name: "test-emptydir", + Path: "/tmp/", + EmptyDir: &corev1.EmptyDirVolumeSource{}, + RestartPods: false, + }, { Name: "test-cm", Path: "/opt/test-cm", diff --git a/opensearch-operator/pkg/reconcilers/util/util.go b/opensearch-operator/pkg/reconcilers/util/util.go index 02c1616f..6998eb33 100644 --- a/opensearch-operator/pkg/reconcilers/util/util.go +++ b/opensearch-operator/pkg/reconcilers/util/util.go @@ -98,6 +98,7 @@ func CreateAdditionalVolumes( namesIndex := map[string]int{} for i, volumeConfig := range volumeConfigs { + readOnly := true if volumeConfig.ConfigMap != nil { retVolumes = append(retVolumes, corev1.Volume{ Name: volumeConfig.Name, @@ -114,13 +115,22 @@ func CreateAdditionalVolumes( }, }) } + if volumeConfig.EmptyDir != nil { + readOnly = false + retVolumes = append(retVolumes, corev1.Volume{ + Name: volumeConfig.Name, + VolumeSource: corev1.VolumeSource{ + EmptyDir: volumeConfig.EmptyDir, + }, + }) + } if volumeConfig.RestartPods { namesIndex[volumeConfig.Name] = i names = append(names, volumeConfig.Name) } retVolumeMounts = append(retVolumeMounts, corev1.VolumeMount{ Name: volumeConfig.Name, - ReadOnly: true, + ReadOnly: readOnly, MountPath: volumeConfig.Path, }) }