From 4ab7a6253983a7641a495551ced95d2361e4c8ee Mon Sep 17 00:00:00 2001 From: Svetlana Brennan <50715937+svetlanabrennan@users.noreply.github.com> Date: Tue, 19 Sep 2023 10:35:21 -0500 Subject: [PATCH] Update kubectl version command --- recipes/newrelic/infrastructure/kubernetes.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/recipes/newrelic/infrastructure/kubernetes.yml b/recipes/newrelic/infrastructure/kubernetes.yml index df0ddf00b..a78236f0a 100644 --- a/recipes/newrelic/infrastructure/kubernetes.yml +++ b/recipes/newrelic/infrastructure/kubernetes.yml @@ -147,11 +147,13 @@ install: # Check the Kubernetes version KUBECTL_VERSION=$($SUDO $KUBECTL version --short 2>&1) + SHORT_FLAG_ERROR=false # Check if $KUBECTL_VERSION contains an error with unknown flag --short # run again without --short flag since it was deprecated in kubectl version 1.28 if echo "$KUBECTL_VERSION" | grep -q "unknown flag: --short" then + SHORT_FLAG_ERROR=true KUBECTL_VERSION=$($SUDO $KUBECTL version 2>&1) fi @@ -322,12 +324,12 @@ install: fi fi - K8S_VERSION=$($SUDO $KUBECTL version --short | grep "Server Version") - # Check if $K8S_VERSION contains an error with unknown flag --short - # run again without --short flag since it was deprecated in kubectl version 1.28 - if echo ${K8S_VERSION} | grep -q "unknown flag: --short" - then + # SHORT_FLAG_ERROR will be true if it returned an --short flag error earlier in the script + # if SHORT_FLAG_ERROR is true, run KUBECTL version without --short flag since it was deprecated in kubectl version 1.28 + if $SHORT_FLAG_ERROR == true; then K8S_VERSION=$($SUDO $KUBECTL version | grep "Server Version") + else + K8S_VERSION=$($SUDO $KUBECTL version --short | grep "Server Version") fi if echo ${K8S_VERSION} | grep "\-gke\." >/dev/null; then