Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added option to use emptyDir as additional mount #512

Merged
merged 5 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
54 changes: 54 additions & 0 deletions docs/designs/crd.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ GeneralConfig defines global Opensearch cluster configuration
<td>Snapshot Repo settings</td>
<td>false</td>
<td> - </td>
</tr><tr>
<td><b>additionalVolumes</b></td>
<td>[]object</td>
<td>List of additional volume mounts</td>
<td>false</td>
<td>-</td>
</tr>
</table>

Expand Down Expand Up @@ -676,3 +682,51 @@ Every Keystore Value defines a secret to pull secrets from.
</tr>
</tbody>
</table>

<h3 id="GeneralConfig">
AdditionalVolume
</h3>

AdditionalVolume object define additional volume and volumeMount
<table>
<tbody>
<tr>
<td><b>name</b></td>
<td>string</td>
<td>Defines name for additional volume</td>
<td>true</td>
<td>-</td>
</tr><tr>
<td><b>path</b></td>
<td>string</td>
<td>Defines mount path for additional volume</td>
<td>true</td>
<td>-</td>
</tr><tr>
<td><b>restartPods</b></td>
<td>bool</td>
<td>Defines if pod should restar or not in case of change in VolumeSource object</td>
<td>false</td>
<td>false</td>
</tr><tr>
<td><b>emptyDir</b></td>
<td>corev1.EmptyDirVolumeSource</td>
<td>Defines emptyDir object to be mouted</td>
<td>false</td>
<td>-</td>
</tr><tr>
<td><b>configMap</b></td>
<td>corev1.ConfigMapVolumeSource</td>
<td>Defines ConfgMap object to be mounted</td>
<td>false</td>
<td>-</td>
</tr><tr>
<td><b>secret</b></td>
<td>corev1.SecretVolumeSource</td>
<td>Defines Secret object to be mounted</td>
<td>false</td>
<td>-</td>
</tr>
</tbody>
</table>

5 changes: 4 additions & 1 deletion docs/userguide/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions opensearch-operator/api/v1/opensearch_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down
5 changes: 5 additions & 0 deletions opensearch-operator/api/v1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions opensearch-operator/controllers/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ var _ = Describe("Cluster Reconciler", func() {
HaveVolumeMounts(
"test-secret",
"test-cm",
"test-emptydir",
),
)),
HaveMatchingVolume(And(
Expand All @@ -182,6 +183,10 @@ var _ = Describe("Cluster Reconciler", func() {
HaveName("test-cm"),
HaveVolumeSource("ConfigMap"),
)),
HaveMatchingVolume(And(
HaveName("test-emptydir"),
HaveVolumeSource("EmptyDir"),
)),
))
}(nodePool)
}
Expand Down
6 changes: 6 additions & 0 deletions opensearch-operator/controllers/suite_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 11 additions & 1 deletion opensearch-operator/pkg/reconcilers/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
})
}
Expand Down
Loading