Skip to content

Commit

Permalink
Enable Krew custom indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
electrocucaracha committed Mar 2, 2024
1 parent fc88569 commit 0939694
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/kubectl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ curl -fsSL http://bit.ly/install_pkg | PKG=kubectl bash
| PKG_KUBECTL_VERSION | | Specifies the Kubectl version to be installed |
| PKG_KREW_VERSION | | Specifies the Krew version to be installed |
| PKG_KREW_PLUGINS_LIST | tree,access-matrix,score,sniff,view-utilization | List of Krew plugins to be installed |
| PKG_KREW_INDEX_LIST | | List of pair key-value literals of Krew indexes to be added |
| PKG_INSTALL_FINALIZE_NAMESPACE | false | Determines if `finalize_namespace` is going to be installed |
| PKG_FINALIZE_NAMESPACE_VERSION | | Specifies the finalize_namespace plugin version to be installed |

Expand Down
3 changes: 2 additions & 1 deletion src/kubectl/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ Vagrant.configure("2") do |config|
sh.env = {
PKG_DEBUG: ENV["PKG_DEBUG"] || "true",
PKG_KREW_VERSION: ENV.fetch("PKG_KREW_VERSION", nil),
PKG_KREW_PLUGINS_LIST: ENV.fetch("PKG_KREW_PLUGINS_LIST", nil),
PKG_KREW_PLUGINS_LIST: "kubectl-prof/prof",
PKG_KREW_INDEX_LIST: "kubectl-prof=https://github.com/josepdcs/kubectl-prof,",
PKG_FINALIZE_NAMESPACE_VERSION: ENV.fetch("PKG_FINALIZE_NAMESPACE_VERSION", nil),
PKG_INSTALL_FINALIZE_NAMESPACE: "true"
}
Expand Down
6 changes: 6 additions & 0 deletions src/kubectl/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ function install_pkgs {
$INSTALLER_CMD --no-install-recommends install $@
;;
rhel | centos | fedora | rocky)
$sudo_cmd sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* || :
$sudo_cmd sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* || :
INSTALLER_CMD+="$(command -v dnf || command -v yum) -y"
if [[ ${PKG_DEBUG:-false} == "false" ]]; then
INSTALLER_CMD+=" --quiet --errorlevel=0"
Expand Down Expand Up @@ -152,6 +154,7 @@ function main {
local version=${PKG_KUBECTL_VERSION:-$(curl -L -s https://dl.k8s.io/release/stable.txt)}
local krew_version=${PKG_KREW_VERSION:-$(get_github_latest_release kubernetes-sigs/krew)}
krew_plugins_list=${PKG_KREW_PLUGINS_LIST:-tree,access-matrix,score,sniff,view-utilization}
krew_index_list=${PKG_KREW_INDEX_LIST:-}

if ! command -v kubectl || [[ "$(kubectl version --short --client | awk '{print $3}')" != "$version" ]]; then
echo "INFO: Installing kubectl $version version..."
Expand Down Expand Up @@ -200,6 +203,9 @@ function main {
export PATH="$PATH:${KREW_ROOT:-$HOME/.krew}/bin"
popd >/dev/null
fi
for index in ${krew_index_list//,/ }; do
kubectl krew index add "${index%=*}" "${index#*=}"
done
kubectl krew update
for plugin in ${krew_plugins_list//,/ }; do
kubectl krew install "$plugin" || true
Expand Down
5 changes: 5 additions & 0 deletions test/kubectl/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ else
fi
fi

info "Validating prof Krew plugin installation..."
if ! kubectl prof --version; then
warn "prof Krew plugin wasn't installed"
fi

info "Validating finalize_namespace installation..."
if ! command -v kubectl-finalize_namespace; then
warn "finalize_namespace plugin wasn't installed"
Expand Down

0 comments on commit 0939694

Please sign in to comment.