Skip to content

Commit

Permalink
update: scripts (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
codekow authored Oct 11, 2024
1 parent c307549 commit c5307b9
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
apiVersion: v1
kind: Namespace
metadata:
Expand Down
4 changes: 4 additions & 0 deletions components/operators/gpu-operator-certified/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- op: replace
path: /spec/channel
value: v23.6
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- op: replace
path: /spec/channel
value: v23.9
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- op: replace
path: /spec/channel
value: v24.3
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- op: replace
path: /spec/channel
value: v24.6
5 changes: 3 additions & 2 deletions scripts/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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}"
}

Expand Down Expand Up @@ -75,4 +76,4 @@ usage(){
echo "USAGE: get_functions"
}

usage
is_sourced && usage
6 changes: 4 additions & 2 deletions scripts/library/bin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
"
Expand Down Expand Up @@ -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
}

Expand Down
15 changes: 7 additions & 8 deletions scripts/library/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 deletions scripts/library/htpasswd.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/bin/bash

which htpasswd 2>/dev/null || return 0

DEFAULT_HTPASSWD=scratch/htpasswd-local

htpasswd_add_user(){
Expand All @@ -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}"
}
Expand All @@ -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(){
Expand All @@ -59,7 +57,8 @@ htpasswd_validate_user(){
TMP_CONFIG=scratch/kubeconfig.XXX

echo "This may take a few minutes..."
echo "Press <ctrl> + c to cancel"
echo "Press <ctrl> + c to cancel
"

# login to ocp
cp "${KUBECONFIG}" "${TMP_CONFIG}"
Expand All @@ -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}}
Expand Down
2 changes: 1 addition & 1 deletion scripts/library/ocp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c5307b9

Please sign in to comment.