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

Add support for adding PVC volumes as Additional Volumes #852

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
14 changes: 2 additions & 12 deletions charts/opensearch-cluster/templates/opensearch-cluster-cr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@ spec:
{{- end}}
{{- if .Values.opensearchCluster.general.additionalVolumes }}
additionalVolumes:
{{- range $key, $val := .Values.opensearchCluster.general.additionalVolumes }}
- name: {{ $val.name }}
path: {{ $val.path }}
secret:
secretName: {{ $val.secret.secretName }}
{{- end -}}
{{ toYaml .Values.opensearchCluster.general.additionalVolumes | nindent 6 }}
{{- end }}
{{- if .Values.opensearchCluster.general.additionalConfig }}
additionalConfig:
Expand Down Expand Up @@ -167,12 +162,7 @@ spec:
{{- end}}
{{- if .Values.opensearchCluster.dashboards.additionalVolumes }}
additionalVolumes:
{{- range $key,$val := .Values.opensearchCluster.dashboards.additionalVolumes }}
- name: {{ $val.name }}
path: {{ $val.path }}
secret:
secretName: {{ $val.secretName.name }}
{{- end }}
{{ toYaml .Values.opensearchCluster.dashboards.additionalVolumes | nindent 6 }}
{{- end }}
{{- if .Values.opensearchCluster.dashboards.additionalConfig }}
additionalConfig:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,20 @@ spec:
description: Path in the container to mount the volume at.
Required.
type: string
persistentVolumeClaim:
description: PersistentVolumeClaim object to use to populate the volume
properties:
claimName:
description: |-
The name of a PersistentVolumeClaim in the same namespace as the pod using this volume.
More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims
type: string
readOnly:
description: |-
Will force the ReadOnly setting in VolumeMounts.
Default false.
type: boolean
type: object
projected:
description: Projected object to use to populate the volume
properties:
Expand Down Expand Up @@ -3005,6 +3019,20 @@ spec:
description: Path in the container to mount the volume at.
Required.
type: string
persistentVolumeClaim:
description: PersistentVolumeClaim object to use to populate the volume
properties:
claimName:
description: |-
The name of a PersistentVolumeClaim in the same namespace as the pod using this volume.
More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims
type: string
readOnly:
description: |-
Will force the ReadOnly setting in VolumeMounts.
Default false.
type: boolean
type: object
projected:
description: Projected object to use to populate the volume
properties:
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 @@ -296,6 +296,8 @@ type AdditionalVolume struct {
EmptyDir *corev1.EmptyDirVolumeSource `json:"emptyDir,omitempty"`
// CSI object to use to populate the volume
CSI *corev1.CSIVolumeSource `json:"csi,omitempty"`
// Persistent object to use to populate the volume
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Persistent object to use to populate the volume
// PersistentVolumeClaim object to use to populate the volume

PersistentVolumeClaim *corev1.PersistentVolumeClaimVolumeSource `json:"persistentVolumeClaim,omitempty"`
// Projected object to use to populate the volume
Projected *corev1.ProjectedVolumeSource `json:"projected,omitempty"`
// Whether to restart the pods on content change
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 @@ -1098,6 +1098,22 @@ spec:
description: Path in the container to mount the volume at.
Required.
type: string
persistentVolumeClaim:
description: Persistent object to use to populate the volume
properties:
claimName:
description: |-
claimName is the name of a PersistentVolumeClaim in the same namespace as the pod using this volume.
More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims
type: string
readOnly:
description: |-
readOnly Will force the ReadOnly setting in VolumeMounts.
Default false.
type: boolean
required:
- claimName
type: object
projected:
description: Projected object to use to populate the volume
properties:
Expand Down Expand Up @@ -3005,6 +3021,22 @@ spec:
description: Path in the container to mount the volume at.
Required.
type: string
persistentVolumeClaim:
description: Persistent object to use to populate the volume
properties:
claimName:
description: |-
claimName is the name of a PersistentVolumeClaim in the same namespace as the pod using this volume.
More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims
type: string
readOnly:
description: |-
readOnly Will force the ReadOnly setting in VolumeMounts.
Default false.
type: boolean
required:
- claimName
type: object
projected:
description: Projected object to use to populate the volume
properties:
Expand Down
9 changes: 9 additions & 0 deletions opensearch-operator/pkg/reconcilers/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ func CreateAdditionalVolumes(
},
})
}
if volumeConfig.PersistentVolumeClaim != nil {
readOnly = volumeConfig.PersistentVolumeClaim.ReadOnly
retVolumes = append(retVolumes, corev1.Volume{
Name: volumeConfig.Name,
VolumeSource: corev1.VolumeSource{
PersistentVolumeClaim: volumeConfig.PersistentVolumeClaim,
},
})
}
if volumeConfig.Projected != nil {
retVolumes = append(retVolumes, corev1.Volume{
Name: volumeConfig.Name,
Expand Down
14 changes: 14 additions & 0 deletions opensearch-operator/pkg/reconcilers/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ var _ = Describe("Additional volumes", func() {
})
})

When("PersistentVolumeClaim volume is added", func() {
It("Should have PersistentVolumeClaimVolumeSource fields", func() {
readOnly := true
volumeConfigs[0].PersistentVolumeClaim = &v1.PersistentVolumeClaimVolumeSource{
ClaimName: "testClaim",
ReadOnly: readOnly,
}

volume, _, _, _ := CreateAdditionalVolumes(mockClient, namespace, volumeConfigs)
Expect(volume[0].PersistentVolumeClaim.ClaimName).To(Equal("testClaim"))
Expect(volume[0].PersistentVolumeClaim.ReadOnly).Should(BeTrue())
})
})

When("Projected volume is added", func() {
It("Should have ProjectedVolumeSource fields", func() {
volumeConfigs[0].Projected = &v1.ProjectedVolumeSource{
Expand Down
Loading