Add integration test for Kustomize inetgration (#1288)

Summary of changes:

* Output any error from Mkdir in `helmfile template`

* Add failing test for .Release.Name interpolation

* Add golden files for testing

* Parse resources with kustomize to compare them structure by structure

* Decode resources into plain maps

The RNode type from kustomize uses yaml.Node under the hood,
which carries extra information like line numbers, which
become noisy when comparing with deep.Equal.
This commit is contained in:
ento
2020-06-16 09:06:52 +09:00
committed by GitHub
parent 3a2a460fe7
commit face92536c
22 changed files with 579 additions and 4 deletions
+21
View File
@@ -0,0 +1,21 @@
# 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
*~
# Various IDEs
.project
.idea/
*.tmproj
+4
View File
@@ -0,0 +1,4 @@
apiVersion: v1
description: Chart for testing helmx features
name: helmx
version: 0.1.0
@@ -0,0 +1,16 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "helmx.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "helmx.fullname" -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
@@ -0,0 +1,13 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: release-name
data:
name: {{ .Release.Name }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: release-namespace
data:
namespace: {{ .Release.Namespace }}
+14
View File
@@ -25,3 +25,17 @@ releases:
values:
- mysecret: {{ .Environment.Values.mysecret }}
- values.yaml
- name: helmx
chart: ./charts/helmx
namespace: helmx-system
jsonPatches:
- target:
version: v1
kind: ConfigMap
name: release-name
patch:
- op: add
path: /metadata/annotations
value:
foo: bar
+14 -1
View File
@@ -47,12 +47,15 @@ set -e
info "Using namespace: ${test_ns}"
# helm v2
if helm version --client 2>/dev/null | grep '"v2\.'; then
helm_major_version=2
info "Using Helm version: $(helm version --short --client | grep -o v.*$)"
${helm} init --wait --override spec.template.spec.automountServiceAccountToken=true
# helm v3
else
helm_major_version=3
info "Using Helm version: $(helm version --short | grep -o v.*$)"
fi
info "Using Kustomize version: $(kustomize version --short | grep -o 'v[^ ]+')"
${helm} plugin install https://github.com/databus23/helm-diff --version v3.0.0-rc.7
${kubectl} get namespace ${test_ns} &> /dev/null && warn "Namespace ${test_ns} exists, from a previous test run?"
$kubectl create namespace ${test_ns} || fail "Could not create namespace ${test_ns}"
@@ -73,9 +76,19 @@ info "Diffing ${dir}/happypath.yaml with limited context"
bash -c "${helmfile} -f ${dir}/happypath.yaml diff --context 3 --detailed-exitcode; code="'$?'"; [ "'${code}'" -eq 2 ]" || fail "unexpected exit code returned by helmfile diff"
info "Templating ${dir}/happypath.yaml"
${helmfile} -f ${dir}/happypath.yaml template
rm -rf ${dir}/tmp
${helmfile} -f ${dir}/happypath.yaml --debug template --output-dir tmp
code=$?
[ ${code} -eq 0 ] || fail "unexpected exit code returned by helmfile template: ${code}"
for output in $(ls -d ${dir}/tmp/*); do
# e.g. test/integration/tmp/happypath-877c0dd4-helmx/helmx
for release_dir in $(ls -d ${output}/*); do
release_name=$(basename ${release_dir})
golden_dir=${dir}/templates-golden/v${helm_major_version}/${release_name}
info "Comparing template output ${release_dir}/templates with ${golden_dir}"
./diff-yamls ${golden_dir} ${release_dir}/templates || fail "unexpected diff in template result for ${release_name}"
done
done
info "Applying ${dir}/happypath.yaml"
bash -c "${helmfile} -f ${dir}/happypath.yaml apply --detailed-exitcode; code="'$?'"; echo Code: "'$code'"; [ "'${code}'" -eq 2 ]" || fail "unexpected exit code returned by helmfile apply"
@@ -0,0 +1,17 @@
---
# Source: helmx/templates/helmx.all.yaml
apiVersion: v1
data:
namespace: helmx-system
kind: ConfigMap
metadata:
name: release-namespace
---
apiVersion: v1
data:
name: helmx
kind: ConfigMap
metadata:
name: release-name
annotations:
foo: bar
@@ -0,0 +1,39 @@
---
# Source: httpbin/templates/deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
metadata:
name: httpbin-httpbin
labels:
app: httpbin
chart: httpbin-0.1.0
release: httpbin
heritage: Tiller
spec:
replicas: 1
strategy: {}
template:
metadata:
labels:
app: httpbin
release: httpbin
spec:
containers:
- name: httpbin
image: "docker.io/citizenstig/httpbin:latest"
imagePullPolicy: IfNotPresent
livenessProbe:
httpGet:
path: /
port: 8000
readinessProbe:
httpGet:
path: /
port: 8000
ports:
- containerPort: 8000
resources:
{}
status: {}
@@ -0,0 +1,21 @@
---
# Source: httpbin/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
name: httpbin-httpbin
labels:
app: httpbin
chart: httpbin-0.1.0
release: httpbin
heritage: Tiller
spec:
type: LoadBalancer
ports:
- port: 8000
targetPort: 8000
protocol: TCP
name: httpbin
selector:
app: httpbin
release: httpbin
@@ -0,0 +1,13 @@
---
# Source: raw/templates/resources.yaml
apiVersion: v1
kind: Secret
metadata:
labels:
app: raw
chart: raw-0.2.3
heritage: Tiller
release: raw
name: common-secret
stringData:
mykey: MYSECRET
@@ -0,0 +1,18 @@
---
# Source: helmx/templates/helmx.all.yaml
apiVersion: v1
data:
namespace: helmx-system
kind: ConfigMap
metadata:
name: release-namespace
---
# Source: helmx/templates/helmx.all.yaml
apiVersion: v1
data:
name: helmx
kind: ConfigMap
metadata:
name: release-name
annotations:
foo: bar
@@ -0,0 +1,39 @@
---
# Source: httpbin/templates/deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
metadata:
name: httpbin-httpbin
labels:
app: httpbin
chart: httpbin-0.1.0
release: httpbin
heritage: Helm
spec:
replicas: 1
strategy: {}
template:
metadata:
labels:
app: httpbin
release: httpbin
spec:
containers:
- name: httpbin
image: "docker.io/citizenstig/httpbin:latest"
imagePullPolicy: IfNotPresent
livenessProbe:
httpGet:
path: /
port: 8000
readinessProbe:
httpGet:
path: /
port: 8000
ports:
- containerPort: 8000
resources:
{}
status: {}
@@ -0,0 +1,21 @@
---
# Source: httpbin/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
name: httpbin-httpbin
labels:
app: httpbin
chart: httpbin-0.1.0
release: httpbin
heritage: Helm
spec:
type: LoadBalancer
ports:
- port: 8000
targetPort: 8000
protocol: TCP
name: httpbin
selector:
app: httpbin
release: httpbin
@@ -0,0 +1,13 @@
---
# Source: raw/templates/resources.yaml
apiVersion: v1
kind: Secret
metadata:
labels:
app: raw
chart: raw-0.2.3
heritage: Helm
release: raw
name: common-secret
stringData:
mykey: MYSECRET