Files
helmfile/test/integration/test-cases/issue-2275.sh
T
yxxhero bbf925f154 test: add integration test for issue #1880 transformers with file:// deps (#2673)
* test: add integration test for issue #1880 transformers with file:// deps

Add an integration test reproducing the exact scenario from issue #1880:
a local chart with a relative file:// dependency (file://../library) used
together with kustomize transformers.

Before the fix (rewriteChartDependencies in PR #2334), chartify copied
the chart to a temp directory, breaking the relative file:// path and
causing helm dependency up to fail with:
  Error: directory /tmp/chartify.../monitoring/library not found

Also fix test artifact leak in issue923_test.go where OCI chart downloads
wrote to CWD because OutputDirTemplate lacked {{ .OutputDir }}.

Closes #1880

Signed-off-by: yxxhero <aiopsclub@163.com>

* fix(test): guard exit-code captures against set -e in integration tests

Under set -e (enabled in run.sh), a failing command exits the shell
before 'var=$?' can execute, defeating diagnostic cat+fail blocks and
breaking helm diff tests that expect exit code 2.

Replaced 'cmd; var=$?' with 'var=0; cmd || var=$?' across 12 test
files (29 sites), matching the pattern already used in oci-parallel-pull.sh.

Signed-off-by: yxxhero <aiopsclub@163.com>

---------

Signed-off-by: yxxhero <aiopsclub@163.com>
2026-06-29 08:49:51 +08:00

90 lines
3.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Test for issue #2275: helmfile should detect cluster version and pass to helm-diff
# Without this fix, helm-diff falls back to v1.20.0 and fails for charts requiring newer versions
issue_2275_input_dir="${cases_dir}/issue-2275/input"
issue_2275_tmp_dir=$(mktemp -d)
cd "${issue_2275_input_dir}"
test_start "issue-2275: auto-detect kubernetes version for helm-diff"
info "Testing helmfile apply with chart requiring Kubernetes >=1.25.0"
info "Expected: Success with auto-detected cluster version"
# Test 1: Apply should succeed with auto-detected cluster version
code=0
${helmfile} apply --skip-diff-on-install --suppress-diff > "${issue_2275_tmp_dir}/test-2275-output.txt" 2>&1 || code=$?
if [ $code -ne 0 ]; then
if grep -q "incompatible with Kubernetes v1.20.0" "${issue_2275_tmp_dir}/test-2275-output.txt"; then
cat "${issue_2275_tmp_dir}/test-2275-output.txt"
rm -rf "${issue_2275_tmp_dir}"
fail "Issue #2275 regression: helm-diff fell back to v1.20.0"
else
cat "${issue_2275_tmp_dir}/test-2275-output.txt"
rm -rf "${issue_2275_tmp_dir}"
fail "Unexpected error during apply"
fi
fi
info "Chart installed successfully with auto-detected version"
# Test 2: Diff should work with auto-detected version
info "Testing helmfile diff with auto-detected cluster version"
code=0
${helmfile} diff > "${issue_2275_tmp_dir}/test-2275-diff-output.txt" 2>&1 || code=$?
if [ $code -ne 0 ] && [ $code -ne 2 ]; then
if grep -q "incompatible with Kubernetes v1.20.0" "${issue_2275_tmp_dir}/test-2275-diff-output.txt"; then
cat "${issue_2275_tmp_dir}/test-2275-diff-output.txt"
rm -rf "${issue_2275_tmp_dir}"
fail "Issue #2275 regression in diff: helm-diff fell back to v1.20.0"
else
cat "${issue_2275_tmp_dir}/test-2275-diff-output.txt"
rm -rf "${issue_2275_tmp_dir}"
fail "Unexpected error during diff"
fi
fi
info "Diff succeeded with auto-detected version"
# Test 3: Second apply (upgrade scenario) - this is the critical test case from issue #2275
# The first apply worked with --skip-diff-on-install, but second apply would fail without the fix
info "Testing second helmfile apply (upgrade scenario) - critical test for issue #2275"
info "Modifying chart to trigger an actual upgrade..."
# Update chart version to trigger an upgrade
sed -i.bak 's/version: 1.0.0/version: 1.0.1/' test-chart/Chart.yaml
info "Running helmfile apply to upgrade chart (this will run diff)"
info "This would fail with 'incompatible with Kubernetes v1.20.0' before the fix"
code=0
${helmfile} apply --suppress-diff > "${issue_2275_tmp_dir}/test-2275-apply2-output.txt" 2>&1 || code=$?
# Restore original chart version
mv test-chart/Chart.yaml.bak test-chart/Chart.yaml
if [ $code -ne 0 ]; then
if grep -q "incompatible with Kubernetes v1.20.0" "${issue_2275_tmp_dir}/test-2275-apply2-output.txt"; then
cat "${issue_2275_tmp_dir}/test-2275-apply2-output.txt"
rm -rf "${issue_2275_tmp_dir}"
fail "Issue #2275 regression: upgrade failed - helm-diff fell back to v1.20.0"
else
cat "${issue_2275_tmp_dir}/test-2275-apply2-output.txt"
rm -rf "${issue_2275_tmp_dir}"
fail "Unexpected error during upgrade"
fi
fi
info "Upgrade succeeded with auto-detected version"
# Cleanup
${helm} uninstall test-release-2275 --namespace default 2>/dev/null || true
rm -rf "${issue_2275_tmp_dir}"
test_pass "issue-2275: auto-detect kubernetes version for helm-diff"