mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-11-21 14:48:37 +00:00
* fix(helm): skip OCI registry progress messages on stdout
Helm 4.2.1 moved the registry client's progress messages from stderr to
stdout (helm/helm#32056), so on an OCI reference they now precede the real
output. helm parses the stdout of `helm show chart` and helm_template
returns the stdout of `helm template`, and neither can detect this from the
return code because both commands exit 0.
Helm rewrites '+' to '_' in OCI tags, which makes it also print a free-text
explanation. That is not valid YAML, so a chart version carrying semver
build metadata failed outright. Without the '+' the messages parse as a
mapping instead, silently adding Pulled/Digest keys to the chart info.
Match helm's message verbatim rather than seeking the start of the real
output: the payload has three shapes and can be empty, whereas the messages
are always at the front and byte-identical. A reworded message then fails
loudly instead of consuming a line of real output.
Fixes: #1222
* test(helm): cover OCI charts whose version has build metadata
Pushes a chart versioned 1.0.0+build.1 to the local registry and asserts
that helm installs it idempotently with the version reported verbatim, and
that helm_template returns only rendered manifests. A second version without
build metadata covers the case where the registry messages parse as YAML.
Pinned to Helm 4.2.4: the target is only meaningful on >= 4.2.1, which is
where the messages moved to stdout. The rest of the helm matrix tops out at
v4.0.0, which is why this went unnoticed.
Verified to fail on the parent commit and pass on the fix.
* test(helm): drop Go template from chart fixture
The yamllint sanity test parses chart templates with libyaml, where
`{{ default "test" .Values.myValue }}` is an unhashable mapping key. The
existing chart fixtures carry a yamllint!skip entry in every
tests/sanity/ignore-*.txt for exactly this, but the target never renders
the chart with values, so the template served no purpose. Making the
fixture plain YAML keeps the ignore lists from growing.
* test(ci): empty commit to re-trigger CI
(cherry picked from commit c098ecc8c8)
Co-authored-by: Yuriy Novostavskiy <yuriy@novostavskiy.kyiv.ua>
This commit is contained in:
co-authored by
Yuriy Novostavskiy
parent
e620b92b49
commit
b40a401ec2
@@ -32,6 +32,53 @@ except ImportError:
|
||||
HAS_YAML = False
|
||||
|
||||
|
||||
# Helm's registry client writes these progress messages to stdout as of helm 4.2.1
|
||||
# (helm/helm#32056); earlier versions sent them to stderr. Anything that parses the
|
||||
# stdout of a helm command which may pull from an OCI registry has to skip them.
|
||||
# Kept verbatim from helm's pkg/registry/client.go so that a reworded message fails
|
||||
# to match, and therefore fails loudly, rather than silently eating real output.
|
||||
REGISTRY_PROGRESS_RE = re.compile(r"^(?:Pulled|Pushed|Digest): \S")
|
||||
|
||||
REGISTRY_UNDERSCORE_SUFFIX = " contains an underscore.\n"
|
||||
|
||||
REGISTRY_UNDERSCORE_MESSAGE = """
|
||||
OCI artifact references (e.g. tags) do not support the plus sign (+). To support
|
||||
storing semantic versions, Helm adopts the convention of changing plus (+) to
|
||||
an underscore (_) in chart version tags when pushing to a registry and back to
|
||||
a plus (+) when pulling from a registry.
|
||||
"""
|
||||
|
||||
REGISTRY_UNDERSCORE_MESSAGE_LINES = len(REGISTRY_UNDERSCORE_MESSAGE.splitlines())
|
||||
|
||||
|
||||
def strip_registry_progress(out):
|
||||
"""
|
||||
Drop OCI registry progress messages from the front of a helm command's stdout.
|
||||
|
||||
Helm emits 'Pulled:'/'Pushed:' and 'Digest:' lines, followed - when the
|
||||
reference contains an underscore - by a free-text explanation that is not
|
||||
valid YAML. Since helm 4.2.1 these land on stdout ahead of the real output,
|
||||
so 'helm show chart' can no longer be parsed and 'helm template' no longer
|
||||
returns only rendered manifests.
|
||||
"""
|
||||
lines = out.splitlines(keepends=True)
|
||||
index = 0
|
||||
while index < len(lines):
|
||||
if REGISTRY_PROGRESS_RE.match(lines[index]):
|
||||
index += 1
|
||||
elif lines[index].endswith(REGISTRY_UNDERSCORE_SUFFIX):
|
||||
# helm prints its registryUnderscoreMessage right after this line, led
|
||||
# by a blank line. Anything else is not a message we know about.
|
||||
start = index + 1
|
||||
end = start + REGISTRY_UNDERSCORE_MESSAGE_LINES
|
||||
if "".join(lines[start:end]) != REGISTRY_UNDERSCORE_MESSAGE:
|
||||
break
|
||||
index = end
|
||||
else:
|
||||
break
|
||||
return "".join(lines[index:])
|
||||
|
||||
|
||||
def parse_helm_plugin_list(output=None):
|
||||
"""
|
||||
Parse `helm plugin list`, return list of plugins
|
||||
|
||||
Reference in New Issue
Block a user