Use gopkg.in/yaml.v2 for Helmfile v0.x (#609)

This should fix #435 for Helmfile v0.x releases since the next v0.150.0.
We introduce a new envvar to opt-in to the new YAML library, so that you can give it a shot before upgrading your Helmfile to v1. The same envvar can be used to opt-out of the new YAML library after you upgrade to Helmfile v1, giving you a more flexible migration story.

Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>
This commit is contained in:
Yusuke Kuoka
2023-01-04 18:17:24 +09:00
committed by GitHub
parent 490bb5d147
commit 4688cf0132
28 changed files with 357 additions and 246 deletions
+19 -11
View File
@@ -2,6 +2,14 @@ if [[ helm_major_version -eq 3 ]]; then
chart_need_case_input_dir="${cases_dir}/chart-needs/input"
chart_need_case_output_dir="${cases_dir}/chart-needs/output"
config_file="helmfile.yaml"
if [[ ${HELMFILE_V1MODE} = true ]]; then
pushd "${chart_need_case_input_dir}"
mv "${config_file}" "${config_file}.gotmpl"
config_file="${config_file}.gotmpl"
popd
fi
chart_needs_tmp=$(mktemp -d)
chart_needs_template_reverse=${chart_needs_tmp}/chart.needs.template.log
chart_needs_lint_reverse=${chart_needs_tmp}/chart.needs.lint.log
@@ -20,46 +28,46 @@ if [[ helm_major_version -eq 3 ]]; then
for i in $(seq 10); do
info "Comparing template/chart-needs #$i"
${helmfile} -f ${chart_need_case_input_dir}/helmfile.yaml template --include-needs > ${chart_needs_template_reverse} || fail "\"helmfile template\" shouldn't fail"
${helmfile} -f ${chart_need_case_input_dir}/${config_file} template --include-needs > ${chart_needs_template_reverse} || fail "\"helmfile template\" shouldn't fail"
./dyff between -bs ${chart_need_case_output_dir}/template ${chart_needs_template_reverse} || fail "\"helmfile template\" should be consistent"
echo code=$?
done
for i in $(seq 10); do
info "Comparing lint/chart-needs #$i"
${helmfile} -f ${chart_need_case_input_dir}/helmfile.yaml lint --include-needs | grep -v Linting > ${chart_needs_lint_reverse} || fail "\"helmfile lint\" shouldn't fail"
${helmfile} -f ${chart_need_case_input_dir}/${config_file} lint --include-needs | grep -v Linting > ${chart_needs_lint_reverse} || fail "\"helmfile lint\" shouldn't fail"
diff -u ${lint_out_file} ${chart_needs_lint_reverse} || fail "\"helmfile lint\" should be consistent"
echo code=$?
done
for i in $(seq 10); do
info "Comparing diff/chart-needs #$i"
${helmfile} -f ${chart_need_case_input_dir}/helmfile.yaml diff --include-needs | grep -Ev "Comparing release=azuredisk-csi-storageclass, chart=/tmp/.*/azuredisk-csi-storageclass" > ${chart_needs_diff_reverse} || fail "\"helmfile diff\" shouldn't fail"
${helmfile} -f ${chart_need_case_input_dir}/${config_file} diff --include-needs | grep -Ev "Comparing release=azuredisk-csi-storageclass, chart=/tmp/.*/azuredisk-csi-storageclass" > ${chart_needs_diff_reverse} || fail "\"helmfile diff\" shouldn't fail"
diff -u ${diff_out_file} ${chart_needs_diff_reverse} || fail "\"helmfile diff\" should be consistent"
echo code=$?
done
info "Applying ${chart_need_case_input_dir}/helmfile.yaml"
${helmfile} -f ${chart_need_case_input_dir}/helmfile.yaml apply --include-needs
info "Applying ${chart_need_case_input_dir}/${config_file}"
${helmfile} -f ${chart_need_case_input_dir}/${config_file} apply --include-needs
code=$?
[ ${code} -eq 0 ] || fail "unexpected exit code returned by helmfile apply: want 0, got ${code}"
${kubectl} get storageclass managed-csi -o yaml | grep -q "provisioner: disk.csi.azure.com" || fail "storageclass managed-csi should be created when applying helmfile.yaml"
info "Destroying ${chart_need_case_input_dir}/helmfile.yaml"
${helmfile} -f ${chart_need_case_input_dir}/helmfile.yaml destroy
info "Destroying ${chart_need_case_input_dir}/${config_file}"
${helmfile} -f ${chart_need_case_input_dir}/${config_file} destroy
code=$?
[ ${code} -eq 0 ] || fail "unexpected exit code returned by helmfile destroy: want 0, got ${code}"
info "Syncing ${chart_need_case_input_dir}/helmfile.yaml"
${helmfile} -f ${chart_need_case_input_dir}/helmfile.yaml sync --include-needs
info "Syncing ${chart_need_case_input_dir}/${config_file}"
${helmfile} -f ${chart_need_case_input_dir}/${config_file} sync --include-needs
code=$?
[ ${code} -eq 0 ] || fail "unexpected exit code returned by helmfile apply: want 0, got ${code}"
${kubectl} get storageclass managed-csi -o yaml | grep -q "provisioner: disk.csi.azure.com" || fail "storageclass managed-csi should be created when syncing helmfile.yaml"
info "Destroying ${chart_need_case_input_dir}/helmfile.yaml"
${helmfile} -f ${chart_need_case_input_dir}/helmfile.yaml destroy
info "Destroying ${chart_need_case_input_dir}/${config_file}"
${helmfile} -f ${chart_need_case_input_dir}/${config_file} destroy
code=$?
[ ${code} -eq 0 ] || fail "unexpected exit code returned by helmfile destroy: want 0, got ${code}"
+31 -23
View File
@@ -2,22 +2,30 @@ test_start "happypath - simple rollout of httpbin chart"
happypath_case_input_dir="${cases_dir}/happypath/input"
happypath_case_output_dir="${cases_dir}/happypath/output"
config_file="happypath.yaml"
info "Diffing ${happypath_case_input_dir}/happypath.yaml"
bash -c "${helmfile} -f ${happypath_case_input_dir}/happypath.yaml diff --detailed-exitcode; code="'$?'"; [ "'${code}'" -eq 2 ]" || fail "unexpected exit code returned by helmfile diff"
if [[ ${HELMFILE_V1MODE} = true ]]; then
pushd "${happypath_case_input_dir}"
mv "${config_file}" "${config_file}.gotmpl"
config_file="${config_file}.gotmpl"
popd
fi
info "Diffing ${happypath_case_input_dir}/happypath.yaml without color"
bash -c "${helmfile} -f ${happypath_case_input_dir}/happypath.yaml --no-color diff --detailed-exitcode; code="'$?'"; [ "'${code}'" -eq 2 ]" || fail "unexpected exit code returned by helmfile diff"
info "Diffing ${happypath_case_input_dir}/${config_file}"
bash -c "${helmfile} -f ${happypath_case_input_dir}/${config_file} diff --detailed-exitcode; code="'$?'"; [ "'${code}'" -eq 2 ]" || fail "unexpected exit code returned by helmfile diff"
info "Diffing ${happypath_case_input_dir}/happypath.yaml with limited context"
bash -c "${helmfile} -f ${happypath_case_input_dir}/happypath.yaml diff --context 3 --detailed-exitcode; code="'$?'"; [ "'${code}'" -eq 2 ]" || fail "unexpected exit code returned by helmfile diff"
info "Diffing ${happypath_case_input_dir}/${config_file} without color"
bash -c "${helmfile} -f ${happypath_case_input_dir}/${config_file} --no-color diff --detailed-exitcode; code="'$?'"; [ "'${code}'" -eq 2 ]" || fail "unexpected exit code returned by helmfile diff"
info "Diffing ${happypath_case_input_dir}/happypath.yaml with altered output"
bash -c "${helmfile} -f ${happypath_case_input_dir}/happypath.yaml diff --output simple --detailed-exitcode; code="'$?'"; [ "'${code}'" -eq 2 ]" || fail "unexpected exit code returned by helmfile diff"
info "Diffing ${happypath_case_input_dir}/${config_file} with limited context"
bash -c "${helmfile} -f ${happypath_case_input_dir}/${config_file} diff --context 3 --detailed-exitcode; code="'$?'"; [ "'${code}'" -eq 2 ]" || fail "unexpected exit code returned by helmfile diff"
info "Templating ${happypath_case_input_dir}/happypath.yaml"
info "Diffing ${happypath_case_input_dir}/${config_file} with altered output"
bash -c "${helmfile} -f ${happypath_case_input_dir}/${config_file} diff --output simple --detailed-exitcode; code="'$?'"; [ "'${code}'" -eq 2 ]" || fail "unexpected exit code returned by helmfile diff"
info "Templating ${happypath_case_input_dir}/${config_file}"
rm -rf ${dir}/tmp
${helmfile} -f ${happypath_case_input_dir}/happypath.yaml --debug template --output-dir tmp
${helmfile} -f ${happypath_case_input_dir}/${config_file} --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
@@ -30,39 +38,39 @@ for output in $(ls -d ${dir}/tmp/*); do
done
done
info "Applying ${happypath_case_input_dir}/happypath.yaml"
bash -c "${helmfile} -f ${happypath_case_input_dir}/happypath.yaml apply --detailed-exitcode; code="'$?'"; echo Code: "'$code'"; [ "'${code}'" -eq 2 ]" || fail "unexpected exit code returned by helmfile apply"
info "Applying ${happypath_case_input_dir}/${config_file}"
bash -c "${helmfile} -f ${happypath_case_input_dir}/${config_file} apply --detailed-exitcode; code="'$?'"; echo Code: "'$code'"; [ "'${code}'" -eq 2 ]" || fail "unexpected exit code returned by helmfile apply"
info "Syncing ${happypath_case_input_dir}/happypath.yaml"
${helmfile} -f ${happypath_case_input_dir}/happypath.yaml sync
info "Syncing ${happypath_case_input_dir}/${config_file}"
${helmfile} -f ${happypath_case_input_dir}/${config_file} sync
wait_deploy_ready httpbin-httpbin
retry 5 "curl --fail $(minikube service --url --namespace=${test_ns} httpbin-httpbin)/status/200"
[ ${retry_result} -eq 0 ] || fail "httpbin failed to return 200 OK"
info "Applying ${happypath_case_input_dir}/happypath.yaml"
${helmfile} -f ${happypath_case_input_dir}/happypath.yaml apply --detailed-exitcode
info "Applying ${happypath_case_input_dir}/${config_file}"
${helmfile} -f ${happypath_case_input_dir}/${config_file} apply --detailed-exitcode
code=$?
[ ${code} -eq 0 ] || fail "unexpected exit code returned by helmfile apply: want 0, got ${code}"
info "Locking dependencies"
${helmfile} -f ${happypath_case_input_dir}/happypath.yaml deps
${helmfile} -f ${happypath_case_input_dir}/${config_file} deps
code=$?
[ ${code} -eq 0 ] || fail "unexpected exit code returned by helmfile deps: ${code}"
info "Applying ${happypath_case_input_dir}/happypath.yaml with locked dependencies"
${helmfile} -f ${happypath_case_input_dir}/happypath.yaml apply
info "Applying ${happypath_case_input_dir}/${config_file} with locked dependencies"
${helmfile} -f ${happypath_case_input_dir}/${config_file} apply
code=$?
[ ${code} -eq 0 ] || fail "unexpected exit code returned by helmfile apply: ${code}"
${helm} list --namespace=${test_ns} || fail "unable to list releases"
info "Deleting release"
${helmfile} -f ${happypath_case_input_dir}/happypath.yaml delete
${helmfile} -f ${happypath_case_input_dir}/${config_file} destroy
${helm} status --namespace=${test_ns} httpbin &> /dev/null && fail "release should not exist anymore after a delete"
info "Ensuring \"helmfile delete\" doesn't fail when no releases installed"
${helmfile} -f ${happypath_case_input_dir}/happypath.yaml delete || fail "\"helmfile delete\" shouldn't fail when there are no installed releases"
info "Ensuring \"helmfile destroy\" doesn't fail when no releases installed"
${helmfile} -f ${happypath_case_input_dir}/${config_file} destroy || fail "\"helmfile delete\" shouldn't fail when there are no installed releases"
info "Ensuring \"helmfile template\" output does contain only YAML docs"
(${helmfile} -f ${happypath_case_input_dir}/happypath.yaml template | kubectl apply -f -) || fail "\"helmfile template | kubectl apply -f -\" shouldn't fail"
(${helmfile} -f ${happypath_case_input_dir}/${config_file} template | kubectl apply -f -) || fail "\"helmfile template | kubectl apply -f -\" shouldn't fail"
test_pass "happypath"
@@ -2,6 +2,14 @@ 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"
config_file="helmfile.yaml"
if [[ ${HELMFILE_V1MODE} = true ]]; then
pushd "${postrender_diff_case_input_dir}"
mv "${config_file}" "${config_file}.gotmpl"
config_file="${config_file}.gotmpl"
popd
fi
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
@@ -14,7 +22,7 @@ if [[ helm_major_version -eq 3 ]]; then
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"
${helmfile} -f ${postrender_diff_case_input_dir}/${config_file} 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
+26 -4
View File
@@ -3,15 +3,37 @@ test_start "regression tests"
if [[ helm_major_version -eq 3 ]]; then
regression_case_input_dir="${cases_dir}/regression/input"
info "https://github.com/roboll/helmfile/issues/1857"
(${helmfile} -f ${regression_case_input_dir}/issue.1857.yaml --state-values-set grafanaEnabled=true template | grep grafana 1>/dev/null) || fail "\"helmfile template\" shouldn't include grafana"
! (${helmfile} -f ${regression_case_input_dir}/issue.1857.yaml --state-values-set grafanaEnabled=false template | grep grafana) || fail "\"helmfile template\" shouldn't include grafana"
config_file="issue.1857.yaml"
if [[ ${HELMFILE_V1MODE} = true ]]; then
pushd "${regression_case_input_dir}"
mv "${config_file}" "${config_file}.gotmpl"
config_file="${config_file}.gotmpl"
popd
fi
(${helmfile} -f ${regression_case_input_dir}/${config_file} --state-values-set grafanaEnabled=true template | grep grafana 1>/dev/null) || fail "\"helmfile template\" shouldn't include grafana"
! (${helmfile} -f ${regression_case_input_dir}/${config_file} --state-values-set grafanaEnabled=false template | grep grafana) || fail "\"helmfile template\" shouldn't include grafana"
info "https://github.com/roboll/helmfile/issues/1867"
(${helmfile} -f ${regression_case_input_dir}/issue.1867.yaml template 1>/dev/null) || fail "\"helmfile template\" shouldn't fail"
config_file="issue.1867.yaml"
if [[ ${HELMFILE_V1MODE} = true ]]; then
pushd "${regression_case_input_dir}"
mv "${config_file}" "${config_file}.gotmpl"
config_file="${config_file}.gotmpl"
popd
fi
(${helmfile} -f ${regression_case_input_dir}/${config_file} template 1>/dev/null) || fail "\"helmfile template\" shouldn't fail"
info "https://github.com/roboll/helmfile/issues/2118"
(${helmfile} -f ${regression_case_input_dir}/issue.2118.yaml template 1>/dev/null) || fail "\"helmfile template\" shouldn't fail"
config_file="issue.2118.yaml"
if [[ ${HELMFILE_V1MODE} = true ]]; then
pushd "${regression_case_input_dir}"
mv "${config_file}" "${config_file}.gotmpl"
config_file="${config_file}.gotmpl"
popd
fi
(${helmfile} -f ${regression_case_input_dir}/${config_file} template 1>/dev/null) || fail "\"helmfile template\" shouldn't fail"
else
info "There are no regression tests for helm 2 because all the target charts have dropped helm 2 support."
fi
+11 -4
View File
@@ -5,6 +5,13 @@ if [[ helm_major_version -eq 3 ]]; then
secretssops_case_input_dir="${cases_dir}/secretssops/input"
secretssops_case_output_dir="${cases_dir}/secretssops/output"
config_file="secretssops.yaml"
if [[ ${HELMFILE_V1MODE} = true ]]; then
pushd "${secretssops_case_input_dir}"
mv "${config_file}" "${config_file}.gotmpl"
config_file="${config_file}.gotmpl"
popd
fi
mkdir -p ${secretssops_case_input_dir}/tmp
@@ -19,7 +26,7 @@ if [[ helm_major_version -eq 3 ]]; then
info "Ensure helmfile fails when no helm-secrets is installed"
unset code
${helmfile} -f ${secretssops_case_input_dir}/secretssops.yaml -e direct build || code="$?"; code="${code:-0}"
${helmfile} -f ${secretssops_case_input_dir}/${config_file} -e direct build || code="$?"; code="${code:-0}"
echo Code: "${code}"
[ "${code}" -ne 0 ] || fail "\"helmfile build\" should fail without secrets plugin"
@@ -31,7 +38,7 @@ if [[ helm_major_version -eq 3 ]]; then
${helm} plugin install https://github.com/jkroepke/helm-secrets --version v${HELM_SECRETS_VERSION}
info "Ensure helmfile succeed when helm-secrets is installed"
${helmfile} -f ${secretssops_case_input_dir}/secretssops.yaml -e direct build || fail "\"helmfile build\" shouldn't fail"
${helmfile} -f ${secretssops_case_input_dir}/${config_file} -e direct build || fail "\"helmfile build\" shouldn't fail"
test_pass "secretssops.2"
@@ -46,7 +53,7 @@ if [[ helm_major_version -eq 3 ]]; then
info "Comparing build/direct output ${direct} with ${secretssops_case_output_dir}"
for i in $(seq 10); do
info "Comparing build/direct #$i"
${helmfile} -f ${secretssops_case_input_dir}/secretssops.yaml -e direct template --skip-deps > ${direct} || fail "\"helmfile template\" shouldn't fail"
${helmfile} -f ${secretssops_case_input_dir}/${config_file} -e direct template --skip-deps > ${direct} || fail "\"helmfile template\" shouldn't fail"
./dyff between -bs ${secretssops_case_output_dir}/direct.build.yaml ${direct} || fail "\"helmfile template\" should be consistent"
echo code=$?
done
@@ -54,7 +61,7 @@ if [[ helm_major_version -eq 3 ]]; then
info "Comparing build/reverse output ${direct} with ${secretssops_case_output_dir}"
for i in $(seq 10); do
info "Comparing build/reverse #$i"
${helmfile} -f ${secretssops_case_input_dir}/secretssops.yaml -e reverse template --skip-deps > ${reverse} || fail "\"helmfile template\" shouldn't fail"
${helmfile} -f ${secretssops_case_input_dir}/${config_file} -e reverse template --skip-deps > ${reverse} || fail "\"helmfile template\" shouldn't fail"
./dyff between -bs ${secretssops_case_output_dir}/reverse.build.yaml ${reverse} || fail "\"helmfile template\" should be consistent"
echo code=$?
done
+18 -14
View File
@@ -1,17 +1,21 @@
if [[ helm_major_version -eq 3 ]]; then
yaml_overwrite_case_input_dir="${cases_dir}/yaml-overwrite/input"
yaml_overwrite_case_output_dir="${cases_dir}/yaml-overwrite/output"
if [[ ${HELMFILE_V1MODE} = true ]]; then
yaml_overwrite_case_input_dir="${cases_dir}/yaml-overwrite/input"
yaml_overwrite_case_output_dir="${cases_dir}/yaml-overwrite/output"
yaml_overwrite_tmp=$(mktemp -d)
yaml_overwrite_reverse=${yaml_overwrite_tmp}/yaml.override.build.yaml
yaml_overwrite_tmp=$(mktemp -d)
yaml_overwrite_reverse=${yaml_overwrite_tmp}/yaml.override.build.yaml
test_start "yaml overwrite feature"
info "Comparing yaml overwrite feature output ${yaml_overwrite_reverse} with ${yaml_overwrite_case_output_dir}/overwritten.yaml"
for i in $(seq 10); do
info "Comparing build/yaml-overwrite #$i"
${helmfile} -f ${yaml_overwrite_case_input_dir}/issue.657.yaml template --skip-deps > ${yaml_overwrite_reverse} || fail "\"helmfile template\" shouldn't fail"
./dyff between -bs ${yaml_overwrite_case_output_dir}/overwritten.yaml ${yaml_overwrite_reverse} || fail "\"helmfile template\" should be consistent"
echo code=$?
done
test_pass "yaml overwrite feature"
fi
test_start "yaml overwrite feature"
info "Comparing yaml overwrite feature output ${yaml_overwrite_reverse} with ${yaml_overwrite_case_output_dir}/overwritten.yaml"
for i in $(seq 10); do
info "Comparing build/yaml-overwrite #$i"
${helmfile} -f ${yaml_overwrite_case_input_dir}/issue.657.yaml.gotmpl template --skip-deps > ${yaml_overwrite_reverse} || fail "\"helmfile template\" shouldn't fail"
./dyff between -bs ${yaml_overwrite_case_output_dir}/overwritten.yaml ${yaml_overwrite_reverse} || fail "\"helmfile template\" should be consistent"
echo code=$?
done
test_pass "yaml overwrite feature"
else
test_pass "[skipped] yaml overwrite feature"
fi
fi