From 8074e6893dd6315b9cb81d673648ff21baa59cd7 Mon Sep 17 00:00:00 2001 From: Svetlana Brennan <50715937+svetlanabrennan@users.noreply.github.com> Date: Wed, 27 Sep 2023 10:09:07 -0500 Subject: [PATCH] feat: Update minimum k8s version (#975) --- .../newrelic/infrastructure/kubernetes.yml | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/recipes/newrelic/infrastructure/kubernetes.yml b/recipes/newrelic/infrastructure/kubernetes.yml index fc938b309..a78236f0a 100644 --- a/recipes/newrelic/infrastructure/kubernetes.yml +++ b/recipes/newrelic/infrastructure/kubernetes.yml @@ -147,6 +147,16 @@ 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 + CLIENT_MAJOR_VERSION=$(echo "${KUBECTL_VERSION}" | grep 'Client Version' | awk -F' v' '{ print $2; }' | awk -F. '{ print $1; }') CLIENT_MINOR_VERSION=$(echo "${KUBECTL_VERSION}" | grep 'Client Version' | awk -F' v' '{ print $2; }' | awk -F. '{ print $2; }') SERVER_MAJOR_VERSION=$(echo "${KUBECTL_VERSION}" | grep 'Server Version' | awk -F' v' '{ print $2; }' | awk -F. '{ print $1; }') @@ -170,8 +180,8 @@ install: exit 131 fi - if [[ "$SERVER_MAJOR_VERSION" -lt 1 ]] || [[ "$SERVER_MAJOR_VERSION" -eq 1 && "$SERVER_MINOR_VERSION" -lt 16 ]] || [[ "$SERVER_MAJOR_VERSION" -eq 1 && "$SERVER_MINOR_VERSION" -gt 27 ]]; then - echo "Installation failed. Kubernetes v1.16 to v1.27 is required, found v${SERVER_MAJOR_VERSION}.${SERVER_MINOR_VERSION}" >&2 + if [[ "$SERVER_MAJOR_VERSION" -lt 1 ]] || [[ "$SERVER_MAJOR_VERSION" -eq 1 && "$SERVER_MINOR_VERSION" -lt 23 ]] || [[ "$SERVER_MAJOR_VERSION" -eq 1 && "$SERVER_MINOR_VERSION" -gt 27 ]]; then + echo "Installation failed. Kubernetes v1.23 to v1.27 is required, found v${SERVER_MAJOR_VERSION}.${SERVER_MINOR_VERSION}" >&2 echo "{\"Metadata\":{\"UnsupportedReason\":\"Unsupported k8s version - found $SERVER_MAJOR_VERSION.$SERVER_MINOR_VERSION\", \"K8sClientVersion\":\"$CLIENT_MAJOR_VERSION.$CLIENT_MINOR_VERSION\", \"K8sServerVersion\":\"$SERVER_MAJOR_VERSION.$SERVER_MINOR_VERSION\"}}" | tee -a {{.NR_CLI_OUTPUT}} exit 131 fi @@ -314,7 +324,14 @@ install: fi fi - K8S_VERSION=$($SUDO $KUBECTL version --short | grep "Server Version") + # 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 PIXIE_SUPPORTED=true fi