diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..05140b5 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,6 @@ +FROM quay.io/operate-first/opf-toolbox:v0.8.0 +RUN dnf -y update +RUN dnf -y install jq +WORKDIR /shell-scripts +COPY src/* /shell-scripts +CMD ["/bin/sh"] \ No newline at end of file diff --git a/docker/src/ope-notebook-culler.sh b/docker/src/ope-notebook-culler.sh new file mode 100644 index 0000000..db8e676 --- /dev/null +++ b/docker/src/ope-notebook-culler.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +echo "Running ope-notebook-culler.sh..." + +#threshold to stop running notebooks. Currently set to 24 hours +cutoff_time=86400 +current_time=$(date +%s) +notebooks=$(oc get notebooks -n ope-rhods-testing-1fef2f -o jsonpath='{range .items[?(@.status.containerState.running)]}{.metadata.name}{" "}{.metadata.namespace}{" "}{.status.containerState.running.startedAt}{"\n"}{end}') +if [ -z "$notebooks" ]; then + echo "No running notebooks found" + exit 0 +fi + +# Loop through each notebook +while read -r nb ns ts; do + timestamp=$(date -d $ts +%s) + difference=$((current_time - timestamp)) + if [ $difference -gt $cutoff_time ]; then + echo "$nb is more than 24 hours old, stopping the notebook" + oc patch notebook $nb -n $ns --type merge -p '{"metadata":{"annotations":{"kubeflow-resource-stopped":"'$(date -u +"%Y-%m-%dT%H:%M:%SZ")'"}}}' + fi +done <<< "$notebooks" + +echo "ope-notebook-culler.sh run complete."