Skip to content

Commit

Permalink
Allow non readOnly CSI additionalVolumes (#937)
Browse files Browse the repository at this point in the history
### Description
Allow additionalVolumes with flag `readOnly: false` as per CSI setting.
Currently, all CSI driver volumes are hardcoded to `readOnly: true`

### Issues Resolved
Closing:
#934

### Check List
- [x] Commits are signed per the DCO using --signoff 
- [x] Unittest added for the new/changed functionality and all unit
tests are successful
- [ ] Customer-visible features documented (not applicable)
- [x] No linter warnings (`make lint`)

If CRDs are changed:  (not applicable)
- [ ] CRD YAMLs updated (`make manifests`) and also copied into the helm
chart
- [ ] Changes to CRDs documented

Please refer to the [PR
guidelines](https://github.com/opensearch-project/opensearch-k8s-operator/blob/main/docs/developing.md#submitting-a-pr)
before submitting this pull request.

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and
signing off your commits, please check
[here](https://github.com/opensearch-project/OpenSearch/blob/main/CONTRIBUTING.md#developer-certificate-of-origin).

Signed-off-by: Roman Krewer <roman.krewer.rk@gmail.com>
  • Loading branch information
jurox83 authored Jan 13, 2025
1 parent d831add commit 203862b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions opensearch-operator/pkg/reconcilers/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ func CreateAdditionalVolumes(
})
}
if volumeConfig.CSI != nil {
if volumeConfig.CSI.ReadOnly != nil {
readOnly = *volumeConfig.CSI.ReadOnly
}
retVolumes = append(retVolumes, corev1.Volume{
Name: volumeConfig.Name,
VolumeSource: corev1.VolumeSource{
Expand Down
24 changes: 23 additions & 1 deletion opensearch-operator/pkg/reconcilers/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ var _ = Describe("Additional volumes", func() {
})
})

When("CSI volume is added", func() {
When("CSI readOnly volume is added", func() {
It("Should have CSIVolumeSource fields", func() {
readOnly := true
volumeConfigs[0].CSI = &v1.CSIVolumeSource{
Expand All @@ -111,6 +111,28 @@ var _ = Describe("Additional volumes", func() {
})
})

When("CSI read-write volume is added", func() {
It("Should have CSIVolumeSource fields", func() {
readOnly := false
volumeConfigs[0].CSI = &v1.CSIVolumeSource{
Driver: "testDriver",
ReadOnly: &readOnly,
VolumeAttributes: map[string]string{
"secretProviderClass": "testSecretProviderClass",
},
NodePublishSecretRef: &v1.LocalObjectReference{
Name: "testSecret",
},
}

volume, _, _, _ := CreateAdditionalVolumes(mockClient, namespace, volumeConfigs)
Expect(volume[0].CSI.Driver).To(Equal("testDriver"))
Expect(*volume[0].CSI.ReadOnly).Should(BeFalse())
Expect(volume[0].CSI.VolumeAttributes["secretProviderClass"]).To(Equal("testSecretProviderClass"))
Expect(volume[0].CSI.NodePublishSecretRef.Name).To(Equal("testSecret"))
})
})

When("CSI volume is added with subPath", func() {
It("Should have the subPath", func() {
volumeConfigs[0].CSI = &v1.CSIVolumeSource{}
Expand Down

0 comments on commit 203862b

Please sign in to comment.