Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing a VSCode extension, want to enable "Attach Visual Studio Code" to kubectl pod #199

Closed
benjiebob opened this issue Aug 29, 2023 · 4 comments

Comments

@benjiebob
Copy link

benjiebob commented Aug 29, 2023

Hi there!

I'm writing a VSCode extension and want to be able to add an "Attach Visual Studio Code" to a Kubectl pod button to my UI. I want to build an experience that closely matches this Kubernetes demo (but with my own custom list of pods). However, after a few days looking through this repo, I'm still struggling to find how to implement this.

Screenshot from Kubernetes demo is here: k8s-attach

I'd be really grateful if you could either point me towards a tutorial for setting this up, or if you could explain the steps that would be great.

Thanks!
Ben

@bamurtaugh
Copy link
Member

Thanks for opening! If you install the VS Code Dev Containers extension and right click, I believe this attach option is added when exploring containers from the Docker extension. Does installing the Dev Containers extension help?

@benjiebob
Copy link
Author

benjiebob commented Aug 29, 2023

Yes, sorry if I wasn't clear enough. I am trying to add a "Attach Visual Studio Code" to my own VSCode extension which I'm building so I need to implement the code behind the feature I referenced. The use-case is similar - I want my users to be able to Attach VSCode to a Kubernetes pod I show them in my UI. I'm struggling to find docs to help me with this - I'd be grateful if you could share/link me to the steps.

@benjiebob
Copy link
Author

benjiebob commented Aug 30, 2023

I've been doing some digging and found a seemingly related question that proposes the following terminal command to open a Remote Visual Studio window attached to a docker container:

code --folder-uri "vscode-remote://attached-container+<SOMETHING>"

I suspect that the "Attach Visual Studio Code" menu option I screenshotted above is launching a terminal command like this. I've tried lots of variants of hex values etc. to try and launch a VSCode window connected to my kubectl pod but haven't yet had any success.

I'd be really grateful if you could share the terminal command (or process) that mirrors the steps described in Attach to a container in a Kubernetes cluster.

Thanks!

@benjiebob
Copy link
Author

Aha, I found the answer. This fantastic contributor solved it.

cmd = f"code --folder-uri "vscode-remote://k8s-container%2Bcontext%3D{context}+podname={podname}+namespace={namespace}+name={container_name}{some_path}"

Be careful to escape any slashes with %2F in the URI.

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

No branches or pull requests

2 participants