Skip to content

Commit 1f23292

Browse files
Adding support for ready only volumes
Signed-off-by: Vishesh Tanksale <[email protected]>
1 parent f190a68 commit 1f23292

File tree

4 files changed

+128
-0
lines changed

4 files changed

+128
-0
lines changed

api/apps/v1alpha1/nimservice_types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ func (n *NIMService) GetVolumes(modelPVC PersistentVolumeClaim) []corev1.Volume
408408
VolumeSource: corev1.VolumeSource{
409409
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
410410
ClaimName: modelPVC.Name,
411+
ReadOnly: n.GetStorageReadOnly(),
411412
},
412413
},
413414
},
@@ -508,6 +509,14 @@ func (n *NIMService) GetGroupID() *int64 {
508509

509510
}
510511

512+
// GetGroupID returns the group ID for the NIMService deployment
513+
func (n *NIMService) GetStorageReadOnly() bool {
514+
if n.Spec.Storage.ReadOnly == nil {
515+
return false
516+
}
517+
return *n.Spec.Storage.ReadOnly
518+
}
519+
511520
// GetServiceAccountParams return params to render ServiceAccount from templates
512521
func (n *NIMService) GetServiceAccountParams() *rendertypes.ServiceAccountParams {
513522
params := &rendertypes.ServiceAccountParams{}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
Copyright 2024.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
"reflect"
21+
"testing"
22+
23+
corev1 "k8s.io/api/core/v1"
24+
)
25+
26+
// TestGetVolumes tests the GetVolumes function.
27+
func TestGetVolumes(t *testing.T) {
28+
tests := []struct {
29+
name string
30+
modelPVC PersistentVolumeClaim
31+
desired []corev1.Volume
32+
nimService *NIMService
33+
}{
34+
{
35+
name: "Storage read only is nil",
36+
nimService: &NIMService{Spec: NIMServiceSpec{Storage: NIMServiceStorage{}}},
37+
modelPVC: PersistentVolumeClaim{Name: "test-pvc"},
38+
desired: []corev1.Volume{
39+
{
40+
Name: "dshm",
41+
VolumeSource: corev1.VolumeSource{
42+
EmptyDir: &corev1.EmptyDirVolumeSource{
43+
Medium: corev1.StorageMediumMemory,
44+
},
45+
},
46+
},
47+
{
48+
Name: "model-store",
49+
VolumeSource: corev1.VolumeSource{
50+
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
51+
ClaimName: "test-pvc",
52+
ReadOnly: false,
53+
},
54+
},
55+
},
56+
},
57+
},
58+
{
59+
name: "Storage read only is false",
60+
nimService: &NIMService{Spec: NIMServiceSpec{Storage: NIMServiceStorage{ReadOnly: &[]bool{false}[0]}}},
61+
modelPVC: PersistentVolumeClaim{Name: "test-pvc"},
62+
desired: []corev1.Volume{
63+
{
64+
Name: "dshm",
65+
VolumeSource: corev1.VolumeSource{
66+
EmptyDir: &corev1.EmptyDirVolumeSource{
67+
Medium: corev1.StorageMediumMemory,
68+
},
69+
},
70+
},
71+
{
72+
Name: "model-store",
73+
VolumeSource: corev1.VolumeSource{
74+
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
75+
ClaimName: "test-pvc",
76+
ReadOnly: false,
77+
},
78+
},
79+
},
80+
},
81+
},
82+
{
83+
name: "Storage read only is true",
84+
nimService: &NIMService{Spec: NIMServiceSpec{Storage: NIMServiceStorage{ReadOnly: &[]bool{true}[0]}}},
85+
modelPVC: PersistentVolumeClaim{Name: "test-pvc"},
86+
desired: []corev1.Volume{
87+
{
88+
Name: "dshm",
89+
VolumeSource: corev1.VolumeSource{
90+
EmptyDir: &corev1.EmptyDirVolumeSource{
91+
Medium: corev1.StorageMediumMemory,
92+
},
93+
},
94+
},
95+
{
96+
Name: "model-store",
97+
VolumeSource: corev1.VolumeSource{
98+
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
99+
ClaimName: "test-pvc",
100+
ReadOnly: true,
101+
},
102+
},
103+
},
104+
},
105+
},
106+
}
107+
108+
for _, tt := range tests {
109+
t.Run(tt.name, func(t *testing.T) {
110+
vols := tt.nimService.GetVolumes(tt.modelPVC)
111+
if !reflect.DeepEqual(vols, tt.desired) {
112+
t.Errorf("GetVolumes() = %v, want %v", vols, tt.desired)
113+
}
114+
})
115+
}
116+
117+
}

internal/controller/platform/standalone/nimservice_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ var _ = Describe("NIMServiceReconciler for a standalone platform", func() {
226226
VolumeSource: corev1.VolumeSource{
227227
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
228228
ClaimName: "test-pvc",
229+
ReadOnly: false,
229230
},
230231
},
231232
},

manifests/deployment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ spec:
7676
{{- if .PersistentVolumeClaim }}
7777
persistentVolumeClaim:
7878
claimName: {{ .PersistentVolumeClaim.ClaimName }}
79+
readOnly: {{ .PersistentVolumeClaim.ReadOnly }}
7980
{{- end }}
8081
{{- if .HostPath }}
8182
hostPath:

0 commit comments

Comments
 (0)