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

Only show values conflicting with schema when explicitly running validate #2363

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/ck8s
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ install-requirements)
validate)
[[ "${2}" =~ ^(wc|sc)$ ]] || usage
check_tools
config_load "$2"
config_load "$2" -v
echo "Config validation successful"
;;
providers) echo "${ck8s_cloud_providers[@]}" ;;
Expand Down
24 changes: 13 additions & 11 deletions bin/common.bash
Original file line number Diff line number Diff line change
Expand Up @@ -393,13 +393,15 @@ validate_config() {
if ! yajsv -s "${schema_file}" "${merged_config}" >"${schema_validation_result}"; then
log_warning "Failed schema validation:"
sed -r 's/^.*_(..-config\.yaml): fail: (.*)/\1: \2/; / failed validation$/q' <"${schema_validation_result}"
grep -oP '(?<=fail: )[^:]+' "${schema_validation_result}" | sort -u |
while read -r jpath; do
if [[ $jpath != "(root)" ]]; then
echo -n ".$jpath = "
yq4 -oj ".$jpath" "${merged_config}"
fi
done
if [[ "${3:-}" == "-v" ]]; then
grep -oP '(?<=fail: )[^:]+' "${schema_validation_result}" | sort -u |
while read -r jpath; do
if [[ $jpath != "(root)" ]]; then
echo -n ".$jpath = "
yq4 -oj ".$jpath" "${merged_config}"
fi
done
fi
maybe_exit="true"
fi
}
Expand Down Expand Up @@ -431,10 +433,10 @@ validate_config() {

check_conditionals "${config_to_validate}" "${template_file}"
validate "${config_to_validate}" "${template_file}"
schema_validate "${config_to_validate}" "${config_template_path}/schemas/config.yaml"
schema_validate "${config_to_validate}" "${config_template_path}/schemas/config.yaml" "${2:-}"
check_conditionals "${secrets[secrets_file]}" "${config_template_path}/secrets.yaml"
validate "${secrets[secrets_file]}" "${config_template_path}/secrets.yaml"
schema_validate "${secrets[secrets_file]}" "${config_template_path}/schemas/secrets.yaml"
schema_validate "${secrets[secrets_file]}" "${config_template_path}/schemas/secrets.yaml" "${2:-}"

if ${maybe_exit} && ! ${CK8S_AUTO_APPROVE}; then
ask_abort
Expand Down Expand Up @@ -473,13 +475,13 @@ validate_sops_config() {
}

# Load and validate all configuration options from the config path.
# Usage: config_load <sc|wc> [sk]
# Usage: config_load <sc|wc> [--skip-validation|-v]
config_load() {
load_config "$1"

if [[ "--skip-validation" != "${2:-''}" ]]; then
validate_version "$1"
validate_config "$1"
validate_config "$1" "${2:-''}"
validate_sops_config
fi
}
Expand Down
Loading