Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace YQ with helm lint in helm test #36

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/helm.bash
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,26 @@
helm_template() {
local chart_dir=$1
local template_opts=$2
local return_message
local tmp_write_dir
tmp_write_dir=/tmp/rhcop/$(date +'%d-%m-%Y-%H-%M')/"${chart_dir}"

mkdir -p "${tmp_write_dir}"

local output_file
output_file="${tmp_write_dir}/templates.yaml"

# NOTE: eval is used due to helm not liking empty template_opts
eval "helm template ${template_opts} ${chart_dir} &> ${output_file}"
lint_output_file="${tmp_write_dir}/linting.output"

# Safety check to make sure nothing above silently failed
if [[ ! -s "${output_file}" ]] || [[ $(wc -c "${output_file}" | awk '{print $1}') -le 1 ]] ; then
fail "# FATAL-ERROR: (helm.bash): File is empty: '${output_file}'" || return $?
pabrahamsson marked this conversation as resolved.
Show resolved Hide resolved
if ! return_message=$(eval "helm template ${template_opts} ${chart_dir} > ${output_file}") ; then
fail "# FATAL-ERROR: (helm.bash): helm template failed: ${return_message}" || return $?
fi

# Another, safety check to make sure nothing above silently failed
yq "." "${output_file}" > /dev/null 2>&1
if [[ $? -eq 1 ]] ; then
fail "# FATAL-ERROR: (helm.bash): File is not valid YAML: '${output_file}'" || return $?
# Safety check to make sure nothing above silently failed
if ! lint_return_message=$(eval "helm lint ${template_opts} ${chart_dir} > ${lint_output_file}") ; then
fail "# FATAL-ERROR: (helm.bash): helm lint failed: ${lint_return_message} " || return $?
fi

echo "${tmp_write_dir}"

}