Skip to content

Conversation

@AlirezaPourchali
Copy link
Contributor

Fixes #5449

This PR adds support for custom container names via kubectl.kubernetes.io/default-container annotation and fixes two critical bugs found during testing.

Background

PR #5452 attempted to add this feature but has implementation issues that prevent it from working correctly. This PR provides a complete working solution.

Changes

New Feature:

  • Added getDefaultContainerName() function to read kubectl.kubernetes.io/default-container annotation
  • Falls back to "manager" for backward compatibility when annotation is missing

Bug Fix 1: Container names were being incorrectly templated

  • substituteResourceNamesWithPrefix() was converting container names to Helm templates like {{ include "chart.resourceName" ... }}
  • Container names are internal pod identifiers and should remain literal, not templated like cluster-wide resource names
  • Root cause: Container names with dashes (e.g., osiris-manager, controller-test) match the same regex pattern project-prefix-* intended for resource names like project-webhook-service
  • Fixed by detecting container context (looking backward for containers:) and excluding them from templating

Bug Fix 2: Image templating failed with custom container names

  • Order-of-operations issue: substituteResourceNamesWithPrefix runs before templateImageReference
  • When container name gets templated first, the image regex no longer matches the literal container name
  • Fixed by modifying all image-related functions (templateImageReference, templateEnvironmentVariables, templateResources, templateContainerSecurityContext, templateControllerManagerArgs) to check for both literal and templated container names

Testing

  • ✅ Unit tests added for custom container name support
  • ✅ Verified with custom container name controller-test
  • ✅ Backward compatibility maintained with default manager container name
  • ✅ All existing tests pass

Example

Projects can now use any container name:

metadata:
  annotations:
    kubectl.kubernetes.io/default-container: my-custom-controller
spec:
  containers:
  - name: my-custom-controller  # Stays literal, not templated
    image: controller:latest     # Gets templated correctly

@k8s-ci-robot k8s-ci-robot added do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Feb 10, 2026
@k8s-ci-robot
Copy link
Contributor

Hi @AlirezaPourchali. 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 /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.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 10, 2026
… bugs

This PR adds support for custom container names via
kubectl.kubernetes.io/default-container annotation and fixes two
critical bugs found during testing:

1. Container names were being incorrectly templated by
   substituteResourceNamesWithPrefix. Container names are internal
   pod identifiers and should remain literal, not templated like
   cluster-wide resource names.

2. Image templating failed due to order-of-operations issue where
   substituteResourceNamesWithPrefix runs before templateImageReference.
   Modified all image-related functions to check for both literal and
   templated container names.

Testing: Verified with custom container names (controller-test) and
ensures backward compatibility with default 'manager' container name.
@AlirezaPourchali AlirezaPourchali force-pushed the fix-helm-custom-container-names branch from 0ce6f96 to d9b67c1 Compare February 10, 2026 05:38
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Feb 10, 2026
Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 10, 2026
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AlirezaPourchali, camilamacedo86

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

The pull request process is described 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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 10, 2026
@camilamacedo86
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 10, 2026
@k8s-ci-robot k8s-ci-robot merged commit 816ad1b into kubernetes-sigs:master Feb 10, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

helm/v2-alpha: Helm plugin fails to template deployment fields when container name is not "manager"

3 participants