Skip to content

Commit 8597da0

Browse files
test: add test to verify that crds folder is managed (#3246)
1 parent b0bbf6b commit 8597da0

5 files changed

Lines changed: 81 additions & 0 deletions

File tree

‎pkg/controller/actions/render/helm/action_render_manifests_test.go‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,51 @@ func TestRenderMultipleHelmCharts(t *testing.T) {
180180
))
181181
}
182182

183+
func TestCRDInCrdsDirIsNotTemplated(t *testing.T) {
184+
g := NewWithT(t)
185+
186+
ctx := t.Context()
187+
ns := xid.New().String()
188+
chartDir := filepath.Join("testdata", "with-crds-dir")
189+
190+
action := helm.NewAction(
191+
helm.WithCache(false),
192+
)
193+
194+
rr := types.ReconciliationRequest{
195+
Instance: &ccmv1alpha1.AzureKubernetesEngine{},
196+
HelmCharts: []types.HelmChartInfo{{
197+
Source: helmRenderer.Source{
198+
Chart: chartDir,
199+
ReleaseName: "test-crds-dir",
200+
Values: helmRenderer.Values(map[string]any{
201+
"namespace": ns,
202+
}),
203+
},
204+
}},
205+
}
206+
207+
err := action(ctx, &rr)
208+
209+
g.Expect(err).ShouldNot(HaveOccurred())
210+
g.Expect(rr.Resources).Should(HaveLen(2))
211+
212+
// CRDs from crds/ directory are not template-rendered by the Helm engine,
213+
// they are decoded as raw YAML. They should appear first in the output.
214+
g.Expect(rr.Resources[0]).Should(And(
215+
jq.Match(`.kind == "CustomResourceDefinition"`),
216+
jq.Match(`.metadata.name == "testresources.test.opendatahub.io"`),
217+
))
218+
219+
// Templates from templates/ directory are rendered through the Helm engine
220+
g.Expect(rr.Resources[1]).Should(And(
221+
jq.Match(`.kind == "TestResource"`),
222+
jq.Match(`.metadata.namespace == "%s"`, ns),
223+
jq.Match(`.metadata.name == "test-crds-dir-instance"`),
224+
jq.Match(`.spec.message == "Hello from test-crds-dir"`),
225+
))
226+
}
227+
183228
func TestCRDAndCRRender(t *testing.T) {
184229
g := NewWithT(t)
185230

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
apiVersion: v2
2+
name: with-crds-dir
3+
version: 0.1.0
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: testresources.test.opendatahub.io
5+
spec:
6+
group: test.opendatahub.io
7+
names:
8+
kind: TestResource
9+
listKind: TestResourceList
10+
plural: testresources
11+
singular: testresource
12+
scope: Namespaced
13+
versions:
14+
- name: v1alpha1
15+
served: true
16+
storage: true
17+
schema:
18+
openAPIV3Schema:
19+
type: object
20+
properties:
21+
spec:
22+
type: object
23+
properties:
24+
message:
25+
type: string
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: test.opendatahub.io/v1alpha1
2+
kind: TestResource
3+
metadata:
4+
name: {{ .Release.Name }}-instance
5+
namespace: {{ .Values.namespace }}
6+
spec:
7+
message: "Hello from {{ .Release.Name }}"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
namespace: default

0 commit comments

Comments
 (0)