🐛 (helm/v2-alpha): scope manager port templating to the manager container - #5921
🐛 (helm/v2-alpha): scope manager port templating to the manager container#5921v47 wants to merge 1 commit into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: v47 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @v47. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Tip We noticed you've done this a few times! Consider joining the org to skip this step and gain Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
fbbf812 to
68f88bd
Compare
|
Hey @camilamacedo86 — heads up, this PR ended up a bit larger than I initially planned. I considered splitting it into a few smaller step-by-step PRs since each scoping fix and the labels/annotations fix are logically independent, but they all live in the same manager templating flow, and all fall under #5901, so keeping them together felt cleaner for review and history than a chain of three PRs stacked on the same file. Happy to split it if you would prefer separate PRs - just let me know. One thing I intentionally left out for a follow-up: I kept it out of this PR for two reasons:
Happy to open the follow-up after we're done with this one. |
|
/retest |
|
@v47: Cannot trigger testing until a trusted user reviews the PR and leaves an DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
68f88bd to
2aa656c
Compare
|
@camilamacedo86 sorry, can you take a look? |
|
Just a nit otherwise, all shows fine. |
2aa656c to
57d62fc
Compare
57d62fc to
943cce4
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
pkg/plugins/optional/helm/v2alpha/scaffolds/internal/kustomize/templater/appliers/helpers.go:155
- The helper/comment says "manager container", but FindManagerContainerRange (per its implementation) uses GetDefaultContainerName(yamlContent) and then searches by "name: ". This mismatch makes the behavior easy to misunderstand and can lead to incorrect scoping if the default container annotation differs from the actual manager container. Consider either (a) updating naming/docs to "default container" everywhere (function name + comments), or (b) changing the range finder to explicitly locate the manager container by name ("manager") if that is the intended invariant for this templating pass.
// applyToManagerContainer runs transform on only the manager container's block within
// yamlContent, leaving sidecar containers and the rest of the Deployment untouched.
// When the manager container cannot be located, transform is applied to the whole
// document, preserving behavior for manifests without a detectable manager container.
func applyToManagerContainer(yamlContent string, transform func(string) string) string {
start, end := FindManagerContainerRange(yamlContent)
| func applyToManagerContainer(yamlContent string, transform func(string) string) string { | ||
| start, end := FindManagerContainerRange(yamlContent) | ||
| if start < 0 { | ||
| return transform(yamlContent) | ||
| } |
943cce4 to
52b89ad
Compare
Description
The Helm
v2-alphaplugin templated the manager Deployment's ports, health probes, and port-related arguments (--metrics-bind-address,--webhook-port,--health-probe-bind-address) by running regex replacements across the entire rendered Deployment. This change scopes all of that Deployment port, probe and argument templating to the manager container only.Detection reuses the existing
FindManagerContainerRangelookup — the same manager-container detection the values extractor relies on — through a newapplyToManagerContainerhelper, so the manager is correctly identified whether it is declared before or after other containers. Services and NetworkPolicies have no containers and continue to be matched by name, split out into a dedicatedtemplateServicePortsfor clarity.While here, the port-templating regexes are hoisted to package-level variables so they are compiled once instead of on every call (matching the existing pattern in
escape.go/helpers.go). A separate fix inAddCustomLabelsAndAnnotationsis folded in: hand-ordered Deployment metadata (labels:beforeannotations:) used to emit a duplicateannotations:header beforespec:; the state machine now flushes the pending labels merge on theannotations:line so both blocks stay undermetadata:.Test coverage added:
ApplyHelmSubstitutionsasserting the manager container is fully templated while a sidecar's ports, probes, image, and arguments are left untouched.labels:-then-annotations:metadata shape, asserting a single merged block instead of a duplicate header.Motivation
Because the replacements matched across the whole Deployment, a sidecar that happened to reuse the same ports, probe paths, or bind-address flags was rewritten to use manager chart values. For example, a proxy sidecar with a health probe on port
9440had it rewritten to{{ .Values.manager.healthProbe.port }}, so changingmanager.healthProbe.portwould unintentionally move the sidecar's port as well. The same class of bug affected the managerargs:rewrite: when a sidecar declared its ownargs:before the manager, the whole-document search landed on the sidecar first and silently skipped the manager's args wrappers. Webhook detection had the same problem because it also inspected the fully rendered document. Only values belonging to the manager container should use manager chart values; sidecars must remain unchanged.Partial Fixes #5901