Skip to content

Commit

Permalink
bin/out now supports multicontainer pods
Browse files Browse the repository at this point in the history
  • Loading branch information
jcderr committed Aug 23, 2016
1 parent bb4ec74 commit f543f65
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions bin/out
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,41 @@ jq -M -S . < /dev/stdin > /tmp/input

deploy() {
DEPLOYMENT=$1
IMAGE=$2

CONTAINER=$2
IMAGE=$3

[ -n "$DEPLOYMENT" ] || exit 1
[ -n "$IMAGE" ] || exit 1

$KUBECTL set image deployment/$DEPLOYMENT $DEPLOYMENT=$IMAGE
[ -n "$CONTAINER" ] || exit 1

$KUBECTL set image deployment/$DEPLOYMENT $CONTAINER=$IMAGE
}

rollingupdate() {
RC=$1
IMAGE=$2

[ -n "$RC" ] || exit 1
[ -n "$IMAGE" ] || exit 1

$KUBECTL rolling-update rc/$RC --image=$IMAGE
}

start_job() {
JOB=$1
IMAGE=$2
UID=${3:-$(date +%s)}

[ -n "$JOB" ] || exit 1
[ -n "$IMAGE" ] || exit 1
[ -n "$UID" ] || exit 1

cat $JOB | IMAGE=$IMAGE UID=$UID envsubst | $KUBECTL create -f -
}

DEBUG=$(jq -r .source.debug < /tmp/input)
[[ "$DEBUG" == "true" ]] && { echo "Enabling debug mode.";set -x; }

cd $1

mkdir -p /root/.kube
Expand All @@ -54,11 +59,11 @@ if [[ "$KUBE_URL" =~ https.* ]]; then
CA_PATH="/root/.kube/ca.pem"
KEY_PATH="/root/.kube/key.pem"
CERT_PATH="/root/.kube/cert.pem"

echo "$KUBE_CA" | base64 -d > $CA_PATH
echo "$KUBE_KEY" | base64 -d > $KEY_PATH
echo "$KUBE_CERT" | base64 -d > $CERT_PATH

KUBECTL="$KUBECTL --certificate-authority=$CA_PATH --client-key=$KEY_PATH --client-certificate=$CERT_PATH"
fi

Expand All @@ -73,13 +78,26 @@ IMG="$IMG:$TAG"
RESOURCE_TYPE=$(jq -r .source.resource_type < /tmp/input)
RESOURCE_NAME=$(jq -r .source.resource_name < /tmp/input)
RESOURCE_PATH=$(jq -r .params.resource_path < /tmp/input)
CONTAINER_NAME=$(jq -r .source.container_name < /tmp/input)

if [[ -z "$RESOURCE_TYPE" ]]; then
RESOURCE_TYPE=$(jq -r .params.resource_type < /tmp/input)
fi

if [[ -z "$RESOURCE_NAME" ]]; then
RESOURCE_TYPE=$(jq -r .params.resource_name < /tmp/input)
fi

if [[ "$CONTAINER_NAME" == "null" ]]; then
CONTAINER_NAME=$RESOURCE_NAME
fi

export KUBECTL

# do things
case $RESOURCE_TYPE in
deployment)
deploy $RESOURCE_NAME $IMG;;
deploy $RESOURCE_NAME $CONTAINER_NAME $IMG;;
replicationcontroller)
rollingupdate $RESOURCE_NAME $IMG;;
job)
Expand Down

0 comments on commit f543f65

Please sign in to comment.