- 
                Notifications
    
You must be signed in to change notification settings  - Fork 1.6k
 
✨ feat: add autocomplete for development #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.  | 
    
| echo ". <(kind completion bash)" >> "$BASHRC_FILE" | ||
| echo "$END_MARKER" >> "$BASHRC_FILE" | ||
| echo "" | ||
| fi | 
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.
I think we should install the autocompletion files under /etc/bash_completion.d/ instead of editing $HOME/.bashrc, because it makes the setup cleaner and works automatically for all users in the Dev Container without touching their personal shell files.
#!/bin/bash
set -x
BASH_COMPLETIONS_DIR="/etc/bash_completion.d"
mkdir -p "$BASH_COMPLETIONS_DIR"
# ------------------ kind ------------------
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-$(go env GOARCH)
chmod +x ./kind
mv ./kind /usr/local/bin/kind
# Install bash completion (no dotfile edits)
if command -v kind >/dev/null 2>&1; then
    kind completion bash > "${BASH_COMPLETIONS_DIR}/kind" || true
fi
# ------------------ kubebuilder ------------------
curl -L -o kubebuilder https://go.kubebuilder.io/dl/latest/linux/$(go env GOARCH)
chmod +x kubebuilder
mv kubebuilder /usr/local/bin/
# Install bash completion (no dotfile edits)
if command -v kubebuilder >/dev/null 2>&1; then
    kubebuilder completion bash > "${BASH_COMPLETIONS_DIR}/kubebuilder" || true
fi
# ------------------ kubectl ------------------
KUBECTL_VERSION=$(curl -L -s https://dl.k8s.io/release/stable.txt)
curl -LO "https://dl.k8s.io/release/$KUBECTL_VERSION/bin/linux/$(go env GOARCH)/kubectl"
chmod +x kubectl
mv kubectl /usr/local/bin/kubectl
# Install bash completion (no dotfile edits)
if command -v kubectl >/dev/null 2>&1; then
    kubectl completion bash > "${BASH_COMPLETIONS_DIR}/kubectl" || true
fi
# ------------------ docker (optional) ------------------
# Only try to install docker completion if docker exists in the container
if command -v docker >/dev/null 2>&1; then
    # some docker builds support `docker completion`
    docker completion bash > "${BASH_COMPLETIONS_DIR}/docker" || true
fi
# ------------------ network for kind ------------------
docker network create -d=bridge --subnet=172.19.0.0/24 kind
# ------------------ versions ------------------
kind version
kubebuilder version
docker --version
go version
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.
@camilamacedo86 Agreed; I will test this out and verify that everything works, because sometimes the bash_completion.d does not get loaded correctly in a devcontainer. I will verify and commit any changes later.
8dd9615    to
    3cbdbd7      
    Compare
  
    
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