@@ -44,6 +44,240 @@ var _ = Describe("Cmd", func() {
44
44
"encoding/protobuf/cue/cue.proto" ,
45
45
}
46
46
47
+ {
48
+ type TestEntry struct {
49
+ name string
50
+ values any
51
+ staticVolumes []v1.Volume
52
+ conditionalVolumes []ConditionalVolume
53
+ staticVolumeMounts []v1.VolumeMount
54
+ conditionalVolumeMounts []ConditionalVolumeMount
55
+ }
56
+
57
+ DescribeTable (
58
+ "extraVolume/extraVolumeMounts" ,
59
+ Ordered , func (entry TestEntry , expectedVolumes , expectedVolumeMounts int ) {
60
+ cmd := & Command {
61
+ Chart : & Chart {
62
+ Data : Data {
63
+ ApiVersion : "v1" ,
64
+ Description : "" ,
65
+ Name : "Painting Operator" ,
66
+ Version : "v0.0.1" ,
67
+ Home : "https://docs.solo.io/skv2/latest" ,
68
+ Sources : []string {
69
+ "https://github.com/solo-io/skv2" ,
70
+ },
71
+ },
72
+ Operators : []Operator {{
73
+ Name : "painter" ,
74
+ Deployment : Deployment {
75
+ Container : Container {
76
+ Image : Image {
77
+ Tag : "v0.0.0" ,
78
+ Repository : "painter" ,
79
+ Registry : "quay.io/solo-io" ,
80
+ PullPolicy : "IfNotPresent" ,
81
+ },
82
+ VolumeMounts : entry .staticVolumeMounts ,
83
+ ConditionalVolumeMounts : entry .conditionalVolumeMounts ,
84
+ },
85
+ Volumes : entry .staticVolumes ,
86
+ ConditionalVolumes : entry .conditionalVolumes ,
87
+ },
88
+ }},
89
+ },
90
+ ManifestRoot : fmt .Sprintf ("codegen/test/chart/%s" , entry .name ),
91
+ }
92
+ Expect (cmd .Execute ()).NotTo (HaveOccurred (), "failed to execute command" )
93
+
94
+ manifests := helmTemplate (fmt .Sprintf ("./test/chart/%s" , entry .name ), entry .values )
95
+
96
+ var (
97
+ renderedDeployment * appsv1.Deployment
98
+ decoder = kubeyaml .NewYAMLOrJSONDecoder (bytes .NewBuffer (manifests ), 4096 )
99
+ )
100
+ for {
101
+ var deployment appsv1.Deployment
102
+ if err := decoder .Decode (& deployment ); errors .Is (err , io .EOF ) {
103
+ break
104
+ }
105
+
106
+ if deployment .GetName () == "painter" && deployment .Kind == "Deployment" {
107
+ renderedDeployment = & deployment
108
+ break
109
+ }
110
+ }
111
+
112
+ Expect (renderedDeployment .Spec .Template .Spec .Volumes ).To (HaveLen (expectedVolumes ))
113
+
114
+ Expect (renderedDeployment .Spec .Template .Spec .Containers ).To (HaveLen (1 ))
115
+
116
+ Expect (renderedDeployment .Spec .Template .Spec .Containers [0 ].VolumeMounts ).To (HaveLen (expectedVolumes ))
117
+ },
118
+ Entry (
119
+ "empty with no volumes" ,
120
+ TestEntry {
121
+ name : "extra-volumes" ,
122
+ values : map [string ]any {
123
+ "painter" : map [string ]any {
124
+ "enabled" : true ,
125
+ "extraVolumes" : []v1.Volume {{
126
+ Name : "extra-certs" ,
127
+ VolumeSource : v1.VolumeSource {
128
+ Secret : & v1.SecretVolumeSource {
129
+ SecretName : "extra-secret" ,
130
+ },
131
+ },
132
+ }},
133
+ "extraVolumeMounts" : []v1.VolumeMount {{
134
+ Name : "extra-certs" ,
135
+ MountPath : "/etc/ssl/certs" ,
136
+ }},
137
+ },
138
+ },
139
+ },
140
+ 0 ,
141
+ 0 ,
142
+ ),
143
+ Entry (
144
+ "with static volumes" ,
145
+ TestEntry {
146
+ name : "static-volumes" ,
147
+ values : map [string ]any {
148
+ "painter" : map [string ]any {
149
+ "enabled" : true ,
150
+ "extraVolumes" : []v1.Volume {{
151
+ Name : "extra-certs" ,
152
+ VolumeSource : v1.VolumeSource {
153
+ Secret : & v1.SecretVolumeSource {
154
+ SecretName : "extra-secret" ,
155
+ },
156
+ },
157
+ }},
158
+ "extraVolumeMounts" : []v1.VolumeMount {{
159
+ Name : "extra-certs" ,
160
+ MountPath : "/etc/ssl/extra" ,
161
+ }},
162
+ },
163
+ },
164
+ staticVolumes : []v1.Volume {{
165
+ Name : "static-certs" ,
166
+ VolumeSource : v1.VolumeSource {
167
+ Secret : & v1.SecretVolumeSource {
168
+ SecretName : "static-secret" ,
169
+ },
170
+ },
171
+ }},
172
+ staticVolumeMounts : []v1.VolumeMount {{
173
+ Name : "static-certs" ,
174
+ MountPath : "/var/run/secret/static" ,
175
+ }},
176
+ },
177
+ 2 ,
178
+ 2 ,
179
+ ),
180
+ Entry (
181
+ "with conditional volumes" ,
182
+ TestEntry {
183
+ name : "conditional-volumes" ,
184
+ values : map [string ]any {
185
+ "painter" : map [string ]any {
186
+ "enabled" : true ,
187
+ "extraVolumes" : []v1.Volume {{
188
+ Name : "extra-certs" ,
189
+ VolumeSource : v1.VolumeSource {
190
+ Secret : & v1.SecretVolumeSource {
191
+ SecretName : "extra-secret" ,
192
+ },
193
+ },
194
+ }},
195
+ "extraVolumeMounts" : []v1.VolumeMount {{
196
+ Name : "extra-certs" ,
197
+ MountPath : "/etc/ssl/extra" ,
198
+ }},
199
+ },
200
+ },
201
+ conditionalVolumes : []ConditionalVolume {{
202
+ Condition : ".Values.painter.enabled" ,
203
+ Volume : v1.Volume {
204
+ Name : "conditional-certs" ,
205
+ VolumeSource : v1.VolumeSource {
206
+ Secret : & v1.SecretVolumeSource {
207
+ SecretName : "conditional-secret" ,
208
+ },
209
+ },
210
+ },
211
+ }},
212
+ conditionalVolumeMounts : []ConditionalVolumeMount {{
213
+ Condition : ".Values.painter.enabled" ,
214
+ VolumeMount : v1.VolumeMount {
215
+ Name : "conditional-certs" ,
216
+ MountPath : "/var/run/secret/conditional" ,
217
+ },
218
+ }},
219
+ },
220
+ 2 ,
221
+ 2 ,
222
+ ),
223
+ Entry (
224
+ "with all volumes" ,
225
+ TestEntry {
226
+ name : "all-volumes" ,
227
+ values : map [string ]any {
228
+ "painter" : map [string ]any {
229
+ "enabled" : true ,
230
+ "extraVolumes" : []v1.Volume {{
231
+ Name : "extra-certs" ,
232
+ VolumeSource : v1.VolumeSource {
233
+ Secret : & v1.SecretVolumeSource {
234
+ SecretName : "extra-secret" ,
235
+ },
236
+ },
237
+ }},
238
+ "extraVolumeMounts" : []v1.VolumeMount {{
239
+ Name : "extra-certs" ,
240
+ MountPath : "/etc/ssl/extra" ,
241
+ }},
242
+ },
243
+ },
244
+ staticVolumes : []v1.Volume {{
245
+ Name : "static-certs" ,
246
+ VolumeSource : v1.VolumeSource {
247
+ Secret : & v1.SecretVolumeSource {
248
+ SecretName : "static-secret" ,
249
+ },
250
+ },
251
+ }},
252
+ conditionalVolumes : []ConditionalVolume {{
253
+ Condition : ".Values.painter.enabled" ,
254
+ Volume : v1.Volume {
255
+ Name : "conditional-certs" ,
256
+ VolumeSource : v1.VolumeSource {
257
+ Secret : & v1.SecretVolumeSource {
258
+ SecretName : "conditional-secret" ,
259
+ },
260
+ },
261
+ },
262
+ }},
263
+ staticVolumeMounts : []v1.VolumeMount {{
264
+ Name : "static-certs" ,
265
+ MountPath : "/var/run/secret/static" ,
266
+ }},
267
+ conditionalVolumeMounts : []ConditionalVolumeMount {{
268
+ Condition : ".Values.painter.enabled" ,
269
+ VolumeMount : v1.VolumeMount {
270
+ Name : "conditional-certs" ,
271
+ MountPath : "/var/run/secret/conditional" ,
272
+ },
273
+ }},
274
+ },
275
+ 3 ,
276
+ 3 ,
277
+ ),
278
+ )
279
+ }
280
+
47
281
Describe ("image pull secrets" , Ordered , func () {
48
282
BeforeAll (func () {
49
283
cmd := & Command {
0 commit comments