Skip to content

fix(server): fix find container logic for terminal #26858

Open
linghaoSu wants to merge 1 commit intoargoproj:masterfrom
linghaoSu:fix/init-container-terminal
Open

fix(server): fix find container logic for terminal #26858
linghaoSu wants to merge 1 commit intoargoproj:masterfrom
linghaoSu:fix/init-container-terminal

Conversation

@linghaoSu
Copy link
Member

@linghaoSu linghaoSu commented Mar 16, 2026

fix #26830

Before

terminal-before.mp4

After

terminal-after.mp4

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • The title of the PR conforms to the Title of the PR
  • I've included "Closes [ISSUE #]" or "Fixes [ISSUE #]" in the description to automatically close the associated issue.
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Does this PR require documentation updates?
  • I've updated documentation as required by this PR.
  • I have signed off all my commits as required by DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My build is green (troubleshooting builds).
  • My new feature complies with the feature status guidelines.
  • I have added a brief description of why this PR is necessary and/or what this PR solves.
  • Optional. My organization is added to USERS.md.
  • Optional. For bug fixes, I've indicated what older releases this fix should be cherry-picked into (this may or may not happen depending on risk/complexity).

@linghaoSu linghaoSu requested a review from a team as a code owner March 16, 2026 14:13
@bunnyshell
Copy link

bunnyshell bot commented Mar 16, 2026

✅ Preview Environment deployed on Bunnyshell

Component Endpoints
argocd https://argocd-jz6fej.bunnyenv.com/
argocd-ttyd https://argocd-web-cli-jz6fej.bunnyenv.com/

See: Environment Details | Pipeline Logs

Available commands (reply to this comment):

  • 🔴 /bns:stop to stop the environment
  • 🚀 /bns:deploy to redeploy the environment
  • /bns:delete to remove the environment

@linghaoSu linghaoSu force-pushed the fix/init-container-terminal branch 2 times, most recently from 856f1dc to d18f55f Compare March 16, 2026 14:59
Signed-off-by: linghaoSu <linghao.su@daocloud.io>
@linghaoSu linghaoSu force-pushed the fix/init-container-terminal branch from d18f55f to 208d3c0 Compare March 16, 2026 15:02
@codecov
Copy link

codecov bot commented Mar 16, 2026

Codecov Report

❌ Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 63.07%. Comparing base (5a6c832) to head (208d3c0).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
server/application/terminal.go 85.71% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master   #26858   +/-   ##
=======================================
  Coverage   63.06%   63.07%           
=======================================
  Files         414      414           
  Lines       56286    56287    +1     
=======================================
+ Hits        35499    35502    +3     
+ Misses      17418    17417    -1     
+ Partials     3369     3368    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@dudinea dudinea left a comment

Choose a reason for hiding this comment

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

@linghaoSu thank you for noticing and fixing that, great work!

I tried and it worked fine as you described.

I noticed one problem: the web terminal still cannot access a regular init container (without restartPolicy: Always) while it still executing (pod stuck initializing). I get error 400 fromm the web socket in such a case.

I can do kubectl exec into such a container just fine.

Would it possible to fix this as well?

}
}
if !findContainer {
if !ContainerExists(pod, container) {
Copy link
Member

Choose a reason for hiding this comment

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

ContainerExists() is not used from outside this package, probably should start from small letter

}

func ContainerExists(pod *corev1.Pod, containerName string) bool {
allContainers := slices.Concat(pod.Spec.Containers, pod.Spec.InitContainers)
Copy link
Member

Choose a reason for hiding this comment

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

slices.Concat() allocates new slice and copies all data from the source containers into it. And the data is the full container specs.
It seems to be wasteful, I'd just check both arrays in sequence instead.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe, you can use slices.Contains :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Web Terminal does not support sidecar containers created with native sidecar feature (initContainers with restartPolicy: Always)

3 participants