Skip to content
Open
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
5 changes: 5 additions & 0 deletions examples/bzlmod/root/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ patches:

buildMetadata:
- originAnnotations

# commonLabels is deprecated and builds produce warnings to stderr
# These warnings are not shown for successful builds if the option `silent_on_success` is set to true
commonLabels:
"car": "ford-mustang"
25 changes: 24 additions & 1 deletion kustomize/kustomize-build-from-archived-runfiles
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,27 @@ runfiles_archive_file="$(mktemp runfiles-archive-XXXXXX)"
kustomization_dir="$(mktemp -d kustomization-target-XXXXXX)"
"${zipper}" x "${runfiles_archive_file}" -d "${kustomization_dir}"

"${kustomize}" build "${kustomization_dir}/$(dirname ${target_file})" "${@}"
if [ "${KUSTOMIZE_RESOURCES__SILENT_ON_SUCCESS:-}" ]; then
STDERR_CAPTURE=$(mktemp)
fi

_exit() {
EXIT_CODE=$?

if [ "${STDERR_CAPTURE:-}" ]; then
if [ "$EXIT_CODE" != 0 ] || [ -z "${KUSTOMIZE_RESOURCES__SILENT_ON_SUCCESS:-}" ]; then
cat "$STDERR_CAPTURE" >&2
fi
rm "$STDERR_CAPTURE"
fi

exit $EXIT_CODE
}

trap _exit EXIT

if [ "${STDERR_CAPTURE:-}" ]; then
"${kustomize}" build "${kustomization_dir}/$(dirname ${target_file})" "${@}" 2> "$STDERR_CAPTURE"
else
"${kustomize}" build "${kustomization_dir}/$(dirname ${target_file})" "${@}"
fi
25 changes: 24 additions & 1 deletion kustomize/kustomize-build-from-runfiles
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,27 @@ if [ -z "${target_runfile_path}" ]; then
exit 1
fi

"${kustomize}" build "$(dirname ${target_runfile_path})" "${@}"
if [ "${KUSTOMIZE_RESOURCES__SILENT_ON_SUCCESS:-}" ]; then
STDERR_CAPTURE=$(mktemp)
fi

_exit() {
EXIT_CODE=$?

if [ "${STDERR_CAPTURE:-}" ]; then
if [ "$EXIT_CODE" != 0 ] || [ -z "${KUSTOMIZE_RESOURCES__SILENT_ON_SUCCESS:-}" ]; then
cat "$STDERR_CAPTURE" >&2
fi
rm "$STDERR_CAPTURE"
fi

exit $EXIT_CODE
}

trap _exit EXIT

if [ "${STDERR_CAPTURE:-}" ]; then
"${kustomize}" build "$(dirname ${target_runfile_path})" "${@}" 2> "$STDERR_CAPTURE"
else
"${kustomize}" build "$(dirname ${target_runfile_path})" "${@}"
fi
7 changes: 7 additions & 0 deletions kustomize/kustomize.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ _kustomized_resources_attrs = {
doc = "The built result, as a YAML stream of KRM resources in separate documents.",
mandatory = True,
),
"silent_on_success": attr.bool(
doc = "If true, suppress stderr output when the build succeeds.",
default = True,
),
}

_kustomize_toolchain_type = "//tools/kustomize:toolchain_type"
Expand Down Expand Up @@ -220,6 +224,9 @@ def _kustomized_resources_impl(ctx):
([helm_tool] if kustomization.requires_helm else []),
outputs = [ctx.outputs.result],
use_default_shell_env = use_default_shell_env,
env = {
"KUSTOMIZE_RESOURCES__SILENT_ON_SUCCESS": "1" if ctx.attr.silent_on_success else "",
},
mnemonic = mnemonic,
progress_message = progress_message,
)
Expand Down