Skip to content

Instantly share code, notes, and snippets.

@jkeam
Last active October 30, 2021 21:48
Show Gist options
  • Save jkeam/b03fc25bad4dd4c6943c73ac6f1422e6 to your computer and use it in GitHub Desktop.
Save jkeam/b03fc25bad4dd4c6943c73ac6f1422e6 to your computer and use it in GitHub Desktop.
After a source to image, this script will export all the import yamls
#!/bin/bash
set -e -u -o pipefail
function export_objects() {
app_name=$1
namespace=$2
items=( service deployment buildconfig imagestream route )
for i in "${items[@]}"
do
oc get $i/$app_name -n $namespace -o yaml > $app_name/$app_name-$i.yaml
done
}
usage() { echo "$0 usage:" && grep ".)\ #" $0 | sed 's/ #//' ; exit 0; }
namespace="$(oc project -q)"
app_name=''
while getopts ":hn:a:" arg; do
case $arg in
a) # Specify mandatory app name.
app_name=$OPTARG
;;
n) # Specify optional namespace -- will default to current namespace.
namespace=$OPTARG
;;
h | *) # Display help.
usage
exit 0
;;
esac
done
if [ -z $app_name ]; then
usage
exit 0
fi
mkdir -p $app_name
export_objects $app_name $namespace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment