Skip to content

Commit

Permalink
Refactor Bash script for Kubeflow installation
Browse files Browse the repository at this point in the history
- Reorganized script into functions for better readability and maintainability.

- Added error handling and informative messages for failure cases.

- Ensured consistent indentation and improved variable naming.

- Updated comments for clarity and added usage function.

Signed-off-by: Adriel007 <adrielsouzaandrade8@gmail.com>
  • Loading branch information
Adriel007 committed May 2, 2024
1 parent 6252504 commit 39e80c8
Showing 1 changed file with 62 additions and 63 deletions.
125 changes: 62 additions & 63 deletions kind/hack/tools/install_kubeflow.sh
Original file line number Diff line number Diff line change
@@ -1,79 +1,78 @@
#!/usr/bin/env bash

op=$1

source ../common.sh

# Set default values if not provided
SLEEP_TIME="${SLEEP_TIME:-50}"
MAX_RETRIES="${MAX_RETRIES:-20}"
EXIT_CODE=0

deploy() {
TEMP_DIR="$(mktemp -d)"
echo "Temporary dir:"
echo "${TEMP_DIR}"
cd $TEMP_DIR
git clone https://github.com/kubeflow/pipelines.git
cd pipelines
git checkout tags/${PIPELINE_VERSION}
kubectl apply -k manifests/kustomize/cluster-scoped-resources
kubectl wait --for condition=established --timeout=60s crd/applications.app.k8s.io
# Disable the public endpoint
# ref: https://www.kubeflow.org/docs/components/pipelines/v1/installation/standalone-deployment/#disable-the-public-endpoint
sed -i.back '/inverse-proxy$/d' manifests/kustomize/env/dev/kustomization.yaml
sed -i.back 's/30Mi/60Mi/' manifests/kustomize/third-party/application/application-controller-deployment.yaml
sed -i.back 's/20Mi/60Mi/' manifests/kustomize/third-party/application/application-controller-deployment.yaml
deploy_with_retries "-k" "manifests/kustomize/env/dev" "$MAX_RETRIES" "$SLEEP_TIME" || EXIT_CODE=$?
if [[ $EXIT_CODE -ne 0 ]]
then
echo "Kubeflow deployment unsuccessful."
exit 1
fi
kubectl create clusterrolebinding pipeline-runner-extend --clusterrole cluster-admin --serviceaccount=kubeflow:pipeline-runner
echo "Finished Kubeflow deployment."
rm -rf $TEMP_DIR
}
# Include common functions
source ../common.sh

# Functions

wait(){
echo "Wait for kubeflow deployment."
wait_for_pods "kubeflow" "$MAX_RETRIES" "$SLEEP_TIME" || EXIT_CODE=$?
deploy_kubeflow() {
local temp_dir
temp_dir=$(mktemp -d)
echo "Temporary dir: $temp_dir"
cd "$temp_dir" || exit 1
git clone https://github.com/kubeflow/pipelines.git
cd pipelines || exit 1
git checkout "tags/${PIPELINE_VERSION}"
kubectl apply -k manifests/kustomize/cluster-scoped-resources
kubectl wait --for condition=established --timeout=60s crd/applications.app.k8s.io
# Disable the public endpoint
sed -i.back '/inverse-proxy$/d' manifests/kustomize/env/dev/kustomization.yaml
sed -i.back 's/30Mi/60Mi/' manifests/kustomize/third-party/application/application-controller-deployment.yaml
sed -i.back 's/20Mi/60Mi/' manifests/kustomize/third-party/application/application-controller-deployment.yaml
deploy_with_retries "-k" "manifests/kustomize/env/dev" "$MAX_RETRIES" "$SLEEP_TIME" || EXIT_CODE=$?
if [[ $EXIT_CODE -ne 0 ]]; then
echo "Kubeflow deployment unsuccessful."
exit 1
fi
kubectl create clusterrolebinding pipeline-runner-extend --clusterrole cluster-admin --serviceaccount=kubeflow:pipeline-runner
echo "Finished Kubeflow deployment."
rm -rf "$temp_dir"
}

if [[ $EXIT_CODE -ne 0 ]]
then
echo "Kubeflow Deployment unsuccessful. Not all pods running"
exit $EXIT_CODE
fi
# disable cache for testing
# ref https://www.kubeflow.org/docs/components/pipelines/v1/overview/caching/#disabling-caching-in-your-kubeflow-pipelines-deployment
kubectl patch mutatingwebhookconfiguration cache-webhook-kubeflow --type='json' -p='[{"op":"replace", "path": "/webhooks/0/rules/0/operations/0", "value": "DELETE"}]'
wait_for_kubeflow() {
echo "Waiting for Kubeflow deployment..."
wait_for_pods "kubeflow" "$MAX_RETRIES" "$SLEEP_TIME" || EXIT_CODE=$?
if [[ $EXIT_CODE -ne 0 ]]; then
echo "Kubeflow deployment unsuccessful. Not all pods running."
exit $EXIT_CODE
fi
# Disable cache for testing
kubectl patch mutatingwebhookconfiguration cache-webhook-kubeflow --type='json' -p='[{"op":"replace", "path": "/webhooks/0/rules/0/operations/0", "value": "DELETE"}]'
}

delete(){
kubectl delete -k "github.com/kubeflow/pipelines/manifests/kustomize/cluster-scoped-resources?ref=$PIPELINE_VERSION"
kubectl delete -k "github.com/kubeflow/pipelines/manifests/kustomize/env/dev?ref=$PIPELINE_VERSION"
delete_kubeflow() {
kubectl delete -k "github.com/kubeflow/pipelines/manifests/kustomize/cluster-scoped-resources?ref=$PIPELINE_VERSION"
kubectl delete -k "github.com/kubeflow/pipelines/manifests/kustomize/env/dev?ref=$PIPELINE_VERSION"
}

usage(){
cat <<EOF
"Usage: ./install_kubeflow.sh [cleanup|deploy-wait|deploy]"
print_usage() {
cat <<EOF
Usage: $0 [cleanup|deploy-wait|deploy]
EOF
}

case "$op" in
cleanup)
header_text "Uninstalling Kubeflow"
delete
;;
deploy-wait)
header_text "wait for Kubeflow deployment"
wait
;;
deploy)
header_text "Installing Kubeflow"
deploy
;;
*)
usage
;;
esac
# Main

case "$1" in
cleanup)
header_text "Uninstalling Kubeflow"
delete_kubeflow
;;
deploy-wait)
header_text "Waiting for Kubeflow deployment"
wait_for_kubeflow
;;
deploy)
header_text "Installing Kubeflow"
deploy_kubeflow
;;
*)
print_usage
exit 1
;;
esac

0 comments on commit 39e80c8

Please sign in to comment.