-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile.test
241 lines (211 loc) · 12.3 KB
/
Makefile.test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# This makefile holds "end-to-end" tests, i.e. function usage with kpt and real manifest manipulation
FN_MODE ?= exec
ifeq ($(CONTAINER_TAG),)
APPLY_SETTERS_IMAGE := ghcr.io/krm-functions/apply-setters@sha256:18c6f1b3ad30ed6599ff13388e9632945fcb2d32d26c7284235b85c3c295de78
DIGESTER_IMAGE := ghcr.io/krm-functions/digester@sha256:f08710681314ca57a308ef8b5b0f373e2be0468c1ae83faf98e4f1b0f7f22834
HELM_RENDER_IMAGE := ghcr.io/krm-functions/render-helm-chart@sha256:2594819377e5409a053db7a903f76ae9ac64622c7daf361bbafa1fd28cc9f9db
HELM_SOURCE_IMAGE := ghcr.io/krm-functions/source-helm-chart@sha256:1ec2a7070b7b0d01dd8c457299887c1d751bb148c5ec0317f9945e94782f8679
HELM_UPGRADER_IMAGE := ghcr.io/krm-functions/helm-upgrader@sha256:8a31e20c5a02eb992d67b1705aea4bb9eeefe4c93b0bf9d95677584180b04062
KUBECONFORM_IMAGE := ghcr.io/krm-functions/kubeconform@sha256:aab67e8b52eebd95cb068314818bbc3b05059ff3b71d3de84a661a1df4718b73
SOURCE_PACKAGES_IMAGE := ghcr.io/krm-functions/source-packages@sha256:30e52b8976e867d50d0a1745e2577c806790987befb477e3ca8ea53bd0aa3859
else
APPLY_SETTERS_IMAGE := ghcr.io/krm-functions/apply-setters:$(CONTAINER_TAG)
DIGESTER_IMAGE := ghcr.io/krm-functions/digester:$(CONTAINER_TAG)
HELM_RENDER_IMAGE := ghcr.io/krm-functions/render-helm-chart:$(CONTAINER_TAG)
HELM_SOURCE_IMAGE := ghcr.io/krm-functions/source-helm-chart:$(CONTAINER_TAG)
HELM_UPGRADER_IMAGE := ghcr.io/krm-functions/helm-upgrader:$(CONTAINER_TAG)
KUBECONFORM_IMAGE := ghcr.io/krm-functions/kubeconform:$(CONTAINER_TAG)
SOURCE_PACKAGES_IMAGE := ghcr.io/krm-functions/source-packages:$(CONTAINER_TAG)
endif
ifeq ($(FN_MODE),exec)
APPLY_SETTERS := --exec bin/linux_amd64/apply-setters
DIGESTER := --exec bin/linux_amd64/digester
HELM_RENDER := --exec bin/linux_amd64/render-helm-chart
HELM_SOURCE := --exec bin/linux_amd64/source-helm-chart
HELM_UPGRADER := --exec bin/linux_amd64/helm-upgrader
KUBECONFORM := --exec bin/linux_amd64/kubeconform
TEMPLATE_KYAML := --exec bin/linux_amd64/template-kyaml
SOURCE_PACKAGES := --exec bin/linux_amd64/source-packages
else
APPLY_SETTERS := --image $(APPLY_SETTERS_IMAGE)
DIGESTER := --network --image $(DIGESTER_IMAGE)
HELM_RENDER := --network --image $(HELM_RENDER_IMAGE)
HELM_SOURCE := --network --image $(HELM_SOURCE_IMAGE)
HELM_UPGRADER := --network --image $(HELM_UPGRADER_IMAGE)
KUBECONFORM := --network --image $(KUBECONFORM_IMAGE)
SOURCE_PACKAGES := --network --image $(SOURCE_PACKAGES_IMAGE)
endif
BASELINE_RENDER_HELM_CHART := gcr.io/kpt-fn/render-helm-chart:v0.2.2
e2e-tests: test-render-helm-chart \
render-helm-chart-example \
render-helm-chart-example2 \
render-with-kube-version \
test-source-helm-chart \
test-helm-upgrader \
test-apply-setters \
test-digester \
test-kubeconform \
test-source-packages-e2e
# BEWARE: These tests are fragile - we want to test upgrades, but without upgrade-constraints tests might fail when charts are updated
.PHONY: test-helm-upgrader
test-helm-upgrader:
rm -rf tmp-results
kpt fn source examples/helm-upgrader | kpt fn eval - --fn-config example-function-configs/config-upgrade-helm-version-inline.yaml --truncate-output=false --results-dir tmp-results $(HELM_UPGRADER) > test-out.txt
grep -e '.*upgrade-available: .*cert-manager:v1.8.2' test-out.txt
grep -e '.*upgrade-available.0: .*cert-manager:v1.12.1' test-out.txt
grep -e '.*upgrade-available.0: .*metacontroller-helm:v4.10.0' test-out.txt
grep -e '.*upgrade-available.0: .*karpenter:0.35.0' test-out.txt
grep -e '.*upgrade-available.1: .*/external-secrets:0.10.5' test-out.txt
rm test-out.txt
rm -rf tmp-results
.PHONY: test-render-helm-chart
test-render-helm-chart:
# For reference, render chart using baseline function
rm -rf rendered-output
echo "" | kpt fn eval - --network --fn-config examples/render-helm-chart2/argo-workflows.yaml -i ${BASELINE_RENDER_HELM_CHART} | kpt fn sink rendered-output
# Source step, fetch chart from upstream, but do not render
rm -rf sourced-output
kpt fn source examples/render-helm-chart2 | kpt fn eval - ${HELM_RENDER} --results-dir results2 | kpt fn sink sourced-output
grep -e 'message: sourcing with render-helm-chart is deprecated' results2/results.yaml
# Render from previously sourced chart
rm -rf rendered-output2
kpt fn source sourced-output | kpt fn eval - ${HELM_RENDER} | kpt fn sink rendered-output2
diff -q rendered-output rendered-output2
rm -rf rendered-output sourced-output rendered-output2 results2
# Example usage from docs/render-helm-chart.md
.PHONY: render-helm-chart-example
render-helm-chart-example:
kpt fn source examples/render-helm-chart | kpt fn eval - ${HELM_SOURCE} | kpt fn sink my-cert-manager-package
grep -q 'apiVersion: experimental.helm.sh/v1alpha1' my-cert-manager-package/cert-manager-chart.yaml
cp examples/render-helm-chart/Kptfile my-cert-manager-package/
kpt fn render my-cert-manager-package -o stdout | grep -q 'team-name: blue-team'
rm -rf my-cert-manager-package
.PHONY: render-helm-chart-example2
render-helm-chart-example2:
kpt fn source examples/render-helm-chart/non-stardard-tar-filename | kpt fn eval - ${HELM_RENDER} | kpt fn sink my-non-stardard-tar-filename
rm -rf my-non-stardard-tar-filename
# Test rendering using Capabilities.KubeVersion
.PHONY: render-with-kube-version
render-with-kube-version:
mkdir _tmp
helm package test-data/test-chart
scripts/source-chart.sh test-data/render-test-chart.yaml test-chart-0.1.0.tgz > _tmp/render.yaml
rm test-chart-0.1.0.tgz
# Note, no patch version
sed -i 's/kubeVersion: .*/kubeVersion: 1.29/' _tmp/render.yaml
kpt fn source _tmp | kpt fn eval - ${HELM_RENDER} | kpt fn sink _tmp-output
cat _tmp-output/configmap_foo.yaml
grep -q 'kubeVersion: "v1.29.0"' _tmp-output/configmap_foo.yaml
grep -q 'kubeVersionMinor: "29"' _tmp-output/configmap_foo.yaml
rm -rf _tmp-output
sed -i 's/kubeVersion: .*/kubeVersion: 1.30.0/' _tmp/render.yaml
kpt fn source _tmp | kpt fn eval - ${HELM_RENDER} | kpt fn sink _tmp-output
cat _tmp-output/configmap_foo.yaml
grep -q 'kubeVersion: "v1.30.0"' _tmp-output/configmap_foo.yaml
grep -q 'kubeVersionMinor: "30"' _tmp-output/configmap_foo.yaml
rm -rf _tmp _tmp-output
.PHONY: test-source-helm-chart
test-source-helm-chart:
kpt fn source examples/render-helm-chart3 | kpt fn eval - --truncate-output=false $(HELM_SOURCE) > test-out.txt
grep -e 'experimental.helm.sh/chart-sum/karpenter' test-out.txt
grep -e 'experimental.helm.sh/chart-sum/cert-manager' test-out.txt
rm test-out.txt
.PHONY: test-apply-setters
test-apply-setters: test-apply-setters1 test-apply-setters2
.PHONY: test-apply-setters1
test-apply-setters1:
kpt fn source examples/apply-setters | kpt fn eval - --truncate-output=false $(APPLY_SETTERS) --fn-config example-function-configs/apply-setters/cm-setters.yaml | kpt fn eval - -i gcr.io/kpt-fn/remove-local-config-resources:v0.1.0 -o unwrap > test-out.txt
grep -e 'foo: "valueFoo"' test-out.txt
grep -e 'bar: "valueBar"' test-out.txt
grep -e 'baz: "valueBaz"' test-out.txt
grep -e 'replicas: "4"' test-out.txt
grep -e 'combined: ""' test-out.txt
grep -e 'app.kubernetes.io/version: "a1b2c3d4e5e6"' test-out.txt
rm test-out.txt
.PHONY: test-apply-setters2
test-apply-setters2:
kpt fn source examples/apply-setters | kpt fn eval - --truncate-output=false $(APPLY_SETTERS) --fn-config example-function-configs/apply-setters/apply-setters-fn-config.yaml | kpt fn eval - -i gcr.io/kpt-fn/remove-local-config-resources:v0.1.0 -o unwrap > test-out.txt
grep -e 'foo: ""' test-out.txt
grep -e 'bar: "valueBar2"' test-out.txt
grep -e 'baz: "valueBaz2"' test-out.txt
grep -e 'replicas: "4"' test-out.txt
grep -e 'combined: "4-a1b2c3d4e5e6"' test-out.txt
grep -e 'app.kubernetes.io/version: "a1b2c3d4e5e6"' test-out.txt
rm test-out.txt
.PHONY: test-digester
test-digester: test-digester-step1 test-digester-step3 test-digester-output
.PHONY: test-digester-step1
test-digester-step1:
rm -rf digester-tmp0
kpt fn source examples/digester | kpt fn eval - --truncate-output=false $(HELM_SOURCE) | kpt fn sink digester-tmp0
.PHONY: test-digester-step2
test-digester-step2:
kpt fn source digester-tmp0 | kpt fn eval - --truncate-output=false $(DIGESTER) > test-out.txt
head -n 60 test-out.txt
.PHONY: test-digester-step3
test-digester-step3:
rm -rf digester-tmp1
kpt fn source digester-tmp0 | kpt fn eval - --truncate-output=false $(DIGESTER) | kpt fn sink digester-tmp1
kpt fn render digester-tmp1 -o unwrap > test-out.yaml
.PHONY: test-digester-output
test-digester-output:
grep 'image: "quay.io/jetstack/cert-manager-controller@sha256:.*' test-out.yaml
grep 'image: "quay.io/jetstack/cert-manager-cainjector@sha256:.*' test-out.yaml
grep 'image: "quay.io/jetstack/cert-manager-webhook@sha256:.*' test-out.yaml
grep 'image: "quay.io/jetstack/cert-manager-ctl@sha256:.*' test-out.yaml
.PHONY: test-digester-w-containers
test-digester-w-containers:
echo "** sourcing step"
rm -rf cert-manager-package
kpt fn source examples/digester \
| kpt fn eval - $(HELM_SOURCE) \
| kpt fn eval - --truncate-output=false $(DIGESTER) \
| kpt fn sink cert-manager-package
.PHONY: test-digester-w-containers2
test-digester-w-containers2:
echo "** rendering using pipeline in Ktfile"
rm -rf cert-manager-rendered
kpt fn render cert-manager-package -o stdout | kpt fn sink cert-manager-rendered
#KUBECONFORM_SCHEMA_LOCATIONS ?= "default"
KUBECONFORM_SCHEMA_LOCATIONS ?= 'examples/kubeconform/schema-bundle/,examples/kubeconform/schema-bundle/CRDs-catalog/{{.Group}}/{{.ResourceKind}}_{{.ResourceAPIVersion}}.json'
.PHONY: test-kubeconform
test-kubeconform:
rm -rf tmp-results
#kpt fn source examples/kubeconform/manifests | kpt fn eval - --results-dir tmp-results --truncate-output=false $(KUBECONFORM) -- ignore_missing_schemas=true kubernetes_version=1.29.1 schema_locations=$(KUBECONFORM_SCHEMA_LOCATIONS) > test-out.txt || true
kpt fn source examples/kubeconform/manifests | kpt fn eval - --results-dir tmp-results --truncate-output=false $(KUBECONFORM) -- schema_locations=$(KUBECONFORM_SCHEMA_LOCATIONS) debug=true > test-out.txt || true
make test-kubeconform-results
.PHONY: test-kubeconform-w-container
test-kubeconform-w-container:
rm -rf tmp-results
kpt fn source examples/kubeconform/manifests | kpt fn eval - --results-dir tmp-results --truncate-output=false -i $(KUBECONFORM_IMAGE) -- ignore_missing_schemas=true schema_locations=$(KUBECONFORM_SCHEMA_LOCATIONS) > test-out.txt || true
make test-kubeconform-results
.PHONY: test-kubeconform-results
test-kubeconform-results:
grep -e '.* /data/nested: expected string or null, but got object' tmp-results/results.yaml
grep -e '.* name: invalid-nested-dict' tmp-results/results.yaml
grep -e '.* /data/a-number: expected string or null, but got number' tmp-results/results.yaml
grep -e '.* name: invalid-non-string-value' tmp-results/results.yaml
LOCAL_PACKAGES_DIR ?= /tmp/source-packages
.PHONY: test-source-packages-e2e
test-source-packages-e2e: test-source-packages test-source-packages-ref
# We don't set all annotations and comments exactly as kpt
if [ "$(shell diff -rw fn-output/fleet-1/example-fleet example-fleet-ref | wc -l)" != "40" ]; then echo "*** source-package diff not as expected"; exit 1; fi
.PHONY: test-source-packages
test-source-packages:
rm -rf tmp-results fn-output
kpt fn source examples/source-packages/specs | kpt fn eval - --results-dir tmp-results --truncate-output=false $(SOURCE_PACKAGES) | kpt fn sink fn-output
kpt pkg tree fn-output
tree fn-output
.PHONY: test-source-packages-ref
test-source-packages-ref:
# This is identical to 'examples/source-packages/specs/fleet-1/packages.yaml'
rm -rf example-fleet-ref && mkdir -p example-fleet-ref/olo
kpt pkg get https://github.com/krm-functions/catalog.git/examples/source-packages/pkg1 example-fleet-ref/foo --for-deployment
kpt pkg get https://github.com/krm-functions/catalog.git/examples/source-packages/pkg2 example-fleet-ref/bar --for-deployment
kpt pkg get https://github.com/krm-functions/catalog.git/examples/source-packages/pkg3 example-fleet-ref/bar/baz1 --for-deployment
kpt pkg get https://github.com/krm-functions/catalog.git/examples/source-packages/pkg1 example-fleet-ref/bar/baz2 --for-deployment
kpt pkg get https://github.com/krm-functions/catalog.git/examples/source-packages/pkg4 example-fleet-ref/olo/baz --for-deployment
.PHONY: test-template-kyaml
test-template-kyaml:
kpt fn source examples/template | kpt fn eval - --truncate-output=false $(TEMPLATE_KYAML) -- someConfig=aTestConfigString > test-out.txt
kpt fn source examples/template | kpt fn eval - --truncate-output=false $(TEMPLATE_KYAML) > test-out.txt