Skip to content

Commit 43680a0

Browse files
authored
Add support for extraVolumes/extraVolumeMounts (#583)
* Add support for `extraVolumes/extraVolumeMounts` * changelog
1 parent 4f24776 commit 43680a0

File tree

26 files changed

+1212
-7
lines changed

26 files changed

+1212
-7
lines changed

Makefile

+14-5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ install-go-tools: mod-download
2323
go install github.com/golang/mock/[email protected]
2424
go install github.com/onsi/ginkgo/v2/[email protected]
2525
go install golang.org/x/tools/cmd/goimports
26+
go install sigs.k8s.io/kind/cmd/[email protected]
2627

2728
# proto compiler installation
2829
PROTOC_VERSION:=3.15.8
@@ -74,18 +75,26 @@ generate-changelog:
7475
# set TEST_PKG to run a specific test package
7576
.PHONY: run-tests
7677
run-tests:
77-
PATH=$(DEPSGOBIN):$$PATH ginkgo -r -failFast -trace -progress \
78-
-progress \
78+
PATH=$(DEPSGOBIN):$$PATH ginkgo -r --fail-fast -trace \
79+
--show-node-events \
7980
-compilers=4 \
80-
-skipPackage=$(SKIP_PACKAGES) $(TEST_PKG) \
81+
$(GINKGO_FLAGS) \
82+
--skip-package=$(SKIP_PACKAGES) $(TEST_PKG) \
8183
-failOnPending \
8284
-randomizeAllSpecs \
8385
-randomizeSuites \
8486
-keepGoing
8587
$(DEPSGOBIN)/goimports -w .
8688

87-
run-test:
88-
PATH=$(DEPSGOBIN):$$PATH ginkgo $(GINKGO_FLAGS) $(TEST_PKG)
89+
test-clusters:
90+
@kind create cluster --name skv2-test-master 2> /dev/null || true
91+
@kind create cluster --name skv2-test-remote 2> /dev/null || true
92+
93+
# CI workflow for running tests
94+
run-all: REMOTE_CLUSTER_CONTEXT ?= kind-skv2-test-remote
95+
run-all: test-clusters
96+
@go test ./...
97+
@goimports -w .
8998

9099
#----------------------------------------------------------------------------------
91100
# Third Party License Management

changelog/v0.40.7/issue-582.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
changelog:
2+
- type: NEW_FEATURE
3+
issueLink: https://github.com/solo-io/skv2/issues/582
4+
description: >
5+
Support extraVolumes/extraVolumeMounts fields which can be passed in by the user from helm values.
6+
skipCI: "false"

codegen/cmd_test.go

+234
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,240 @@ var _ = Describe("Cmd", func() {
4444
"encoding/protobuf/cue/cue.proto",
4545
}
4646

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+
47281
Describe("image pull secrets", Ordered, func() {
48282
BeforeAll(func() {
49283
cmd := &Command{

codegen/templates/chart/operator-deployment.yamltmpl

+14-2
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,15 @@ spec:
105105
[[- end ]]
106106
[[- if $volumes ]]
107107
volumes:
108-
[[ toYaml $volumes | indent 6 ]]
108+
[[- toYaml $volumes | nindent 6 ]]
109+
{{- if [[ (opVar $operator) ]].extraVolumes }}
110+
{{- tpl (toYaml [[ (opVar $operator) ]].extraVolumes) . | nindent 6 }}
111+
{{- end }}
109112
[[- else if $conditionalVolumes ]]
110113
volumes:
114+
{{- if [[ (opVar $operator) ]].extraVolumes }}
115+
{{- tpl (toYaml [[ (opVar $operator) ]].extraVolumes) . | nindent 6 }}
116+
{{- end }}
111117
[[- end ]]
112118
[[- range $v := $conditionalVolumes ]]
113119
{{- if [[ $v.Condition ]] }}
@@ -178,9 +184,15 @@ spec:
178184
{{- end }}
179185
[[- if $container.VolumeMounts ]]
180186
volumeMounts:
181-
[[ toYaml $container.VolumeMounts | indent 8 ]]
187+
[[- toYaml $container.VolumeMounts | nindent 8 ]]
188+
{{- if [[ (opVar $operator) ]].extraVolumeMounts }}
189+
{{- tpl (toYaml [[ (opVar $operator) ]].extraVolumeMounts) . | nindent 8 }}
190+
{{- end }}
182191
[[- else if $container.ConditionalVolumeMounts ]]
183192
volumeMounts:
193+
{{- if [[ (opVar $operator) ]].extraVolumeMounts }}
194+
{{- tpl (toYaml [[ (opVar $operator) ]].extraVolumeMounts) . | nindent 8 }}
195+
{{- end }}
184196
[[- end ]]
185197
[[- range $v := $container.ConditionalVolumeMounts ]]
186198
{{- if [[ $v.Condition ]] }}

codegen/test/chart-no-desc/templates/deployment.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ spec:
4242
volumes:
4343
- emptyDir: {}
4444
name: paint
45+
{{- if $.Values.painter.extraVolumes }}
46+
{{- tpl (toYaml $.Values.painter.extraVolumes) . | nindent 6 }}
47+
{{- end }}
4548
containers:
4649
{{- $painter := $.Values.painter }}
4750
{{- $painterImage := $painter.image }}
@@ -116,6 +119,9 @@ spec:
116119
volumeMounts:
117120
- mountPath: /etc/paint
118121
name: paint
122+
{{- if $.Values.painter.extraVolumeMounts }}
123+
{{- tpl (toYaml $.Values.painter.extraVolumeMounts) . | nindent 8 }}
124+
{{- end }}
119125
resources:
120126
{{- if $palette.resources }}
121127
{{ toYaml $palette.resources | indent 10}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Code generated by skv2. DO NOT EDIT.
2+
3+
apiVersion: v1
4+
home: https://docs.solo.io/skv2/latest
5+
name: Painting Operator
6+
sources:
7+
- https://github.com/solo-io/skv2
8+
version: v0.0.1

0 commit comments

Comments
 (0)