From 09396940119f91225be6b810f6c65048627b55ce Mon Sep 17 00:00:00 2001 From: Victor Morales Date: Fri, 1 Mar 2024 16:43:01 -0800 Subject: [PATCH] Enable Krew custom indexes --- src/kubectl/README.md | 1 + src/kubectl/Vagrantfile | 3 ++- src/kubectl/install.sh | 6 ++++++ test/kubectl/test.sh | 5 +++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/kubectl/README.md b/src/kubectl/README.md index 81451f632..19fb52b33 100644 --- a/src/kubectl/README.md +++ b/src/kubectl/README.md @@ -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 | diff --git a/src/kubectl/Vagrantfile b/src/kubectl/Vagrantfile index d49b3bf6f..bc3afacdc 100644 --- a/src/kubectl/Vagrantfile +++ b/src/kubectl/Vagrantfile @@ -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" } diff --git a/src/kubectl/install.sh b/src/kubectl/install.sh index 277cf32ce..fbc51e2d4 100755 --- a/src/kubectl/install.sh +++ b/src/kubectl/install.sh @@ -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" @@ -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..." @@ -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 diff --git a/test/kubectl/test.sh b/test/kubectl/test.sh index 58150f011..105b52bd2 100755 --- a/test/kubectl/test.sh +++ b/test/kubectl/test.sh @@ -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"