11#! /usr/bin/env bash
22# shellcheck disable=SC1091
33
4+ # Setup PATH to include BINDIR for kubectl and other tools
5+ # This ensures credential plugins can find kubectl
6+ setup_path () {
7+ if [ -n " ${BINDIR:- } " ]; then
8+ export PATH=" ${BINDIR} :${PATH} "
9+ fi
10+ }
11+
412# Define the retry function
513waitandretry () {
614 local waittime=" $1 "
@@ -36,29 +44,34 @@ waitandretry() {
3644 fi
3745}
3846
39- function setup_arch_and_os(){
47+ function setup_arch_and_os() {
4048 ARCH=$( uname -m)
4149 case $ARCH in
42- armv5* ) ARCH=" armv5" ;;
43- armv6* ) ARCH=" armv6" ;;
44- armv7* ) ARCH=" arm" ;;
45- aarch64) ARCH=" arm64" ;;
46- x86) ARCH=" 386" ;;
47- x86_64) ARCH=" amd64" ;;
48- i686) ARCH=" 386" ;;
49- i386) ARCH=" 386" ;;
50- * ) echo " Error architecture '${ARCH} ' unknown" ; exit 1 ;;
50+ armv5* ) ARCH=" armv5" ;;
51+ armv6* ) ARCH=" armv6" ;;
52+ armv7* ) ARCH=" arm" ;;
53+ aarch64) ARCH=" arm64" ;;
54+ x86) ARCH=" 386" ;;
55+ x86_64) ARCH=" amd64" ;;
56+ i686) ARCH=" 386" ;;
57+ i386) ARCH=" 386" ;;
58+ * )
59+ echo " Error architecture '${ARCH} ' unknown"
60+ exit 1
61+ ;;
5162 esac
5263
53- OS=$( uname | tr ' [:upper:]' ' [:lower:]' )
64+ OS=$( uname | tr ' [:upper:]' ' [:lower:]' )
5465 case " $OS " in
5566 # Minimalist GNU for Windows
56- " mingw" * ) OS=' windows' ; return ;;
67+ " mingw" * )
68+ OS=' windows'
69+ return
70+ ;;
5771 esac
5872}
5973
60-
61- function check_supported_arch_and_os(){
74+ function check_supported_arch_and_os() {
6275 local supported=$1
6376 local os=$2
6477 local arch=$3
@@ -89,8 +102,7 @@ function install_kubectl() {
89102 version=$( curl -L -s https://dl.k8s.io/release/stable.txt)
90103 fi
91104
92- if ! command -v " ${KUBECTL} " & > /dev/null
93- then
105+ if ! command -v " ${KUBECTL} " & > /dev/null; then
94106 echo " WARNING: kubectl could not be found. Downloading and installing it locally..."
95107 echo " Downloading https://dl.k8s.io/release/${version} /bin/${os} /${arch} /kubectl"
96108 if ! curl --fail -Lo " ${KUBECTL} " " https://dl.k8s.io/release/${version} /bin/${os} /${arch} /kubectl" ; then
@@ -100,6 +112,10 @@ function install_kubectl() {
100112 fi
101113
102114 chmod +x " ${KUBECTL} "
115+
116+ # Setup PATH to include BINDIR
117+ setup_path
118+
103119 echo " kubectl version:"
104120 " ${KUBECTL} " version --client
105121}
@@ -114,8 +130,7 @@ function install_helm() {
114130
115131 HELM_VERSION=" v3.15.3"
116132
117- if ! command -v " ${HELM} " & > /dev/null
118- then
133+ if ! command -v " ${HELM} " & > /dev/null; then
119134 echo " WARNING: helm could not be found. Downloading and installing it locally..."
120135 if ! curl --fail -Lo " ./helm-${HELM_VERSION} -${os} -${arch} .tar.gz" " https://get.helm.sh/helm-${HELM_VERSION} -${os} -${arch} .tar.gz" ; then
121136 echo " Error: Unable to download helm for '${os} -${arch} '"
@@ -159,27 +174,24 @@ function install_gcloud() {
159174 cd -
160175
161176 # Login to gcloud
162- echo " ${GCLOUD_KEY} " | base64 -d > " ${BINDIR} /gke_key_file.json"
177+ echo " ${GCLOUD_KEY} " | base64 -d > " ${BINDIR} /gke_key_file.json"
163178 " ${GCLOUD} " auth activate-service-account --key-file=" ${BINDIR} /gke_key_file.json"
164179 " ${GCLOUD} " components install gke-gcloud-auth-plugin
165180}
166181
167182function install_az() {
168183 local os=$1
169184
170- if ! command -v az & > /dev/null
171- then
172- echo " Azure CLI could not be found. Downloading and installing..."
173- if [[ " ${os} " == " linux" ]]
174- then
175- curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
176- elif [[ " ${os} " == " darwin" ]]
177- then
178- brew update && brew install azure-cli
179- else
180- echo " Error: Azure CLI is not supported on ${os} "
181- exit 1
182- fi
185+ if ! command -v az & > /dev/null; then
186+ echo " Azure CLI could not be found. Downloading and installing..."
187+ if [[ " ${os} " == " linux" ]]; then
188+ curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
189+ elif [[ " ${os} " == " darwin" ]]; then
190+ brew update && brew install azure-cli
191+ else
192+ echo " Error: Azure CLI is not supported on ${os} "
193+ exit 1
194+ fi
183195 fi
184196
185197 echo " Azure CLI version:"
@@ -206,8 +218,7 @@ function wait_kyverno() {
206218 local kubeconfig=$1
207219
208220 # Wait for the kyverno deployments to be ready
209- if ! waitandretry 5s 2 " ${KUBECTL} rollout status deployment -n kyverno --kubeconfig ${kubeconfig} "
210- then
221+ if ! waitandretry 5s 2 " ${KUBECTL} rollout status deployment -n kyverno --kubeconfig ${kubeconfig} " ; then
211222 echo " Failed to wait for kyverno deployments to be ready"
212223 exit 1
213224 fi
@@ -221,3 +232,27 @@ function install_clusterctl() {
221232 sudo install -o root -g root -m 0755 clusterctl /usr/local/bin/clusterctl
222233 clusterctl version
223234}
235+
236+ function install_krew() {
237+ local os=$1
238+ local arch=$2
239+
240+ (
241+ set -x
242+ cd " $( mktemp -d) " &&
243+ KREW=" krew-${os} _${arch} " &&
244+ curl -fsSLO " https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW} .tar.gz" &&
245+ tar zxvf " ${KREW} .tar.gz" &&
246+ ./" ${KREW} " install krew
247+ )
248+
249+ # Add krew to PATH in .bashrc if not already present
250+ echo ' export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"' >> ~/.bashrc
251+
252+ # Export for current session
253+ export PATH=" ${KREW_ROOT:- $HOME / .krew} /bin:$PATH "
254+ }
255+
256+ function install_oidc() {
257+ " ${KUBECTL} " krew install oidc-login
258+ }
0 commit comments