Skip to content

Instantly share code, notes, and snippets.

@todd-dsm
Created June 6, 2021 22:47
Show Gist options
  • Save todd-dsm/0eadda4c9026656375125081327fa4fc to your computer and use it in GitHub Desktop.
Save todd-dsm/0eadda4c9026656375125081327fa4fc to your computer and use it in GitHub Desktop.
checks to see if a service has been deployed to the cluster; if not, we install it.
#!/usr/bin/env bash
# PURPOSE: Given a repo and chart name this script will check to see if the
# chart is installed, if not it installs the chart, else it will
# display Helm deployment info.
# -----------------------------------------------------------------------------
# PREREQS: a) Helm is installed
# b) The target repo has been added
# c)
# -----------------------------------------------------------------------------
# EXECUTE:
# -----------------------------------------------------------------------------
# TODO: 1)
# 2)
# 3)
# -----------------------------------------------------------------------------
# AUTHOR: Todd E Thomas
# -----------------------------------------------------------------------------
# CREATED: 2021/06/06
# -----------------------------------------------------------------------------
#set -x
###----------------------------------------------------------------------------
### VARIABLES
###----------------------------------------------------------------------------
# ENV Stuff
: "${1? Wheres my first agument, bro!}"
myApp="$1"
myRepoName="$2"
# Data
###----------------------------------------------------------------------------
### FUNCTIONS
###----------------------------------------------------------------------------
function pMsg() {
theMessage="$1"
printf '%s\n' "$theMessage"
}
function installService() {
helm upgrade -i "project-name" "${myRepoName}/${myApp}"
}
function checkService() {
if ! kubectl wait --for=condition=ready pod \
-l app.kubernetes.io/name="$myApp" --timeout=300s; then
pMsg "service does not exist"
return 1
else
pMsg "service already exists"
return 0
fi
}
###----------------------------------------------------------------------------
### MAIN PROGRAM
###----------------------------------------------------------------------------
### Check pre-condition
###---
if ! checkService "$myApp"; then
pMsg "Installing Service..."
installService
fi
###---
### REQ
###---
while false; do
checkService "$myApp"
pMsg "checkService"
done
###---
### fin~
###---
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment