@@ -36,29 +36,34 @@ waitandretry() {
3636 fi
3737}
3838
39- function setup_arch_and_os(){
39+ function setup_arch_and_os() {
4040 ARCH=$( uname -m)
4141 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 ;;
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+ * )
51+ echo " Error architecture '${ARCH} ' unknown"
52+ exit 1
53+ ;;
5154 esac
5255
53- OS=$( uname | tr ' [:upper:]' ' [:lower:]' )
56+ OS=$( uname | tr ' [:upper:]' ' [:lower:]' )
5457 case " $OS " in
5558 # Minimalist GNU for Windows
56- " mingw" * ) OS=' windows' ; return ;;
59+ " mingw" * )
60+ OS=' windows'
61+ return
62+ ;;
5763 esac
5864}
5965
60-
61- function check_supported_arch_and_os(){
66+ function check_supported_arch_and_os() {
6267 local supported=$1
6368 local os=$2
6469 local arch=$3
@@ -89,8 +94,7 @@ function install_kubectl() {
8994 version=$( curl -L -s https://dl.k8s.io/release/stable.txt)
9095 fi
9196
92- if ! command -v " ${KUBECTL} " & > /dev/null
93- then
97+ if ! command -v " ${KUBECTL} " & > /dev/null; then
9498 echo " WARNING: kubectl could not be found. Downloading and installing it locally..."
9599 echo " Downloading https://dl.k8s.io/release/${version} /bin/${os} /${arch} /kubectl"
96100 if ! curl --fail -Lo " ${KUBECTL} " " https://dl.k8s.io/release/${version} /bin/${os} /${arch} /kubectl" ; then
@@ -100,6 +104,10 @@ function install_kubectl() {
100104 fi
101105
102106 chmod +x " ${KUBECTL} "
107+
108+ # Add BINDIR to PATH so credential plugins can find kubectl
109+ export PATH=" ${BINDIR} :${PATH} "
110+
103111 echo " kubectl version:"
104112 " ${KUBECTL} " version --client
105113}
@@ -114,8 +122,7 @@ function install_helm() {
114122
115123 HELM_VERSION=" v3.15.3"
116124
117- if ! command -v " ${HELM} " & > /dev/null
118- then
125+ if ! command -v " ${HELM} " & > /dev/null; then
119126 echo " WARNING: helm could not be found. Downloading and installing it locally..."
120127 if ! curl --fail -Lo " ./helm-${HELM_VERSION} -${os} -${arch} .tar.gz" " https://get.helm.sh/helm-${HELM_VERSION} -${os} -${arch} .tar.gz" ; then
121128 echo " Error: Unable to download helm for '${os} -${arch} '"
@@ -159,27 +166,24 @@ function install_gcloud() {
159166 cd -
160167
161168 # Login to gcloud
162- echo " ${GCLOUD_KEY} " | base64 -d > " ${BINDIR} /gke_key_file.json"
169+ echo " ${GCLOUD_KEY} " | base64 -d > " ${BINDIR} /gke_key_file.json"
163170 " ${GCLOUD} " auth activate-service-account --key-file=" ${BINDIR} /gke_key_file.json"
164171 " ${GCLOUD} " components install gke-gcloud-auth-plugin
165172}
166173
167174function install_az() {
168175 local os=$1
169176
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
177+ if ! command -v az & > /dev/null; then
178+ echo " Azure CLI could not be found. Downloading and installing..."
179+ if [[ " ${os} " == " linux" ]]; then
180+ curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
181+ elif [[ " ${os} " == " darwin" ]]; then
182+ brew update && brew install azure-cli
183+ else
184+ echo " Error: Azure CLI is not supported on ${os} "
185+ exit 1
186+ fi
183187 fi
184188
185189 echo " Azure CLI version:"
@@ -206,8 +210,7 @@ function wait_kyverno() {
206210 local kubeconfig=$1
207211
208212 # Wait for the kyverno deployments to be ready
209- if ! waitandretry 5s 2 " ${KUBECTL} rollout status deployment -n kyverno --kubeconfig ${kubeconfig} "
210- then
213+ if ! waitandretry 5s 2 " ${KUBECTL} rollout status deployment -n kyverno --kubeconfig ${kubeconfig} " ; then
211214 echo " Failed to wait for kyverno deployments to be ready"
212215 exit 1
213216 fi
@@ -221,3 +224,27 @@ function install_clusterctl() {
221224 sudo install -o root -g root -m 0755 clusterctl /usr/local/bin/clusterctl
222225 clusterctl version
223226}
227+
228+ function install_krew() {
229+ local os=$1
230+ local arch=$2
231+
232+ (
233+ set -x
234+ cd " $( mktemp -d) " &&
235+ KREW=" krew-${os} _${arch} " &&
236+ curl -fsSLO " https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW} .tar.gz" &&
237+ tar zxvf " ${KREW} .tar.gz" &&
238+ ./" ${KREW} " install krew
239+ )
240+
241+ # Add krew to PATH in .bashrc if not already present
242+ echo ' export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"' >> ~/.bashrc
243+
244+ # Export for current session
245+ export PATH=" ${KREW_ROOT:- $HOME / .krew} /bin:$PATH "
246+ }
247+
248+ function install_oidc() {
249+ " ${KUBECTL} " krew install oidc-login
250+ }
0 commit comments