Skip to content

Commit

Permalink
update: functions
Browse files Browse the repository at this point in the history
  • Loading branch information
codekow committed Jun 25, 2024
1 parent e51e8c3 commit 5fcce0e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
#!/bin/bash
# shellcheck disable=SC2120

# See https://github.com/redhat-na-ssa/demo-ai-gitops-catalog
# FUNCTIONS='
# ocp_aws_cluster
# ocp_aws_create_gpu_machineset
# ocp_aws_clone_worker_machineset
# ocp_create_machineset_autoscale'

# for function in $FUNCTIONS
# do
# extract_function $function scripts/library/ocp.sh >> tmp
# echo >> tmp
# done

ocp_aws_cluster(){
TARGET_NS=kube-system
OBJ=secret/aws-creds
Expand All @@ -22,7 +35,7 @@ ocp_aws_create_gpu_machineset(){

INSTANCE_TYPE=${1:-g4dn.4xlarge}

ocp_aws_clone_machineset "${INSTANCE_TYPE}"
ocp_aws_clone_worker_machineset "${INSTANCE_TYPE}"

MACHINE_SET_TYPE=$(oc -n openshift-machine-api get machinesets.machine.openshift.io -o name | grep "${INSTANCE_TYPE%.*}" | head -n1)

Expand Down Expand Up @@ -57,28 +70,38 @@ ocp_aws_create_gpu_machineset(){
--type=merge --patch '{"spec":{"template":{"spec":{"providerSpec":{"value":{"instanceType":"'"${INSTANCE_TYPE}"'"}}}}}}'
}

ocp_aws_clone_machineset(){
ocp_aws_clone_worker_machineset(){
[ -z "${1}" ] && \
echo "
usage: ocp_aws_create_gpu_machineset < instance type, default g4dn.4xlarge >
usage: ocp_aws_clone_worker_machineset < instance type, default g4dn.4xlarge > < machine set name >
"

INSTANCE_TYPE=${1:-g4dn.4xlarge}
MACHINE_SET=$(oc -n openshift-machine-api get machinesets.machine.openshift.io -o name | grep worker | head -n1)
SHORT_NAME=${2:-${INSTANCE_TYPE%.*}}

MACHINE_SET_NAME=$(oc -n openshift-machine-api get machinesets.machine.openshift.io -o name | grep "${SHORT_NAME}" | head -n1)
MACHINE_SET_WORKER=$(oc -n openshift-machine-api get machinesets.machine.openshift.io -o name | grep worker | head -n1)

# check for an existing instance machine set
if oc -n openshift-machine-api get machinesets.machine.openshift.io -o name | grep -q "${INSTANCE_TYPE%.*}"; then
echo "Exists: machineset - ${INSTANCE_TYPE}"
if [ -n "${MACHINE_SET_NAME}" ]; then
echo "Exists: machineset - ${MACHINE_SET_NAME}"
else
echo "Creating: machineset - ${INSTANCE_TYPE}"
echo "Creating: machineset - ${SHORT_NAME}"
oc -n openshift-machine-api \
get "${MACHINE_SET}" -o yaml | \
get "${MACHINE_SET_WORKER}" -o yaml | \
sed '/machine/ s/-worker/-'"${INSTANCE_TYPE}"'/g
/name/ s/-worker/-'"${INSTANCE_TYPE%.*}"'/g
/^ name:/ s/cluster-.*/'"${SHORT_NAME}"'/g
/name/ s/-worker/-'"${SHORT_NAME}"'/g
s/instanceType.*/instanceType: '"${INSTANCE_TYPE}"'/
/cluster-api-autoscaler/d
s/replicas.*/replicas: 0/' | \
oc apply -f -
fi

# cosmetic pretty
oc -n openshift-machine-api \
patch "${MACHINE_SET_NAME}" \
--type=merge --patch '{"spec":{"template":{"spec":{"metadata":{"labels":{"node-role.kubernetes.io/'"${SHORT_NAME}"'":""}}}}}}'
}

ocp_create_machineset_autoscale(){
Expand Down
2 changes: 1 addition & 1 deletion scripts/library/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ until_true(){
echo "[OK]"
}

export_function(){
extract_function(){
EXPORT_NAME=${1:-ocp_aws_cluster}
FILE=${2:-scripts/library/ocp.sh}

Expand Down
4 changes: 2 additions & 2 deletions scripts/library/ocp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ ocp_aws_create_metal_machineset(){

INSTANCE_TYPE=${1:-m5n.metal}

ocp_aws_clone_machineset "${INSTANCE_TYPE}"
ocp_aws_clone_worker_machineset "${INSTANCE_TYPE}"

MACHINE_SET_TYPE=$(oc -n openshift-machine-api get machinesets.machine.openshift.io -o name | grep "${INSTANCE_TYPE%.*}" | head -n1)

Expand Down Expand Up @@ -230,7 +230,7 @@ ocp_aws_create_gpu_machineset(){

INSTANCE_TYPE=${1:-g4dn.4xlarge}

ocp_aws_clone_machineset "${INSTANCE_TYPE}"
ocp_aws_clone_worker_machineset "${INSTANCE_TYPE}"

MACHINE_SET_TYPE=$(oc -n openshift-machine-api get machinesets.machine.openshift.io -o name | grep "${INSTANCE_TYPE%.*}" | head -n1)

Expand Down

0 comments on commit 5fcce0e

Please sign in to comment.