Skip to content

Conversation

@gjrtimmer
Copy link
Contributor

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.sh script 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

  • kind
  • kubebuilder
  • kubectl
  • docker

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Oct 24, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: gjrtimmer
Once this PR has been reviewed and has the lgtm label, please assign camilamacedo86 for approval. For more information see the Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 24, 2025
@k8s-ci-robot
Copy link
Contributor

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 /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.

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.

Copy link

Copilot AI left a 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.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 27, 2025
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.

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.

@gjrtimmer
Copy link
Contributor Author

gjrtimmer commented Oct 27, 2025

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.

Hi @camilamacedo86

This involves the post-install of the devcontainer. Any other environment used by a developer is not the responsibility of this repository. However, this repository provides a devcontainer. All these changes are within that devcontainer, which sets the default environment to bash.

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.

@camilamacedo86
Copy link
Member

camilamacedo86 commented Nov 2, 2025

Hi @gjrtimmer

that is a good point 👍 but I think we should change it out like: #5144 (comment)

Could you please squash the commits?
We need to have 1 commit to get it merged.

Also, can you please check the suggestion.

@gjrtimmer gjrtimmer force-pushed the feat-dev-autocomplete branch 2 times, most recently from 3cbdbd7 to a8c3616 Compare November 4, 2025 09:27
kubectl completion bash > "${BASH_COMPLETIONS_DIR}/kubectl" || true
fi

# ------------------ docker (optional) ------------------
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# ------------------ docker (optional) ------------------
# ------------------ docker ------------------

chmod +x ./kind
mv ./kind /usr/local/bin/kind

# Install bash completion (no dotfile edits)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# Install bash completion (no dotfile edits)
# Install bash completion

chmod +x kubebuilder
mv kubebuilder /usr/local/bin/

# Install bash completion (no dotfile edits)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# Install bash completion (no dotfile edits)
# Install bash completion

chmod +x kubectl
mv kubectl /usr/local/bin/kubectl

# Install bash completion (no dotfile edits)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# Install bash completion (no dotfile edits)
# Install bash completion

docker --version
go version
kubectl version --client
kubectl version --client
Copy link
Member

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?

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.

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.

@gjrtimmer gjrtimmer force-pushed the feat-dev-autocomplete branch from da2de99 to c083891 Compare November 4, 2025 10:06
@camilamacedo86 camilamacedo86 changed the title ✨ feat: add autocomplete for development ✨ (go/v4): Add autocomplete support in .devcontainer/post-install.sh to improve CLI usability in the dev container. Nov 4, 2025
@camilamacedo86
Copy link
Member

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!
Please make sure everything is squashed into a single commit, all checks are passing in CI, and that you’ve tested the changes locally so we can get it merged smoothly.

Feel free to ping me once everything is ready.

Thanks again for your contribution — really appreciated! 🙌

@gjrtimmer
Copy link
Contributor Author

@camilamacedo86 please read my earlier comment.

@camilamacedo86
Copy link
Member

camilamacedo86 commented Nov 4, 2025

HI @gjrtimmer,

Yes, that’s correct.

The scaffold already sets the VS Code terminal to use bash:
👉 https://github.com/kubernetes-sigs/kubebuilder/blob/master/pkg/plugins/golang/v4/scaffolds/internal/templates/devcontainer.go#L36

"settings": { "terminal.integrated.shell.linux": "/bin/bash" }

However, this only applies to the VS Code terminal.
It doesn’t make every environment use bash — for example, if someone runs docker exec, uses a non-VS Code terminal, or runs CI.

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, the new echo commands don’t follow the same format used in the file.
  • And the code is duplicated

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 "containerUser": "root",

Please, feel free to check it out and improve as you see fit. The above is an idea to ilustrate the suggestion.
I think the general acceptence would be something like

  • Bash completions for these tools are written to /etc/bash_completion.d/.
  • The script works on both amd64 and arm64 architectures.
  • The script does not modify any user files like ~/.bashrc.
  • The logic is simple, clean, and no duplicated code.
  • The configuration is easy to customize (versions, paths, and options can be changed via environment variables).
  • The behavior relies on as few assumptions as possible — it should just work in a standard devcontainer setup.
  • The overall result is maintainable, consistent, and reproducible for all contributors.

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

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants