From c5307b9dfa4b7429decbb125f873dc2d6076f947 Mon Sep 17 00:00:00 2001 From: Cory Latschkowski Date: Fri, 11 Oct 2024 10:55:44 -0500 Subject: [PATCH] update: scripts (#105) --- .../instance/sandbox/namespace.yaml | 1 + .../gpu-operator-certified/README.md | 4 ++++ .../overlays/v23.6/kustomization.yaml | 11 +++++++++++ .../overlays/v23.6/patch-channel.yaml | 3 +++ .../overlays/v23.9/kustomization.yaml | 11 +++++++++++ .../overlays/v23.9/patch-channel.yaml | 3 +++ .../overlays/v24.3/kustomization.yaml | 11 +++++++++++ .../overlays/v24.3/patch-channel.yaml | 3 +++ .../overlays/v24.6/kustomization.yaml | 11 +++++++++++ .../overlays/v24.6/patch-channel.yaml | 3 +++ scripts/functions.sh | 5 +++-- scripts/library/bin.sh | 6 ++++-- scripts/library/common.sh | 15 +++++++-------- scripts/library/htpasswd.sh | 19 ++++++++++--------- scripts/library/ocp.sh | 2 +- 15 files changed, 86 insertions(+), 22 deletions(-) create mode 100644 components/operators/gpu-operator-certified/operator/overlays/v23.6/kustomization.yaml create mode 100644 components/operators/gpu-operator-certified/operator/overlays/v23.6/patch-channel.yaml create mode 100644 components/operators/gpu-operator-certified/operator/overlays/v23.9/kustomization.yaml create mode 100644 components/operators/gpu-operator-certified/operator/overlays/v23.9/patch-channel.yaml create mode 100644 components/operators/gpu-operator-certified/operator/overlays/v24.3/kustomization.yaml create mode 100644 components/operators/gpu-operator-certified/operator/overlays/v24.3/patch-channel.yaml create mode 100644 components/operators/gpu-operator-certified/operator/overlays/v24.6/kustomization.yaml create mode 100644 components/operators/gpu-operator-certified/operator/overlays/v24.6/patch-channel.yaml diff --git a/components/cluster-configs/namespaces/instance/sandbox/namespace.yaml b/components/cluster-configs/namespaces/instance/sandbox/namespace.yaml index 50d074db..0b1e1f50 100644 --- a/components/cluster-configs/namespaces/instance/sandbox/namespace.yaml +++ b/components/cluster-configs/namespaces/instance/sandbox/namespace.yaml @@ -1,3 +1,4 @@ +--- apiVersion: v1 kind: Namespace metadata: diff --git a/components/operators/gpu-operator-certified/README.md b/components/operators/gpu-operator-certified/README.md index 1a01117e..ae3477aa 100644 --- a/components/operators/gpu-operator-certified/README.md +++ b/components/operators/gpu-operator-certified/README.md @@ -11,6 +11,10 @@ The current *overlays* available are for the following channels: * [v1.11](operator/overlays/v1.11) * [v22.9](operator/overlays/v22.9) * [v23.3](operator/overlays/v23.3) +* [v23.6](operator/overlays/v23.6) +* [v23.9](operator/overlays/v23.9) +* [v24.3](operator/overlays/v24.3) +* [v24.6](operator/overlays/v24.6) ## Usage diff --git a/components/operators/gpu-operator-certified/operator/overlays/v23.6/kustomization.yaml b/components/operators/gpu-operator-certified/operator/overlays/v23.6/kustomization.yaml new file mode 100644 index 00000000..c771cd2a --- /dev/null +++ b/components/operators/gpu-operator-certified/operator/overlays/v23.6/kustomization.yaml @@ -0,0 +1,11 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: + - ../../base + +patches: + - target: + kind: Subscription + name: gpu-operator-certified + path: patch-channel.yaml diff --git a/components/operators/gpu-operator-certified/operator/overlays/v23.6/patch-channel.yaml b/components/operators/gpu-operator-certified/operator/overlays/v23.6/patch-channel.yaml new file mode 100644 index 00000000..c45e83c6 --- /dev/null +++ b/components/operators/gpu-operator-certified/operator/overlays/v23.6/patch-channel.yaml @@ -0,0 +1,3 @@ +- op: replace + path: /spec/channel + value: v23.6 diff --git a/components/operators/gpu-operator-certified/operator/overlays/v23.9/kustomization.yaml b/components/operators/gpu-operator-certified/operator/overlays/v23.9/kustomization.yaml new file mode 100644 index 00000000..c771cd2a --- /dev/null +++ b/components/operators/gpu-operator-certified/operator/overlays/v23.9/kustomization.yaml @@ -0,0 +1,11 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: + - ../../base + +patches: + - target: + kind: Subscription + name: gpu-operator-certified + path: patch-channel.yaml diff --git a/components/operators/gpu-operator-certified/operator/overlays/v23.9/patch-channel.yaml b/components/operators/gpu-operator-certified/operator/overlays/v23.9/patch-channel.yaml new file mode 100644 index 00000000..1c23dc2e --- /dev/null +++ b/components/operators/gpu-operator-certified/operator/overlays/v23.9/patch-channel.yaml @@ -0,0 +1,3 @@ +- op: replace + path: /spec/channel + value: v23.9 diff --git a/components/operators/gpu-operator-certified/operator/overlays/v24.3/kustomization.yaml b/components/operators/gpu-operator-certified/operator/overlays/v24.3/kustomization.yaml new file mode 100644 index 00000000..c771cd2a --- /dev/null +++ b/components/operators/gpu-operator-certified/operator/overlays/v24.3/kustomization.yaml @@ -0,0 +1,11 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: + - ../../base + +patches: + - target: + kind: Subscription + name: gpu-operator-certified + path: patch-channel.yaml diff --git a/components/operators/gpu-operator-certified/operator/overlays/v24.3/patch-channel.yaml b/components/operators/gpu-operator-certified/operator/overlays/v24.3/patch-channel.yaml new file mode 100644 index 00000000..b3f6e844 --- /dev/null +++ b/components/operators/gpu-operator-certified/operator/overlays/v24.3/patch-channel.yaml @@ -0,0 +1,3 @@ +- op: replace + path: /spec/channel + value: v24.3 diff --git a/components/operators/gpu-operator-certified/operator/overlays/v24.6/kustomization.yaml b/components/operators/gpu-operator-certified/operator/overlays/v24.6/kustomization.yaml new file mode 100644 index 00000000..c771cd2a --- /dev/null +++ b/components/operators/gpu-operator-certified/operator/overlays/v24.6/kustomization.yaml @@ -0,0 +1,11 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: + - ../../base + +patches: + - target: + kind: Subscription + name: gpu-operator-certified + path: patch-channel.yaml diff --git a/components/operators/gpu-operator-certified/operator/overlays/v24.6/patch-channel.yaml b/components/operators/gpu-operator-certified/operator/overlays/v24.6/patch-channel.yaml new file mode 100644 index 00000000..85390399 --- /dev/null +++ b/components/operators/gpu-operator-certified/operator/overlays/v24.6/patch-channel.yaml @@ -0,0 +1,3 @@ +- op: replace + path: /spec/channel + value: v24.6 diff --git a/scripts/functions.sh b/scripts/functions.sh index 307133bc..e7df63b2 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -16,7 +16,7 @@ check_git_root(){ if [ -d .git ] && [ -d scripts ]; then GIT_ROOT=$(pwd) export GIT_ROOT - echo "GIT_ROOT: ${GIT_ROOT}" + echo "GIT_ROOT: ${GIT_ROOT}" return else echo "Please run this script from the root of the git repo" @@ -28,6 +28,7 @@ check_script_path(){ [ -n "${SCRIPT_DIR}" ] && return SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + export SCRIPT_DIR echo "SCRIPT_DIR: ${SCRIPT_DIR}" } @@ -75,4 +76,4 @@ usage(){ echo "USAGE: get_functions" } -usage +is_sourced && usage diff --git a/scripts/library/bin.sh b/scripts/library/bin.sh index d31e0a1d..62422a34 100644 --- a/scripts/library/bin.sh +++ b/scripts/library/bin.sh @@ -6,11 +6,13 @@ OPENSHIFT_CLIENTS_URL=https://mirror.openshift.com/pub/openshift-v4/x86_64/clien bin_check(){ name=${1:-oc} + which "${name}" && return 0 + OS="$(uname | tr '[:upper:]' '[:lower:]')" ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" echo " - CLI: ${name} + CLI: ${name} (NOT found) OS: ${OS} ARCH: ${ARCH} " @@ -69,7 +71,7 @@ download_helm(){ download_oc(){ BIN_VERSION=stable-4.14 - DOWNLOAD_URL=${OPENSHIFT_CLIENTS_URL}/ocp/${BIN_VERSION}/openshift-client-linux.tar.gz + DOWNLOAD_URL=${OPENSHIFT_CLIENTS_URL}/ocp/${BIN_VERSION}/openshift-client-${OS}.tar.gz curl "${DOWNLOAD_URL}" -sL | tar zx -C "${BIN_PATH}/" oc kubectl } diff --git a/scripts/library/common.sh b/scripts/library/common.sh index 21b8d107..abec304b 100644 --- a/scripts/library/common.sh +++ b/scripts/library/common.sh @@ -46,23 +46,22 @@ until_true(){ } retry(){ - local n=1 - local max=9 + local attempts=20 local delay=20 echo "Running:" "${@}" - echo "Retry: x${max}" - echo "Delay: ${delay}s" + echo "Attempts: ${attempts}" + echo "Delay: ${delay}s" # until "${@}" 1>&2 until "${@}" do - if [[ $n -lt $max ]]; then - ((n++)) - echo "Retry #$n - waiting ${delay}s" + if [[ $attempts -gt "1" ]]; then + ((attempts--)) + echo "Remaining attempts: $attempts - waiting ${delay}s" sleep $delay else - echo "Failed after $n attempts." + echo "[FAILED]" return 1 fi done diff --git a/scripts/library/htpasswd.sh b/scripts/library/htpasswd.sh index 8dcd8188..1ce92746 100644 --- a/scripts/library/htpasswd.sh +++ b/scripts/library/htpasswd.sh @@ -1,7 +1,5 @@ #!/bin/bash -which htpasswd 2>/dev/null || return 0 - DEFAULT_HTPASSWD=scratch/htpasswd-local htpasswd_add_user(){ @@ -22,8 +20,8 @@ htpasswd_add_user(){ PASSWORDS: ${HTPASSWD_FILE}.txt " - [ -e "${HTPASSWD_FILE}" ] || touch "${HTPASSWD_FILE}" "${HTPASSWD_FILE}".txt - sed -i '/# '"${USER}"'/d' "${HTPASSWD_FILE}.txt" + touch "${HTPASSWD_FILE}" "${HTPASSWD_FILE}".txt + sed -i '/# '"${USER}"'/d' "${HTPASSWD_FILE}".txt echo "# ${USER} - ${PASS}" >> "${HTPASSWD_FILE}.txt" htpasswd -bB -C 10 "${HTPASSWD_FILE}" "${USER}" "${PASS}" } @@ -33,12 +31,12 @@ htpasswd_ocp_get_file(){ HTPASSWD_NAME=$(basename "${HTPASSWD_FILE}") oc -n openshift-config \ - get "${HTPASSWD_FILE}" || return 1 + get secret/"${HTPASSWD_NAME}" > /dev/null 2>&1 || return 1 oc -n openshift-config \ extract secret/"${HTPASSWD_NAME}" \ --keys=htpasswd \ - --to=- > "${HTPASSWD_FILE}" + --to=- > "${HTPASSWD_FILE}" 2>/dev/null } htpasswd_ocp_set_file(){ @@ -59,7 +57,8 @@ htpasswd_validate_user(){ TMP_CONFIG=scratch/kubeconfig.XXX echo "This may take a few minutes..." - echo "Press + c to cancel" + echo "Press + c to cancel + " # login to ocp cp "${KUBECONFIG}" "${TMP_CONFIG}" @@ -73,10 +72,12 @@ htpasswd_validate_user(){ # cleanup tmp config rm "${TMP_CONFIG}" - echo "Login validated: ${USER}" + echo "" + echo "Validated Login: ${USER}" + echo "" } -which age 2>/dev/null || return 0 +which age >/dev/null 2>&1 || return 0 htpasswd_encrypt_file(){ HTPASSWD_FILE=${1:-${DEFAULT_HTPASSWD}} diff --git a/scripts/library/ocp.sh b/scripts/library/ocp.sh index 4b106fa5..158909de 100644 --- a/scripts/library/ocp.sh +++ b/scripts/library/ocp.sh @@ -318,7 +318,7 @@ YAML } ocp_aws_cluster_autoscaling(){ - oc apply -k "${GIT_ROOT}"/components/cluster-configs/autoscale/overlays/gpus + oc apply -k https://github.com/redhat-na-ssa/demo-ai-gitops-catalog/components/cluster-configs/autoscale/overlays/gpus ocp_aws_create_gpu_machineset g4dn.4xlarge ocp_create_machineset_autoscale 0 3