Skip to content

Instantly share code, notes, and snippets.

@geetikabatra
Created January 24, 2019 06:22
Show Gist options
  • Save geetikabatra/f22cd4afbefbb2a5ae3315a9e1d7188d to your computer and use it in GitHub Desktop.
Save geetikabatra/f22cd4afbefbb2a5ae3315a9e1d7188d to your computer and use it in GitHub Desktop.
Helpers.sh
function is_set_or_fail() {
local name=$1
local value=$2
if [ ! -v value ] || [ "${value}" == "not-set" ]; then
echo "You have to set $name" >&2
exit 1
fi
}
function tool_is_installed() {
# Check if given command is available on this machine
local cmd=$1
if ! [ -x "$(command -v $cmd)" ]; then
echo "Error: ${cmd} command is not available. Please install it. See README.md file for more information." >&2
exit 1
fi
}
function generate_and_deploy_config() {
oc process -p DEPLOYMENT_PREFIX="${DEPLOYMENT_PREFIX}" \
-f "${here}/config-template.yaml" > "${here}/config.yaml"
oc apply -f config.yaml
}
function deploy_secrets() {
#All secrets must be base64 encoded
oc process \
-f "${here}/secrets-template.yaml" > "${here}/secrets.yaml"
oc apply -f secrets.yaml
}
function oc_process_apply() {
echo -e "\\n Processing template - $1 ($2) \\n"
# Don't quote $2 as we need it to split into individual arguments
oc process -f "$1" $2 | oc apply -f -
}
function openshift_login() {
oc login "${OC_URI}" --token="${OC_TOKEN}" --insecure-skip-tls-verify=true
}
function remove_project_resources() {
echo "Removing all openshift resources from selected project"
oc delete all,cm,secrets --all
}
function delete_project_and_aws_resources() {
if oc get project "${OC_PROJECT}"; then
echo "Deleting project ${OC_PROJECT}"
oc delete project "${OC_PROJECT}"
fi
}
function create_or_reuse_project() {
if oc get project "${OC_PROJECT}"; then
oc project "${OC_PROJECT}"
remove_project_resources
else
oc new-project "${OC_PROJECT}"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment