fix(k8s): custom-stack VPA targets a non-existent (double-suffixed) deployment#330
Merged
Conversation
Cre-eD
requested review from
Laboratory,
smecsia and
universe-ops
as code owners
June 19, 2026 18:04
Semgrep Scan ResultsRepository:
Scanned at 2026-06-21 14:06 UTC |
Security Scan ResultsRepository:
Scanned at 2026-06-21 14:06 UTC |
DeploySimpleContainer already applies the parentEnv suffix to Service/Deployment for custom stacks (parentEnv != stackEnv), e.g. myapp -> myapp-tenant-a. But NewSimpleContainer re-derived baseResourceName via generateDeploymentName on the already-suffixed name, producing myapp-tenant-a-tenant-a. baseResourceName names the VPA (resource name AND spec.targetRef) and the HPA, so for every custom stack the VPA targeted a non-existent deployment and never right-sized the pods (they stayed pinned at the base request). The Deployment itself was always correct (it uses sanitizedDeployment directly), which is why the mismatch went unnoticed. Fix: baseResourceName := sanitizedDeployment — the caller already made it parentEnv-aware. No-op for non-custom stacks; fixes the VPA targetRef and tidies the HPA name for custom stacks. Documented the caller pre-suffix contract on NewSimpleContainer so it can't regress. On the next deploy of a custom stack, Pulumi replaces the VPA and HPA (old double-suffixed logical names removed, correctly-named ones created); the HPA's scaleTargetRef already pointed at the real Deployment object, so scaling is unaffected. VPA/HPA carry no RetainOnDelete/aliases, so the orphans are cleanly deleted (not stranded). The configmap/secret/image-pull-secret names remain double-suffixed for custom stacks (self-consistent: the pod references the same generated names), so they keep working; renaming them is a separate migration with pod-rollout cost. Test: TestNewSimpleContainer_CustomStackVPATargetsDeployment replicates the production caller contract (pre-suffixed Service/Deployment for a custom stack) and asserts the rendered VPA's spec.targetRef.name + name are single-suffixed. Adds the VPA's GVK type token to the test mock so the CustomResource is captured. Confirmed it fails on the bug and passes with the fix; full package green. Signed-off-by: Dmitrii Creed <creeed22@gmail.com>
Contributor
Author
|
Hardened after a 4-way review (2 subagents + codex + gemini):
|
Cre-eD
force-pushed
the
fix/custom-stack-vpa-targetref
branch
from
June 20, 2026 11:10
1b41804 to
8e52f56
Compare
📊 Statement coverageMeasured on the documented included set (see
Baseline: |
smecsia
approved these changes
Jun 21, 2026
universe-ops
approved these changes
Jun 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
For custom stacks (
parentEnv != stackEnv), the VPA never right-sizes the pods because it targets a deployment that doesn't exist.DeploySimpleContaineralready applies the parentEnv suffix toService/Deployment(e.g.myapp→myapp-tenant-a).NewSimpleContainerthen re-derivedbaseResourceNameviagenerateDeploymentNameon the already-suffixed name →myapp-tenant-a-tenant-a. SincebaseResourceNamenames the VPA (resource name andspec.targetRef.name) and the HPA, the VPA'stargetRefpointed at a non-existentmyapp-tenant-a-tenant-aDeployment. The Deployment itself is correct (it usessanitizedDeployment), so the mismatch was silent — the VPA simply applied no recommendation and pods stayed pinned at the base request.Non-custom stacks are unaffected (no suffix is applied upstream, so the names already matched).
Fix
The only caller (
DeploySimpleContainer) already made the name parentEnv-aware, so re-deriving it was the bug.Blast radius
On the next deploy of a custom stack, Pulumi replaces the VPA and HPA (old double-suffixed logical names removed; correctly-named ones created). The HPA's
scaleTargetRefalready used the real Deployment object, so scaling is unaffected by the rename. This fixes previously-orphaned VPAs on all custom stacks.Scoped intentionally: the configmap/secret/image-pull-secret names stay double-suffixed for custom stacks — they're self-consistent (the pod references the same generated names), so they keep working. Renaming them is a separate migration with a pod-rollout cost and isn't needed for this fix.
Test
Test-first regression (
TestNewSimpleContainer_CustomStackBaseNameNotDoubleSuffixed): replicates the production caller contract (pre-suffixed Service/Deployment for a custom stack) and assertsbaseResourceNameis single-suffixed via the HPA (which shares it with the VPA). Confirmed it fails on the bug and passes with the fix; fullpkg/clouds/pulumi/kubernetessuite green.