From 9d1affe005179b15730b0f5fa38e1d2105e4234c Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Thu, 14 Jan 2021 14:49:50 +0100 Subject: [PATCH] salt: Add `bash-completion` for `kubectl` Add a `/etc/bash_completion.d/kubectl` file for completion in bash for kubectl command Fixes: #2996 --- CHANGELOG.md | 4 ++++ buildchain/buildchain/salt_tree.py | 1 + salt/metalk8s/kubectl/configured.sls | 14 ++++++++++++++ salt/metalk8s/kubectl/init.sls | 3 ++- 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 salt/metalk8s/kubectl/configured.sls diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a0f6cafe2..6cdabd30a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ - Bump etcd version to 3.4.13-0 (PR[#3008](https://github.com/scality/metalk8s/pull/3008)) +- [#2996](https://github.com/scality/metalk8s/issues/2996) - The `bash-completion` + completions for the `kubectl` command are now provided when `kubectl` is installed + (PR [#3039](https://github.com/scality/metalk8s/pull/3039)) + ## Release 2.7.0 (in development) ### Enhancements - Bump Kubernetes version to 1.18.13 (PR[#2973](https://github.com/scality/metalk8s/pull/2973)) diff --git a/buildchain/buildchain/salt_tree.py b/buildchain/buildchain/salt_tree.py index 25b1fcb2aa..867dcc7df9 100644 --- a/buildchain/buildchain/salt_tree.py +++ b/buildchain/buildchain/salt_tree.py @@ -465,6 +465,7 @@ def _get_parts(self) -> Iterator[str]: Path('salt/metalk8s/sreport/init.sls'), Path('salt/metalk8s/sreport/installed.sls'), + Path('salt/metalk8s/kubectl/configured.sls'), Path('salt/metalk8s/kubectl/init.sls'), Path('salt/metalk8s/kubectl/installed.sls'), diff --git a/salt/metalk8s/kubectl/configured.sls b/salt/metalk8s/kubectl/configured.sls new file mode 100644 index 0000000000..4fa57d0bfa --- /dev/null +++ b/salt/metalk8s/kubectl/configured.sls @@ -0,0 +1,14 @@ +include: + - .installed + +Create kubectl bash completion file: + file.managed: + - name: /etc/bash_completion.d/kubectl + - contents: __slot__:salt:cmd.run('kubectl completion bash') + - makedirs: True + - dir_mode: 755 + - mode: 644 + - user: root + - group: root + - require: + - metalk8s_package_manager: Install kubectl diff --git a/salt/metalk8s/kubectl/init.sls b/salt/metalk8s/kubectl/init.sls index e0f67da3f7..0152273800 100644 --- a/salt/metalk8s/kubectl/init.sls +++ b/salt/metalk8s/kubectl/init.sls @@ -5,7 +5,8 @@ # ================ # # * installed -> Ensure kubectl is installed +# * configured -> Configure bash completion for kubectl # include: - - .installed + - .configured