Skip to content

Name CapacityBuffer managed PodTemplates by buffer UID - #277

Open
niewysoki wants to merge 3 commits into
kubernetes-sigs:mainfrom
niewysoki:fix-capacitybuffer-podtemplate-name-collision
Open

niewysoki wants to merge 3 commits into
kubernetes-sigs:mainfrom
niewysoki:fix-capacitybuffer-podtemplate-name-collision

Conversation

@niewysoki

@niewysoki niewysoki commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:

Previously, managed PodTemplate names were derived from buffer.Name (capacitybuffer-<name>-pod-template) and truncated at 225 characters. That allowed collisions across long-named CapacityBuffers, pre-existing user PodTemplates, and same-name delete-and-recreate cycles.
This PR names managed PodTemplates capacitybuffer-<buffer.UID>-managed-pod-template:

  • Eliminates name truncation and collisions while keeping ownerReferences self-healing (Index CapacityBuffer status.podTemplateRef for immediate reconciliation #262), since <buffer.UID> uniquely identifies the owning CapacityBuffer instance.
  • Skips terminating CapacityBuffers and verifies the owning buffer is still active before adopting an unowned UID-named PodTemplate, so kubectl delete capacitybuffer --cascade=orphan never re-attaches ownership.
  • Rejects spec.podTemplateRef values matching the reserved capacitybuffer-*-managed-pod-template pattern before dry-run.
  • Adds a ValidatingAdmissionPolicy to the KWOK E2E chart blocking non-controller creation, updates, and active deletion of managed PodTemplates.

Which issue(s) this PR fixes:

N/A

Special notes for your reviewer:

  • Pre-existing CapacityBuffers create a new capacitybuffer-<buffer.UID>-managed-pod-template on upgrade. Previously created capacitybuffer-<name>-pod-template objects keep their ownerReferences to the buffer and are garbage-collected when the buffer is deleted.

Does this PR introduce a user-facing change?

CapacityBuffer managed PodTemplates are now named `capacitybuffer-<buffer.UID>-managed-pod-template` instead of `capacitybuffer-<buffer.Name>-pod-template` to prevent name collisions while preserving `ownerReferences` self-healing. Existing CapacityBuffers switch to a new UID-named PodTemplate on upgrade, and their previous managed PodTemplates are garbage-collected when the CapacityBuffer is deleted.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@kubernetes-prow kubernetes-prow Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Nov 18, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

This issue is currently awaiting triage.

If SIG Autoscaling contributors determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Details

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.

@kubernetes-prow kubernetes-prow Bot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 18, 2026
@niewysoki
niewysoki force-pushed the fix-capacitybuffer-podtemplate-name-collision branch from b46bc5f to 2f04326 Compare November 18, 2026 18:03
@niewysoki
niewysoki marked this pull request as draft November 18, 2026 19:43
@kubernetes-prow kubernetes-prow Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 18, 2026
@niewysoki
niewysoki force-pushed the fix-capacitybuffer-podtemplate-name-collision branch from 2f04326 to cbcd6ed Compare November 19, 2026 13:02
@kubernetes-prow kubernetes-prow Bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 19, 2026
@niewysoki
niewysoki force-pushed the fix-capacitybuffer-podtemplate-name-collision branch 2 times, most recently from b811056 to 6051e39 Compare November 19, 2026 16:32
@kubernetes-prow kubernetes-prow Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Nov 19, 2026
@niewysoki
niewysoki marked this pull request as ready for review November 19, 2026 17:06
@kubernetes-prow kubernetes-prow Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 19, 2026

@norbertcyran norbertcyran left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hashing itself sounds fine to me, but I have some concerns about some other behavior changes introduced by this PR, esp. by breaking self-healing in case of removal of owner reference from the buffer.

Comment thread pkg/capacitybuffer/client/client.go Resolved
Comment thread pkg/capacitybuffer/client/client.go Resolved
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: niewysoki
Once this PR has been reviewed and has the lgtm label, please assign mtrqq for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@niewysoki
niewysoki force-pushed the fix-capacitybuffer-podtemplate-name-collision branch from 6051e39 to 5003b2d Compare November 26, 2026 14:12
@kubernetes-prow kubernetes-prow Bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 26, 2026
@niewysoki niewysoki changed the title Prevent CapacityBuffer managed PodTemplate name collisions Name CapacityBuffer managed PodTemplates by buffer UID Nov 26, 2026
Deriving managed PodTemplate names from buffer.Name truncates names over
225 characters and can collide with pre-existing user PodTemplates,
other long-named CapacityBuffers, or recreated buffers of the same name.

Adds common.ManagedPodTemplateName to name managed PodTemplates
capacitybuffer-<buffer.UID>-managed-pod-template, removes name
truncation in the translators, and validates the controller ownerRef UID
and expected UID name in EnsurePodTemplate.
A CapacityBuffer referencing a managed PodTemplate name in
spec.podTemplateRef can create self-referential or cross-buffer
coupling, and during --cascade=orphan deletion garbage collection clears
ownerReferences before the buffer informer observes DeletionTimestamp,
allowing the controller to re-adopt an orphaned PodTemplate.

Adds common.HasManagedPodTemplateName to reject reserved
capacitybuffer-*-managed-pod-template references before dry-run, skips
terminating CapacityBuffers in both translators, and verifies the live
CapacityBuffer is still active before adopting an unowned managed
PodTemplate in EnsurePodTemplate.
@niewysoki
niewysoki force-pushed the fix-capacitybuffer-podtemplate-name-collision branch from 5003b2d to 5c7ce2b Compare November 30, 2026 10:56
Without admission enforcement, users and other controllers can
pre-create colliding capacitybuffer-*-managed-pod-template PodTemplates
or directly edit and delete active managed PodTemplates in KWOK E2E
clusters.

Adds a ValidatingAdmissionPolicy and binding to the KWOK Helm chart to
deny non-controller creation, updates, and active deletion while leaving
orphaned PodTemplates deletable once ownerReferences are cleared. Adds
envtest admission coverage and updates the KWOK E2E reconciliation test
to assert non-admin updates fail with Forbidden before testing drift
recovery via system:masters.
@niewysoki
niewysoki force-pushed the fix-capacitybuffer-podtemplate-name-collision branch from 5c7ce2b to ec69d6a Compare December 4, 2026 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants