add post render integration test (#576)

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero 2022-12-14 11:38:47 +08:00 committed by GitHub
parent 524003d80b
commit 5da1200a8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 276 additions and 0 deletions

View File

@ -0,0 +1 @@
*.tgz

View File

@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/

View File

@ -0,0 +1,6 @@
apiVersion: v2
name: raw
description: A Helm chart for Kubernetes
type: application
version: 0.0.1
appVersion: "1.16.0"

View File

@ -0,0 +1 @@
A copy of chart ../raw, but older version to test locking.

View File

@ -0,0 +1,6 @@
{{- range $i, $r := $.Values.templates }}
{{- if gt $i 0 }}
---
{{- end }}
{{- (tpl $r $) }}
{{- end }}

View File

@ -0,0 +1,48 @@
templates: []
##
## Example: Uncomment the below and run `helm template ./`:
##
#
# templates:
# - |
# apiVersion: v1
# kind: ConfigMap
# metadata:
# name: {{ .Release.Name }}-1
# namespace: {{ .Release.Namespace }}
# data:
# foo: {{ .Values.foo }}
# - |
# apiVersion: v1
# kind: ConfigMap
# metadata:
# name: {{ .Release.Name }}-2
# namespace: {{ .Release.Namespace }}
# data:
# foo: {{ .Values.foo }}
# values:
# foo: FOO
#
##
## Expected Output:
##
#
# ---
# # Source: raw/templates/resources.yaml
# apiVersion: v1
# kind: ConfigMap
# metadata:
# name: release-name-1
# namespace: default
# data:
# foo:
# ---
# # Source: raw/templates/resources.yaml
# apiVersion: v1
# kind: ConfigMap
# metadata:
# name: release-name-2
# namespace: default
# data:
# foo:

View File

@ -90,6 +90,7 @@ ${kubectl} create namespace ${test_ns} || fail "Could not create namespace ${tes
. ${dir}/test-cases/secretssops.sh
. ${dir}/test-cases/yaml-overwrite.sh
. ${dir}/test-cases/chart-needs.sh
. ${dir}/test-cases/postrender-diff.sh
# ALL DONE -----------------------------------------------------------------------------------------------------------

View File

@ -0,0 +1,22 @@
if [[ helm_major_version -eq 3 ]]; then
postrender_diff_case_input_dir="${cases_dir}/postrender-diff/input"
postrender_diff_case_output_dir="${cases_dir}/postrender-diff/output"
postrender_diff_out_file=${postrender_diff_case_output_dir}/result
if [[ $EXTRA_HELMFILE_FLAGS == *--enable-live-output* ]]; then
postrender_diff_out_file=${postrender_diff_case_output_dir}/result-live
fi
postrender_diff_tmp=$(mktemp -d)
postrender_diff_reverse=${postrender_diff_tmp}/postrender.diff.build.yaml
test_start "postrender diff"
info "Comparing postrender diff output ${postrender_diff_reverse} with ${postrender_diff_case_output_dir}/result.yaml"
for i in $(seq 10); do
info "Comparing build/postrender-diff #$i"
${helmfile} -f ${postrender_diff_case_input_dir}/helmfile.yaml diff --concurrency 1 &> ${postrender_diff_reverse} || fail "\"helmfile diff\" shouldn't fail"
diff -u ${postrender_diff_out_file} ${postrender_diff_reverse} || fail "\"helmfile diff\" should be consistent"
echo code=$?
done
test_pass "postrender diff"
fi

View File

@ -0,0 +1,13 @@
#!/usr/bin/env bash
cat $1
echo "---"
cat <<EOS
apiVersion: v1
kind: ConfigMap
data:
one: ONE
metadata:
name: cm1
EOS

View File

@ -0,0 +1,13 @@
#!/usr/bin/env bash
cat $1
echo "---"
cat <<EOS
apiVersion: v1
kind: ConfigMap
data:
two: TWO
metadata:
name: cm2
EOS

View File

@ -0,0 +1,39 @@
helmDefaults:
postRenderer: ./add-cm1.bash
releases:
- name: foo
chart: ../../../charts/raw
values:
- templates:
- |
apiVersion: v1
kind: ConfigMap
metadata:
name: {{`{{ .Release.Name }}`}}-1
namespace: {{`{{ .Release.Namespace }}`}}
data:
foo: FOO
dep:
templates:
- |
apiVersion: v1
kind: ConfigMap
metadata:
name: {{`{{ .Release.Name }}`}}-2
namespace: {{`{{ .Release.Namespace }}`}}
data:
bar: BAR
postRenderer: ./add-cm2.bash
- name: baz
chart: ../../../charts/raw
values:
- templates:
- |
apiVersion: v1
kind: ConfigMap
metadata:
name: {{`{{ .Release.Name }}`}}-3
namespace: {{`{{ .Release.Namespace }}`}}
data:
baz: BAZ

View File

@ -0,0 +1,52 @@
Building dependency release=foo, chart=../../../charts/raw
Building dependency release=baz, chart=../../../charts/raw
Comparing release=foo, chart=../../../charts/raw
********************
Release was not present in Helm. Diff will show entire contents as new.
********************
helmfile-tests, cm2, ConfigMap (v1) has been added:
-
+ apiVersion: v1
+ kind: ConfigMap
+ data:
+ two: TWO
+ metadata:
+ name: cm2
helmfile-tests, foo-1, ConfigMap (v1) has been added:
-
+ # Source: raw/templates/resources.yaml
+ apiVersion: v1
+ kind: ConfigMap
+ metadata:
+ name: foo-1
+ namespace: helmfile-tests
+ data:
+ foo: FOO
Comparing release=baz, chart=../../../charts/raw
********************
Release was not present in Helm. Diff will show entire contents as new.
********************
helmfile-tests, baz-3, ConfigMap (v1) has been added:
-
+ # Source: raw/templates/resources.yaml
+ apiVersion: v1
+ kind: ConfigMap
+ metadata:
+ name: baz-3
+ namespace: helmfile-tests
+ data:
+ baz: BAZ
helmfile-tests, cm1, ConfigMap (v1) has been added:
-
+ apiVersion: v1
+ kind: ConfigMap
+ data:
+ one: ONE
+ metadata:
+ name: cm1

View File

@ -0,0 +1,51 @@
Live output is enabled
Building dependency release=foo, chart=../../../charts/raw
Building dependency release=baz, chart=../../../charts/raw
********************
Release was not present in Helm. Diff will show entire contents as new.
********************
helmfile-tests, cm2, ConfigMap (v1) has been added:
-
+ apiVersion: v1
+ kind: ConfigMap
+ data:
+ two: TWO
+ metadata:
+ name: cm2
helmfile-tests, foo-1, ConfigMap (v1) has been added:
-
+ # Source: raw/templates/resources.yaml
+ apiVersion: v1
+ kind: ConfigMap
+ metadata:
+ name: foo-1
+ namespace: helmfile-tests
+ data:
+ foo: FOO
********************
Release was not present in Helm. Diff will show entire contents as new.
********************
helmfile-tests, baz-3, ConfigMap (v1) has been added:
-
+ # Source: raw/templates/resources.yaml
+ apiVersion: v1
+ kind: ConfigMap
+ metadata:
+ name: baz-3
+ namespace: helmfile-tests
+ data:
+ baz: BAZ
helmfile-tests, cm1, ConfigMap (v1) has been added:
-
+ apiVersion: v1
+ kind: ConfigMap
+ data:
+ one: ONE
+ metadata:
+ name: cm1
Comparing release=foo, chart=../../../charts/raw
Comparing release=baz, chart=../../../charts/raw