sassoftware / viya4-monitoring-kubernetes

Provides simple scripts and customization options to deploy monitoring, alerts, and log aggregation for Viya 4 running on Kubernetes
Apache License 2.0
50 stars 31 forks source link

Sos2403b #616

Closed gsmith-sas closed 4 months ago

github-actions[bot] commented 4 months ago

sh-checker report

To get the full details, please check in the job output.

shellcheck errors ``` 'shellcheck -e SC1004' returned error 1 finding the following syntactical issues: ---------- In bin/openshift-include.sh line 1: # Copyright © 2021, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. ^-- SC2148 (error): Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. In bin/openshift-include.sh line 11: allArr=($(oc version 2>/dev/null)) ^-----------------------^ SC2207 (warning): Prefer mapfile or read -a to split command output (or quote to avoid splitting). In bin/openshift-include.sh line 16: verArr=(${allArr[$i]}) ^-----------^ SC2206 (warning): Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a. In bin/openshift-include.sh line 97: if [ ! $(which oc) ]; then ^---------^ SC2046 (warning): Quote this to prevent word splitting. For more information: https://www.shellcheck.net/wiki/SC2148 -- Tips depend on target shell and y... https://www.shellcheck.net/wiki/SC2046 -- Quote this to prevent word splitt... https://www.shellcheck.net/wiki/SC2206 -- Quote to prevent word splitting/g... ---------- You can address the above issues in one of three ways: 1. Manually correct the issue in the offending shell script; 2. Disable specific issues by adding the comment: # shellcheck disable=NNNN above the line that contains the issue, where NNNN is the error code; 3. Add '-e NNNN' to the SHELLCHECK_OPTS setting in your .yml action file. ```
shfmt errors ``` 'shfmt -s' returned error 1 finding the following formatting issues: ---------- --- bin/kube-include.sh.orig +++ bin/kube-include.sh @@ -7,8 +7,8 @@ # Assumes bin/common.sh has been sourced if [ ! "$(which kubectl)" ]; then - log_error "kubectl not found on the current PATH" - exit 1 + log_error "kubectl not found on the current PATH" + exit 1 fi KUBE_CLIENT_VER=$(kubectl version --short | grep 'Client Version' | awk '{print $3}' 2>/dev/null) @@ -16,10 +16,10 @@ # Client version allowed to be one minor version earlier than minimum server version if [[ $KUBE_CLIENT_VER =~ v1.2[0-9] ]]; then - : -else - log_warn "Unsupported kubectl version: [$KUBE_CLIENT_VER]." - log_warn "This script might not work as expected. Support might not be available until kubectl is upgraded to a supported version." + : +else + log_warn "Unsupported kubectl version: [$KUBE_CLIENT_VER]." + log_warn "This script might not work as expected. Support might not be available until kubectl is upgraded to a supported version." fi # SAS Viya 4 versions @@ -34,10 +34,10 @@ # 2024.02 1.26 1.28 if [[ $KUBE_SERVER_VER =~ v1.2[1-9] ]]; then - : -else - log_warn "The detected version of Kubernetes [$KUBE_SERVER_VER] is not supported by any of the currently supported releases of SAS Viya." - log_warn "This script might not work as expected. Support might not be available until Kubernetes is upgraded to a supported version." + : +else + log_warn "The detected version of Kubernetes [$KUBE_SERVER_VER] is not supported by any of the currently supported releases of SAS Viya." + log_warn "This script might not work as expected. Support might not be available until Kubernetes is upgraded to a supported version." fi export KUBE_CLIENT_VER="$KUBE_CLIENT_VER" --- bin/openshift-include.sh.orig +++ bin/openshift-include.sh @@ -5,117 +5,117 @@ # Assumes bin/common.sh has been sourced function ocVersionCheck { - origIFS=$IFS - IFS=$'\n' + origIFS=$IFS + IFS=$'\n' - allArr=($(oc version 2>/dev/null)) - IFS=$origIFS + allArr=($(oc version 2>/dev/null)) + IFS=$origIFS - for (( i=0; i<${#allArr[@]}; i++ )); do - # Split the line into an array - verArr=(${allArr[$i]}) - if [ ${#verArr[@]} -eq 3 ]; then - verType="${verArr[0]}" - ver="${verArr[2]}" - if [ "$verType" == "Client" ]; then - ver="${verArr[2]}" - if [[ $ver =~ v?(([0-9]+)\.([0-9]+)\.([0-9]+)) ]]; then - OC_FULL_VERSION=${BASH_REMATCH[1]} - OC_MAJOR_VERSION=${BASH_REMATCH[2]} - OC_MINOR_VERSION=${BASH_REMATCH[3]} - OC_PATCH_VERSION=${BASH_REMATCH[4]} - else - echo "Unable to parse client version: [$ver]" - fi - elif [ "$verType" == "Server" ]; then - ver="${verArr[2]}" - if [[ $ver =~ (([0-9]+)\.([0-9]+)\.([0-9]+)) ]]; then - OSHIFT_FULL_VERSION=${BASH_REMATCH[1]} - OSHIFT_MAJOR_VERSION=${BASH_REMATCH[2]} - OSHIFT_MINOR_VERSION=${BASH_REMATCH[3]} - OSHIFT_PATCH_VERSION=${BASH_REMATCH[4]} - else - echo "Unable to parse server version: [$ver]" - fi - fi - fi - done - log_info "OpenShift client version: $OC_FULL_VERSION" - log_info "OpenShift server version: $OSHIFT_FULL_VERSION" - - # Version enforcement - if [ "$OPENSHIFT_VERSION_CHECK" == "true" ]; then - ## Server Version - ### Openshift versions that do not start with a 4 should produce an error. - if (( "$OSHIFT_MAJOR_VERSION" != 4 )); then - log_error "Unsupported OpenShift server version: $OSHIFT_FULL_VERSION" - log_error "Version 4.12+ is required" - exit 1 - ### 21FEB24: Openshift 4 versions earlier than 4.12 should produce an error. - elif (( "$OSHIFT_MINOR_VERSION" < 12 )); then - log_error "Unsupported OpenShift server version: $OSHIFT_FULL_VERSION" - log_error "Version 4.12+ is required" - exit 1 - else - log_debug "OpenShift server version check OK" - fi + for ((i = 0; i < ${#allArr[@]}; i++)); do + # Split the line into an array + verArr=(${allArr[$i]}) + if [ ${#verArr[@]} -eq 3 ]; then + verType="${verArr[0]}" + ver="${verArr[2]}" + if [ "$verType" == "Client" ]; then + ver="${verArr[2]}" + if [[ $ver =~ v?(([0-9]+)\.([0-9]+)\.([0-9]+)) ]]; then + OC_FULL_VERSION=${BASH_REMATCH[1]} + OC_MAJOR_VERSION=${BASH_REMATCH[2]} + OC_MINOR_VERSION=${BASH_REMATCH[3]} + OC_PATCH_VERSION=${BASH_REMATCH[4]} + else + echo "Unable to parse client version: [$ver]" + fi + elif [ "$verType" == "Server" ]; then + ver="${verArr[2]}" + if [[ $ver =~ (([0-9]+)\.([0-9]+)\.([0-9]+)) ]]; then + OSHIFT_FULL_VERSION=${BASH_REMATCH[1]} + OSHIFT_MAJOR_VERSION=${BASH_REMATCH[2]} + OSHIFT_MINOR_VERSION=${BASH_REMATCH[3]} + OSHIFT_PATCH_VERSION=${BASH_REMATCH[4]} + else + echo "Unable to parse server version: [$ver]" + fi + fi + fi + done + log_info "OpenShift client version: $OC_FULL_VERSION" + log_info "OpenShift server version: $OSHIFT_FULL_VERSION" - ## Client Version - ### Openshift versions that do not start with a 4 should produce an error. - if (( "$OC_MAJOR_VERSION" != 4 )); then - log_error "Unsupported OpenShift client version: $OC_FULL_VERSION" - log_error "Version 4.11+ is required" - exit 1 - ### Openshift 4 client version must be w/in 1 minor releases of server minimum. - elif (( "$OC_MINOR_VERSION" < 11 )); then - log_error "Unsupported OpenShift client version: $OC_FULL_VERSION" - log_error "Version 4.11+ is required" - exit 1 - else - log_debug "OpenShift client version check OK" - fi - fi + # Version enforcement + if [ "$OPENSHIFT_VERSION_CHECK" == "true" ]; then + ## Server Version + ### Openshift versions that do not start with a 4 should produce an error. + if (("$OSHIFT_MAJOR_VERSION" != 4)); then + log_error "Unsupported OpenShift server version: $OSHIFT_FULL_VERSION" + log_error "Version 4.12+ is required" + exit 1 + ### 21FEB24: Openshift 4 versions earlier than 4.12 should produce an error. + elif (("$OSHIFT_MINOR_VERSION" < 12)); then + log_error "Unsupported OpenShift server version: $OSHIFT_FULL_VERSION" + log_error "Version 4.12+ is required" + exit 1 + else + log_debug "OpenShift server version check OK" + fi + + ## Client Version + ### Openshift versions that do not start with a 4 should produce an error. + if (("$OC_MAJOR_VERSION" != 4)); then + log_error "Unsupported OpenShift client version: $OC_FULL_VERSION" + log_error "Version 4.11+ is required" + exit 1 + ### Openshift 4 client version must be w/in 1 minor releases of server minimum. + elif (("$OC_MINOR_VERSION" < 11)); then + log_error "Unsupported OpenShift client version: $OC_FULL_VERSION" + log_error "Version 4.11+ is required" + exit 1 + else + log_debug "OpenShift client version check OK" + fi + fi } OPENSHIFT_VERSION_CHECK=${OPENSHIFT_VERSION_CHECK:-true} if [ "$SAS_OPENSHIFT_SOURCED" != "true" ]; then - if [ "$OPENSHIFT_CLUSTER" == "" ]; then - # Detect OpenShift cluster - if kubectl get ns openshift 2>/dev/null 1>&2; then - log_debug "OpenShift detected" - OPENSHIFT_CLUSTER="true" - else - log_debug "OpenShift not detected" - OPENSHIFT_CLUSTER="false" - fi - else - log_debug "Skipping OpenShift detection. OPENSHIFT_CLUSTER=[$OPENSHIFT_CLUSTER]" - fi + if [ "$OPENSHIFT_CLUSTER" == "" ]; then + # Detect OpenShift cluster + if kubectl get ns openshift 2>/dev/null 1>&2; then + log_debug "OpenShift detected" + OPENSHIFT_CLUSTER="true" + else + log_debug "OpenShift not detected" + OPENSHIFT_CLUSTER="false" + fi + else + log_debug "Skipping OpenShift detection. OPENSHIFT_CLUSTER=[$OPENSHIFT_CLUSTER]" + fi - if [ "$OPENSHIFT_CLUSTER" == "true" ]; then - if [ "${OPENSHIFT_OC_CHECK:-true}" == "true" ]; then - if [ ! $(which oc) ]; then - echo "'oc' is required for OpenShift and not found on the current PATH" - exit 1 - fi - ocVersionCheck + if [ "$OPENSHIFT_CLUSTER" == "true" ]; then + if [ "${OPENSHIFT_OC_CHECK:-true}" == "true" ]; then + if [ ! $(which oc) ]; then + echo "'oc' is required for OpenShift and not found on the current PATH" + exit 1 + fi + ocVersionCheck - # Get base OpenShift route hostname - OPENSHIFT_ROUTE_DOMAIN=${OPENSHIFT_ROUTE_DOMAIN:-$(oc get route -n openshift-console console -o 'jsonpath={.spec.host}' | cut -c 27-)} - if [ "$OPENSHIFT_ROUTE_DOMAIN" != "" ]; then - log_debug "OpenShift route host is [$OPENSHIFT_ROUTE_DOMAIN]" - else - log_error "Unable to determine OpenShift route host. Set OPENSHIFT_ROUTE_DOMAIN if necessary." - exit 1 - fi + # Get base OpenShift route hostname + OPENSHIFT_ROUTE_DOMAIN=${OPENSHIFT_ROUTE_DOMAIN:-$(oc get route -n openshift-console console -o 'jsonpath={.spec.host}' | cut -c 27-)} + if [ "$OPENSHIFT_ROUTE_DOMAIN" != "" ]; then + log_debug "OpenShift route host is [$OPENSHIFT_ROUTE_DOMAIN]" + else + log_error "Unable to determine OpenShift route host. Set OPENSHIFT_ROUTE_DOMAIN if necessary." + exit 1 + fi - export OPENSHIFT_ROUTE_DOMAIN - export OC_MAJOR_VERSION OC_MINOR_VERSION OC_PATCH_VERSION - export OSHIFT_MAJOR_VERSION OSHIFT_MINOR_VERSION OSHIFT_PATCH_VERSION - fi - else - log_debug "OpenShift not detected. Skipping 'oc' checks." - fi - export OPENSHIFT_CLUSTER - export SAS_OPENSHIFT_SOURCED="true" + export OPENSHIFT_ROUTE_DOMAIN + export OC_MAJOR_VERSION OC_MINOR_VERSION OC_PATCH_VERSION + export OSHIFT_MAJOR_VERSION OSHIFT_MINOR_VERSION OSHIFT_PATCH_VERSION + fi + else + log_debug "OpenShift not detected. Skipping 'oc' checks." + fi + export OPENSHIFT_CLUSTER + export SAS_OPENSHIFT_SOURCED="true" fi ---------- You can reformat the above files to meet shfmt's requirements by typing: shfmt -s -w filename ```
github-actions[bot] commented 4 months ago

sh-checker report

To get the full details, please check in the job output.

shellcheck errors ``` 'shellcheck -e SC1004' returned error 1 finding the following syntactical issues: ---------- In bin/openshift-include.sh line 1: # Copyright © 2021, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. ^-- SC2148 (error): Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. In bin/openshift-include.sh line 11: allArr=($(oc version 2>/dev/null)) ^-----------------------^ SC2207 (warning): Prefer mapfile or read -a to split command output (or quote to avoid splitting). In bin/openshift-include.sh line 16: verArr=(${allArr[$i]}) ^-----------^ SC2206 (warning): Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a. In bin/openshift-include.sh line 97: if [ ! $(which oc) ]; then ^---------^ SC2046 (warning): Quote this to prevent word splitting. For more information: https://www.shellcheck.net/wiki/SC2148 -- Tips depend on target shell and y... https://www.shellcheck.net/wiki/SC2046 -- Quote this to prevent word splitt... https://www.shellcheck.net/wiki/SC2206 -- Quote to prevent word splitting/g... ---------- You can address the above issues in one of three ways: 1. Manually correct the issue in the offending shell script; 2. Disable specific issues by adding the comment: # shellcheck disable=NNNN above the line that contains the issue, where NNNN is the error code; 3. Add '-e NNNN' to the SHELLCHECK_OPTS setting in your .yml action file. ```
shfmt errors ``` 'shfmt -s' returned error 1 finding the following formatting issues: ---------- --- bin/kube-include.sh.orig +++ bin/kube-include.sh @@ -7,8 +7,8 @@ # Assumes bin/common.sh has been sourced if [ ! "$(which kubectl)" ]; then - log_error "kubectl not found on the current PATH" - exit 1 + log_error "kubectl not found on the current PATH" + exit 1 fi KUBE_CLIENT_VER=$(kubectl version --short | grep 'Client Version' | awk '{print $3}' 2>/dev/null) @@ -16,10 +16,10 @@ # Client version allowed to be one minor version earlier than minimum server version if [[ $KUBE_CLIENT_VER =~ v1.2[0-9] ]]; then - : -else - log_warn "Unsupported kubectl version: [$KUBE_CLIENT_VER]." - log_warn "This script might not work as expected. Support might not be available until kubectl is upgraded to a supported version." + : +else + log_warn "Unsupported kubectl version: [$KUBE_CLIENT_VER]." + log_warn "This script might not work as expected. Support might not be available until kubectl is upgraded to a supported version." fi # SAS Viya 4 versions @@ -34,10 +34,10 @@ # 2024.02 1.26 1.28 if [[ $KUBE_SERVER_VER =~ v1.2[1-9] ]]; then - : -else - log_warn "The detected version of Kubernetes [$KUBE_SERVER_VER] is not supported by any of the currently supported releases of SAS Viya." - log_warn "This script might not work as expected. Support might not be available until Kubernetes is upgraded to a supported version." + : +else + log_warn "The detected version of Kubernetes [$KUBE_SERVER_VER] is not supported by any of the currently supported releases of SAS Viya." + log_warn "This script might not work as expected. Support might not be available until Kubernetes is upgraded to a supported version." fi export KUBE_CLIENT_VER="$KUBE_CLIENT_VER" --- bin/openshift-include.sh.orig +++ bin/openshift-include.sh @@ -5,117 +5,117 @@ # Assumes bin/common.sh has been sourced function ocVersionCheck { - origIFS=$IFS - IFS=$'\n' + origIFS=$IFS + IFS=$'\n' - allArr=($(oc version 2>/dev/null)) - IFS=$origIFS + allArr=($(oc version 2>/dev/null)) + IFS=$origIFS - for (( i=0; i<${#allArr[@]}; i++ )); do - # Split the line into an array - verArr=(${allArr[$i]}) - if [ ${#verArr[@]} -eq 3 ]; then - verType="${verArr[0]}" - ver="${verArr[2]}" - if [ "$verType" == "Client" ]; then - ver="${verArr[2]}" - if [[ $ver =~ v?(([0-9]+)\.([0-9]+)\.([0-9]+)) ]]; then - OC_FULL_VERSION=${BASH_REMATCH[1]} - OC_MAJOR_VERSION=${BASH_REMATCH[2]} - OC_MINOR_VERSION=${BASH_REMATCH[3]} - OC_PATCH_VERSION=${BASH_REMATCH[4]} - else - echo "Unable to parse client version: [$ver]" - fi - elif [ "$verType" == "Server" ]; then - ver="${verArr[2]}" - if [[ $ver =~ (([0-9]+)\.([0-9]+)\.([0-9]+)) ]]; then - OSHIFT_FULL_VERSION=${BASH_REMATCH[1]} - OSHIFT_MAJOR_VERSION=${BASH_REMATCH[2]} - OSHIFT_MINOR_VERSION=${BASH_REMATCH[3]} - OSHIFT_PATCH_VERSION=${BASH_REMATCH[4]} - else - echo "Unable to parse server version: [$ver]" - fi - fi - fi - done - log_info "OpenShift client version: $OC_FULL_VERSION" - log_info "OpenShift server version: $OSHIFT_FULL_VERSION" - - # Version enforcement - if [ "$OPENSHIFT_VERSION_CHECK" == "true" ]; then - ## Server Version - ### Openshift versions that do not start with a 4 should produce an error. - if (( "$OSHIFT_MAJOR_VERSION" != 4 )); then - log_error "Unsupported OpenShift server version: $OSHIFT_FULL_VERSION" - log_error "Version 4.12+ is required" - exit 1 - ### 21FEB24: Openshift 4 versions earlier than 4.12 should produce an error. - elif (( "$OSHIFT_MINOR_VERSION" < 12 )); then - log_error "Unsupported OpenShift server version: $OSHIFT_FULL_VERSION" - log_error "Version 4.12+ is required" - exit 1 - else - log_debug "OpenShift server version check OK" - fi + for ((i = 0; i < ${#allArr[@]}; i++)); do + # Split the line into an array + verArr=(${allArr[$i]}) + if [ ${#verArr[@]} -eq 3 ]; then + verType="${verArr[0]}" + ver="${verArr[2]}" + if [ "$verType" == "Client" ]; then + ver="${verArr[2]}" + if [[ $ver =~ v?(([0-9]+)\.([0-9]+)\.([0-9]+)) ]]; then + OC_FULL_VERSION=${BASH_REMATCH[1]} + OC_MAJOR_VERSION=${BASH_REMATCH[2]} + OC_MINOR_VERSION=${BASH_REMATCH[3]} + OC_PATCH_VERSION=${BASH_REMATCH[4]} + else + echo "Unable to parse client version: [$ver]" + fi + elif [ "$verType" == "Server" ]; then + ver="${verArr[2]}" + if [[ $ver =~ (([0-9]+)\.([0-9]+)\.([0-9]+)) ]]; then + OSHIFT_FULL_VERSION=${BASH_REMATCH[1]} + OSHIFT_MAJOR_VERSION=${BASH_REMATCH[2]} + OSHIFT_MINOR_VERSION=${BASH_REMATCH[3]} + OSHIFT_PATCH_VERSION=${BASH_REMATCH[4]} + else + echo "Unable to parse server version: [$ver]" + fi + fi + fi + done + log_info "OpenShift client version: $OC_FULL_VERSION" + log_info "OpenShift server version: $OSHIFT_FULL_VERSION" - ## Client Version - ### Openshift versions that do not start with a 4 should produce an error. - if (( "$OC_MAJOR_VERSION" != 4 )); then - log_error "Unsupported OpenShift client version: $OC_FULL_VERSION" - log_error "Version 4.11+ is required" - exit 1 - ### Openshift 4 client version must be w/in 1 minor releases of server minimum. - elif (( "$OC_MINOR_VERSION" < 11 )); then - log_error "Unsupported OpenShift client version: $OC_FULL_VERSION" - log_error "Version 4.11+ is required" - exit 1 - else - log_debug "OpenShift client version check OK" - fi - fi + # Version enforcement + if [ "$OPENSHIFT_VERSION_CHECK" == "true" ]; then + ## Server Version + ### Openshift versions that do not start with a 4 should produce an error. + if (("$OSHIFT_MAJOR_VERSION" != 4)); then + log_error "Unsupported OpenShift server version: $OSHIFT_FULL_VERSION" + log_error "Version 4.12+ is required" + exit 1 + ### 21FEB24: Openshift 4 versions earlier than 4.12 should produce an error. + elif (("$OSHIFT_MINOR_VERSION" < 12)); then + log_error "Unsupported OpenShift server version: $OSHIFT_FULL_VERSION" + log_error "Version 4.12+ is required" + exit 1 + else + log_debug "OpenShift server version check OK" + fi + + ## Client Version + ### Openshift versions that do not start with a 4 should produce an error. + if (("$OC_MAJOR_VERSION" != 4)); then + log_error "Unsupported OpenShift client version: $OC_FULL_VERSION" + log_error "Version 4.11+ is required" + exit 1 + ### Openshift 4 client version must be w/in 1 minor releases of server minimum. + elif (("$OC_MINOR_VERSION" < 11)); then + log_error "Unsupported OpenShift client version: $OC_FULL_VERSION" + log_error "Version 4.11+ is required" + exit 1 + else + log_debug "OpenShift client version check OK" + fi + fi } OPENSHIFT_VERSION_CHECK=${OPENSHIFT_VERSION_CHECK:-true} if [ "$SAS_OPENSHIFT_SOURCED" != "true" ]; then - if [ "$OPENSHIFT_CLUSTER" == "" ]; then - # Detect OpenShift cluster - if kubectl get ns openshift 2>/dev/null 1>&2; then - log_debug "OpenShift detected" - OPENSHIFT_CLUSTER="true" - else - log_debug "OpenShift not detected" - OPENSHIFT_CLUSTER="false" - fi - else - log_debug "Skipping OpenShift detection. OPENSHIFT_CLUSTER=[$OPENSHIFT_CLUSTER]" - fi + if [ "$OPENSHIFT_CLUSTER" == "" ]; then + # Detect OpenShift cluster + if kubectl get ns openshift 2>/dev/null 1>&2; then + log_debug "OpenShift detected" + OPENSHIFT_CLUSTER="true" + else + log_debug "OpenShift not detected" + OPENSHIFT_CLUSTER="false" + fi + else + log_debug "Skipping OpenShift detection. OPENSHIFT_CLUSTER=[$OPENSHIFT_CLUSTER]" + fi - if [ "$OPENSHIFT_CLUSTER" == "true" ]; then - if [ "${OPENSHIFT_OC_CHECK:-true}" == "true" ]; then - if [ ! $(which oc) ]; then - echo "'oc' is required for OpenShift and not found on the current PATH" - exit 1 - fi - ocVersionCheck + if [ "$OPENSHIFT_CLUSTER" == "true" ]; then + if [ "${OPENSHIFT_OC_CHECK:-true}" == "true" ]; then + if [ ! $(which oc) ]; then + echo "'oc' is required for OpenShift and not found on the current PATH" + exit 1 + fi + ocVersionCheck - # Get base OpenShift route hostname - OPENSHIFT_ROUTE_DOMAIN=${OPENSHIFT_ROUTE_DOMAIN:-$(oc get route -n openshift-console console -o 'jsonpath={.spec.host}' | cut -c 27-)} - if [ "$OPENSHIFT_ROUTE_DOMAIN" != "" ]; then - log_debug "OpenShift route host is [$OPENSHIFT_ROUTE_DOMAIN]" - else - log_error "Unable to determine OpenShift route host. Set OPENSHIFT_ROUTE_DOMAIN if necessary." - exit 1 - fi + # Get base OpenShift route hostname + OPENSHIFT_ROUTE_DOMAIN=${OPENSHIFT_ROUTE_DOMAIN:-$(oc get route -n openshift-console console -o 'jsonpath={.spec.host}' | cut -c 27-)} + if [ "$OPENSHIFT_ROUTE_DOMAIN" != "" ]; then + log_debug "OpenShift route host is [$OPENSHIFT_ROUTE_DOMAIN]" + else + log_error "Unable to determine OpenShift route host. Set OPENSHIFT_ROUTE_DOMAIN if necessary." + exit 1 + fi - export OPENSHIFT_ROUTE_DOMAIN - export OC_MAJOR_VERSION OC_MINOR_VERSION OC_PATCH_VERSION - export OSHIFT_MAJOR_VERSION OSHIFT_MINOR_VERSION OSHIFT_PATCH_VERSION - fi - else - log_debug "OpenShift not detected. Skipping 'oc' checks." - fi - export OPENSHIFT_CLUSTER - export SAS_OPENSHIFT_SOURCED="true" + export OPENSHIFT_ROUTE_DOMAIN + export OC_MAJOR_VERSION OC_MINOR_VERSION OC_PATCH_VERSION + export OSHIFT_MAJOR_VERSION OSHIFT_MINOR_VERSION OSHIFT_PATCH_VERSION + fi + else + log_debug "OpenShift not detected. Skipping 'oc' checks." + fi + export OPENSHIFT_CLUSTER + export SAS_OPENSHIFT_SOURCED="true" fi ---------- You can reformat the above files to meet shfmt's requirements by typing: shfmt -s -w filename ```
github-actions[bot] commented 4 months ago

sh-checker report

To get the full details, please check in the job output.

shellcheck errors ``` 'shellcheck -e SC1004' returned error 1 finding the following syntactical issues: ---------- In bin/openshift-include.sh line 1: # Copyright © 2021, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. ^-- SC2148 (error): Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. In bin/openshift-include.sh line 11: allArr=($(oc version 2>/dev/null)) ^-----------------------^ SC2207 (warning): Prefer mapfile or read -a to split command output (or quote to avoid splitting). In bin/openshift-include.sh line 16: verArr=(${allArr[$i]}) ^-----------^ SC2206 (warning): Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a. In bin/openshift-include.sh line 97: if [ ! $(which oc) ]; then ^---------^ SC2046 (warning): Quote this to prevent word splitting. For more information: https://www.shellcheck.net/wiki/SC2148 -- Tips depend on target shell and y... https://www.shellcheck.net/wiki/SC2046 -- Quote this to prevent word splitt... https://www.shellcheck.net/wiki/SC2206 -- Quote to prevent word splitting/g... ---------- You can address the above issues in one of three ways: 1. Manually correct the issue in the offending shell script; 2. Disable specific issues by adding the comment: # shellcheck disable=NNNN above the line that contains the issue, where NNNN is the error code; 3. Add '-e NNNN' to the SHELLCHECK_OPTS setting in your .yml action file. ```
shfmt errors ``` 'shfmt -s' returned error 1 finding the following formatting issues: ---------- --- bin/kube-include.sh.orig +++ bin/kube-include.sh @@ -7,8 +7,8 @@ # Assumes bin/common.sh has been sourced if [ ! "$(which kubectl)" ]; then - log_error "kubectl not found on the current PATH" - exit 1 + log_error "kubectl not found on the current PATH" + exit 1 fi KUBE_CLIENT_VER=$(kubectl version --short | grep 'Client Version' | awk '{print $3}' 2>/dev/null) @@ -16,10 +16,10 @@ # Client version allowed to be one minor version earlier than minimum server version if [[ $KUBE_CLIENT_VER =~ v1.2[0-9] ]]; then - : -else - log_warn "Unsupported kubectl version: [$KUBE_CLIENT_VER]." - log_warn "This script might not work as expected. Support might not be available until kubectl is upgraded to a supported version." + : +else + log_warn "Unsupported kubectl version: [$KUBE_CLIENT_VER]." + log_warn "This script might not work as expected. Support might not be available until kubectl is upgraded to a supported version." fi # SAS Viya 4 versions @@ -34,10 +34,10 @@ # 2024.02 1.26 1.28 if [[ $KUBE_SERVER_VER =~ v1.2[1-9] ]]; then - : -else - log_warn "The detected version of Kubernetes [$KUBE_SERVER_VER] is not supported by any of the currently supported releases of SAS Viya." - log_warn "This script might not work as expected. Support might not be available until Kubernetes is upgraded to a supported version." + : +else + log_warn "The detected version of Kubernetes [$KUBE_SERVER_VER] is not supported by any of the currently supported releases of SAS Viya." + log_warn "This script might not work as expected. Support might not be available until Kubernetes is upgraded to a supported version." fi export KUBE_CLIENT_VER="$KUBE_CLIENT_VER" --- bin/openshift-include.sh.orig +++ bin/openshift-include.sh @@ -5,117 +5,117 @@ # Assumes bin/common.sh has been sourced function ocVersionCheck { - origIFS=$IFS - IFS=$'\n' + origIFS=$IFS + IFS=$'\n' - allArr=($(oc version 2>/dev/null)) - IFS=$origIFS + allArr=($(oc version 2>/dev/null)) + IFS=$origIFS - for (( i=0; i<${#allArr[@]}; i++ )); do - # Split the line into an array - verArr=(${allArr[$i]}) - if [ ${#verArr[@]} -eq 3 ]; then - verType="${verArr[0]}" - ver="${verArr[2]}" - if [ "$verType" == "Client" ]; then - ver="${verArr[2]}" - if [[ $ver =~ v?(([0-9]+)\.([0-9]+)\.([0-9]+)) ]]; then - OC_FULL_VERSION=${BASH_REMATCH[1]} - OC_MAJOR_VERSION=${BASH_REMATCH[2]} - OC_MINOR_VERSION=${BASH_REMATCH[3]} - OC_PATCH_VERSION=${BASH_REMATCH[4]} - else - echo "Unable to parse client version: [$ver]" - fi - elif [ "$verType" == "Server" ]; then - ver="${verArr[2]}" - if [[ $ver =~ (([0-9]+)\.([0-9]+)\.([0-9]+)) ]]; then - OSHIFT_FULL_VERSION=${BASH_REMATCH[1]} - OSHIFT_MAJOR_VERSION=${BASH_REMATCH[2]} - OSHIFT_MINOR_VERSION=${BASH_REMATCH[3]} - OSHIFT_PATCH_VERSION=${BASH_REMATCH[4]} - else - echo "Unable to parse server version: [$ver]" - fi - fi - fi - done - log_info "OpenShift client version: $OC_FULL_VERSION" - log_info "OpenShift server version: $OSHIFT_FULL_VERSION" - - # Version enforcement - if [ "$OPENSHIFT_VERSION_CHECK" == "true" ]; then - ## Server Version - ### Openshift versions that do not start with a 4 should produce an error. - if (( "$OSHIFT_MAJOR_VERSION" != 4 )); then - log_error "Unsupported OpenShift server version: $OSHIFT_FULL_VERSION" - log_error "Version 4.12+ is required" - exit 1 - ### 21FEB24: Openshift 4 versions earlier than 4.12 should produce an error. - elif (( "$OSHIFT_MINOR_VERSION" < 12 )); then - log_error "Unsupported OpenShift server version: $OSHIFT_FULL_VERSION" - log_error "Version 4.12+ is required" - exit 1 - else - log_debug "OpenShift server version check OK" - fi + for ((i = 0; i < ${#allArr[@]}; i++)); do + # Split the line into an array + verArr=(${allArr[$i]}) + if [ ${#verArr[@]} -eq 3 ]; then + verType="${verArr[0]}" + ver="${verArr[2]}" + if [ "$verType" == "Client" ]; then + ver="${verArr[2]}" + if [[ $ver =~ v?(([0-9]+)\.([0-9]+)\.([0-9]+)) ]]; then + OC_FULL_VERSION=${BASH_REMATCH[1]} + OC_MAJOR_VERSION=${BASH_REMATCH[2]} + OC_MINOR_VERSION=${BASH_REMATCH[3]} + OC_PATCH_VERSION=${BASH_REMATCH[4]} + else + echo "Unable to parse client version: [$ver]" + fi + elif [ "$verType" == "Server" ]; then + ver="${verArr[2]}" + if [[ $ver =~ (([0-9]+)\.([0-9]+)\.([0-9]+)) ]]; then + OSHIFT_FULL_VERSION=${BASH_REMATCH[1]} + OSHIFT_MAJOR_VERSION=${BASH_REMATCH[2]} + OSHIFT_MINOR_VERSION=${BASH_REMATCH[3]} + OSHIFT_PATCH_VERSION=${BASH_REMATCH[4]} + else + echo "Unable to parse server version: [$ver]" + fi + fi + fi + done + log_info "OpenShift client version: $OC_FULL_VERSION" + log_info "OpenShift server version: $OSHIFT_FULL_VERSION" - ## Client Version - ### Openshift versions that do not start with a 4 should produce an error. - if (( "$OC_MAJOR_VERSION" != 4 )); then - log_error "Unsupported OpenShift client version: $OC_FULL_VERSION" - log_error "Version 4.11+ is required" - exit 1 - ### Openshift 4 client version must be w/in 1 minor releases of server minimum. - elif (( "$OC_MINOR_VERSION" < 11 )); then - log_error "Unsupported OpenShift client version: $OC_FULL_VERSION" - log_error "Version 4.11+ is required" - exit 1 - else - log_debug "OpenShift client version check OK" - fi - fi + # Version enforcement + if [ "$OPENSHIFT_VERSION_CHECK" == "true" ]; then + ## Server Version + ### Openshift versions that do not start with a 4 should produce an error. + if (("$OSHIFT_MAJOR_VERSION" != 4)); then + log_error "Unsupported OpenShift server version: $OSHIFT_FULL_VERSION" + log_error "Version 4.12+ is required" + exit 1 + ### 21FEB24: Openshift 4 versions earlier than 4.12 should produce an error. + elif (("$OSHIFT_MINOR_VERSION" < 12)); then + log_error "Unsupported OpenShift server version: $OSHIFT_FULL_VERSION" + log_error "Version 4.12+ is required" + exit 1 + else + log_debug "OpenShift server version check OK" + fi + + ## Client Version + ### Openshift versions that do not start with a 4 should produce an error. + if (("$OC_MAJOR_VERSION" != 4)); then + log_error "Unsupported OpenShift client version: $OC_FULL_VERSION" + log_error "Version 4.11+ is required" + exit 1 + ### Openshift 4 client version must be w/in 1 minor releases of server minimum. + elif (("$OC_MINOR_VERSION" < 11)); then + log_error "Unsupported OpenShift client version: $OC_FULL_VERSION" + log_error "Version 4.11+ is required" + exit 1 + else + log_debug "OpenShift client version check OK" + fi + fi } OPENSHIFT_VERSION_CHECK=${OPENSHIFT_VERSION_CHECK:-true} if [ "$SAS_OPENSHIFT_SOURCED" != "true" ]; then - if [ "$OPENSHIFT_CLUSTER" == "" ]; then - # Detect OpenShift cluster - if kubectl get ns openshift 2>/dev/null 1>&2; then - log_debug "OpenShift detected" - OPENSHIFT_CLUSTER="true" - else - log_debug "OpenShift not detected" - OPENSHIFT_CLUSTER="false" - fi - else - log_debug "Skipping OpenShift detection. OPENSHIFT_CLUSTER=[$OPENSHIFT_CLUSTER]" - fi + if [ "$OPENSHIFT_CLUSTER" == "" ]; then + # Detect OpenShift cluster + if kubectl get ns openshift 2>/dev/null 1>&2; then + log_debug "OpenShift detected" + OPENSHIFT_CLUSTER="true" + else + log_debug "OpenShift not detected" + OPENSHIFT_CLUSTER="false" + fi + else + log_debug "Skipping OpenShift detection. OPENSHIFT_CLUSTER=[$OPENSHIFT_CLUSTER]" + fi - if [ "$OPENSHIFT_CLUSTER" == "true" ]; then - if [ "${OPENSHIFT_OC_CHECK:-true}" == "true" ]; then - if [ ! $(which oc) ]; then - echo "'oc' is required for OpenShift and not found on the current PATH" - exit 1 - fi - ocVersionCheck + if [ "$OPENSHIFT_CLUSTER" == "true" ]; then + if [ "${OPENSHIFT_OC_CHECK:-true}" == "true" ]; then + if [ ! $(which oc) ]; then + echo "'oc' is required for OpenShift and not found on the current PATH" + exit 1 + fi + ocVersionCheck - # Get base OpenShift route hostname - OPENSHIFT_ROUTE_DOMAIN=${OPENSHIFT_ROUTE_DOMAIN:-$(oc get route -n openshift-console console -o 'jsonpath={.spec.host}' | cut -c 27-)} - if [ "$OPENSHIFT_ROUTE_DOMAIN" != "" ]; then - log_debug "OpenShift route host is [$OPENSHIFT_ROUTE_DOMAIN]" - else - log_error "Unable to determine OpenShift route host. Set OPENSHIFT_ROUTE_DOMAIN if necessary." - exit 1 - fi + # Get base OpenShift route hostname + OPENSHIFT_ROUTE_DOMAIN=${OPENSHIFT_ROUTE_DOMAIN:-$(oc get route -n openshift-console console -o 'jsonpath={.spec.host}' | cut -c 27-)} + if [ "$OPENSHIFT_ROUTE_DOMAIN" != "" ]; then + log_debug "OpenShift route host is [$OPENSHIFT_ROUTE_DOMAIN]" + else + log_error "Unable to determine OpenShift route host. Set OPENSHIFT_ROUTE_DOMAIN if necessary." + exit 1 + fi - export OPENSHIFT_ROUTE_DOMAIN - export OC_MAJOR_VERSION OC_MINOR_VERSION OC_PATCH_VERSION - export OSHIFT_MAJOR_VERSION OSHIFT_MINOR_VERSION OSHIFT_PATCH_VERSION - fi - else - log_debug "OpenShift not detected. Skipping 'oc' checks." - fi - export OPENSHIFT_CLUSTER - export SAS_OPENSHIFT_SOURCED="true" + export OPENSHIFT_ROUTE_DOMAIN + export OC_MAJOR_VERSION OC_MINOR_VERSION OC_PATCH_VERSION + export OSHIFT_MAJOR_VERSION OSHIFT_MINOR_VERSION OSHIFT_PATCH_VERSION + fi + else + log_debug "OpenShift not detected. Skipping 'oc' checks." + fi + export OPENSHIFT_CLUSTER + export SAS_OPENSHIFT_SOURCED="true" fi ---------- You can reformat the above files to meet shfmt's requirements by typing: shfmt -s -w filename ```