-
Notifications
You must be signed in to change notification settings - Fork 1.6k
✨ (go/v4): Add autocomplete support in .devcontainer/post-install.sh to improve CLI usability in the dev container.
#5144
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
base: master
Are you sure you want to change the base?
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: gjrtimmer The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
Hi @gjrtimmer. Thanks for your PR. I'm waiting for a github.com member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
docs/book/src/getting-started/testdata/project/.devcontainer/post-install.sh
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds bash autocompletion support for development tools (kind, kubebuilder, kubectl, and docker) to improve developer experience in devcontainer environments.
Key Changes:
- Added autocompletion setup scripts for kind, kubebuilder, kubectl, and docker after their respective installations
- Implemented idempotent marker-based checks to prevent duplicate autocompletion entries
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| testdata/project-v4/.devcontainer/post-install.sh | Added autocompletion configuration for all four tools in v4 project template |
| testdata/project-v4-with-plugins/.devcontainer/post-install.sh | Added autocompletion configuration for all four tools in v4-with-plugins template |
| testdata/project-v4-multigroup/.devcontainer/post-install.sh | Added autocompletion configuration for all four tools in v4-multigroup template |
| pkg/plugins/golang/v4/scaffolds/internal/templates/devcontainer.go | Updated devcontainer template to generate autocompletion setup code |
| docs/book/src/multiversion-tutorial/testdata/project/.devcontainer/post-install.sh | Added autocompletion configuration for multiversion tutorial |
| docs/book/src/getting-started/testdata/project/.devcontainer/post-install.sh | Added autocompletion configuration for getting-started tutorial |
| docs/book/src/cronjob-tutorial/testdata/project/.devcontainer/post-install.sh | Added autocompletion configuration for cronjob tutorial |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
docs/book/src/cronjob-tutorial/testdata/project/.devcontainer/post-install.sh
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @gjrtimmer
Thank you a lot for your contribution 🥇
But we can only add to the default scaffold if we can ensure that the changes will work well in all environments.
In this case, I do not see how we could ensure and be able to know what the profile file for any env and so. I think that will be an issue to allow us to move forward within.
This involves the Please clarify your line of reasoning regarding this change and how it applies to the devcontainer development environment, as the devcontainer environment is fixed to ensure an easy, consistent development environment for all developers. This is can can adjust the PR if required. |
|
Hi @gjrtimmer that is a good point 👍 but I think we should change it out like: #5144 (comment) Could you please squash the commits? Also, can you please check the suggestion. |
docs/book/src/cronjob-tutorial/testdata/project/.devcontainer/post-install.sh
Show resolved
Hide resolved
3cbdbd7 to
a8c3616
Compare
| kubectl completion bash > "${BASH_COMPLETIONS_DIR}/kubectl" || true | ||
| fi | ||
|
|
||
| # ------------------ docker (optional) ------------------ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # ------------------ docker (optional) ------------------ | |
| # ------------------ docker ------------------ |
| chmod +x ./kind | ||
| mv ./kind /usr/local/bin/kind | ||
|
|
||
| # Install bash completion (no dotfile edits) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # Install bash completion (no dotfile edits) | |
| # Install bash completion |
| chmod +x kubebuilder | ||
| mv kubebuilder /usr/local/bin/ | ||
|
|
||
| # Install bash completion (no dotfile edits) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # Install bash completion (no dotfile edits) | |
| # Install bash completion |
| chmod +x kubectl | ||
| mv kubectl /usr/local/bin/kubectl | ||
|
|
||
| # Install bash completion (no dotfile edits) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # Install bash completion (no dotfile edits) | |
| # Install bash completion |
| docker --version | ||
| go version | ||
| kubectl version --client | ||
| kubectl version --client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we ensure here an empty line at the end?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @gjrtimmer
Really great !!
Just a few nits such as remove the comments under () that was more to share the thought and add an emoty line at the end of the file to fix the marker raised,
Then I think we could get this one merged 🎉
Thank you a lot for looking on it.
da2de99 to
c083891
Compare
.devcontainer/post-install.sh to improve CLI usability in the dev container.
|
Hi @gjrtimmer, I hope you don’t mind — I updated the title of this PR to align with our release note standards. I’m looking forward to your updates! Feel free to ping me once everything is ready. Thanks again for your contribution — really appreciated! 🙌 |
|
@camilamacedo86 please read my earlier comment. |
|
HI @gjrtimmer, Yes, that’s correct. The scaffold already sets the VS Code terminal to use bash:
However, this only applies to the VS Code terminal. Moreover, for the default scaffolds, we should aim for code that works reliably even when users customize their environments. That means keeping it idempotent, simple, and resilient — so it always works, even if other files or configurations change later. Regards the proposal beyond the assuption that it always will be bin/bash
Also, it is great keep it simple as possible so we could either do more improvements and do something like const postInstallScript = `#!/usr/bin/env bash
set -Eeuo pipefail
: "\${KIND_VERSION:=latest}"
: "\${KUBEBUILDER_VERSION:=latest}"
: "\${KUBECTL_VERSION:=}"
: "\${BASH_COMPLETIONS_DIR:=/etc/bash_completion.d}"
have() { command -v "$1" >/dev/null 2>&1; }
dl() { curl -fsSL -o "$2" "$1"; }
install_bin() { chmod +x "$1"; install -m 0755 "$1" "/usr/local/bin/$2"; }
mkdir -p "\$BASH_COMPLETIONS_DIR"
arch="$(go env GOARCH)"
case "\$arch" in amd64|arm64) ;; *) echo "Unsupported GOARCH: \$arch"; exit 1 ;; esac
# kind
tmp_kind="$(mktemp)"; dl "https://kind.sigs.k8s.io/dl/\${KIND_VERSION}/kind-linux-\${arch}" "\$tmp_kind"
install_bin "\$tmp_kind" kind
have kind && bash -lc "kind completion bash" > "\${BASH_COMPLETIONS_DIR}/kind" || true
# kubebuilder
tmp_kb="$(mktemp)"; dl "https://go.kubebuilder.io/dl/\${KUBEBUILDER_VERSION}/linux/\${arch}" "\$tmp_kb"
install_bin "\$tmp_kb" kubebuilder
have kubebuilder && bash -lc "kubebuilder completion bash" > "\${BASH_COMPLETIONS_DIR}/kubebuilder" || true
# kubectl
[ -z "\${KUBECTL_VERSION}" ] && KUBECTL_VERSION="$(curl -fsSL https://dl.k8s.io/release/stable.txt)"
tmp_kubectl="$(mktemp)"; dl "https://dl.k8s.io/release/\${KUBECTL_VERSION}/bin/linux/\${arch}/kubectl" "\$tmp_kubectl"
install_bin "\$tmp_kubectl" kubectl
have kubectl && bash -lc "kubectl completion bash" > "\${BASH_COMPLETIONS_DIR}/kubectl" || true
# docker completion
have docker && bash -lc "docker completion bash" > "\${BASH_COMPLETIONS_DIR}/docker" || true
# kind network
have docker && docker network create -d=bridge --subnet=172.19.0.0/24 kind || true
# versions
{ kind version || true; }
{ kubebuilder version || true; }
{ docker --version || true; }
{ go version || true; }
{ kubectl version --client || true; }
`Also, in the seetings we might want add Please, feel free to check it out and improve as you see fit. The above is an idea to ilustrate the suggestion.
|
Motivation
I was missing autocomplete during development, so I added it to make my life easier.
Description
This PR will update the
.devcontainer/post-install.shscript to install bash autocomplete for the various development tools. This will make development easier, faster, and more convenient for the developers.Bash autocomplete is already part of the golang:1.25 image.
Impact
None
Affected Tools