Skip to content

Reject duplicate init container names and report them under initContainers - #16696

Open
arpitjain099 wants to merge 1 commit into
knative:mainfrom
arpitjain099:fix/init-container-name-validation
Open

arpitjain099 wants to merge 1 commit into
knative:mainfrom
arpitjain099:fix/init-container-name-validation

Conversation

@arpitjain099

Copy link
Copy Markdown

Fixes #

Proposed Changes

  • validateInitContainers seeds allNames from the regular containers and never adds the init container names it walks past, so two init containers sharing a name are accepted. validateContainers has the else { allNames.Insert(...) } that makes the same check work for regular containers. Issue Container names are not validated for duplicates #12260 said in its first line that this affects init containers too; PR Fix container name collision #12374 fixed the init-vs-regular half and tested that half only.
  • The errors from validateInitContainers use ViaFieldIndex("containers", i) and the one caller does not wrap in ViaField("initContainers"), so an init container fault comes back as containers[0].lifecycle or containers[0].securityContext, pointing the user at a different container than the one at fault.
  • The existing "init-container name collision" case expected the wrong path, so it moves to initContainers[0] along with the fix, and there is a new case for two init containers with the same name.

The new case fails on main with want "duplicate container name \"same\": initContainers[1].name", got "". go test ./pkg/apis/serving/... passes with the change.

Release Note

Duplicate init container names are now rejected, and validation errors for init containers report the initContainers field path instead of containers.

…iners

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
@knative-prow

knative-prow Bot commented Sep 28, 2026

Copy link
Copy Markdown

Welcome @arpitjain099! It looks like this is your first PR to knative/serving 🎉

@knative-prow knative-prow Bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 28, 2026
@knative-prow

knative-prow Bot commented Sep 28, 2026

Copy link
Copy Markdown

Hi @arpitjain099. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@knative-prow

knative-prow Bot commented Sep 28, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: arpitjain099
Once this PR has been reviewed and has the lgtm label, please assign dprotaso 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

@knative-prow
knative-prow Bot requested review from dprotaso and skonto September 28, 2026 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant