forked from openshift/osd-cluster-ready
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request openshift#4 from 2uasimojo/deploy
Update deployment target and script
- Loading branch information
Showing
3 changed files
with
131 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,65 @@ | ||
#!/bin/bash | ||
#!/bin/bash -e | ||
|
||
if [ -z "$IMAGE_REPOSITORY" ]; then | ||
echo "Not set" | ||
else | ||
echo "$IMAGE_REPOSITORY" | ||
usage() { | ||
cat <<EOF | ||
Usage: $0 | ||
Environment: | ||
IMAGE_URI (required): E.g. quay.io/my_repo/osd-cluster-ready:0.1.38-614bf59 | ||
JOB_ONLY (optional): If set, only deploy the Job manifest (skip RBAC etc.). | ||
DRY_RUN (optional): If set, don't actually deploy anything, just print what would have happened. | ||
EOF | ||
exit -1 | ||
} | ||
|
||
maybe() { | ||
echo "+ $@" | ||
if [[ -z "$DRY_RUN" ]]; then | ||
$@ | ||
fi | ||
} | ||
|
||
if [[ -z "$IMAGE_URI" ]]; then | ||
echo "IMAGE_URI not set" | ||
usage | ||
fi | ||
# Gather commit number for Z and short SHA | ||
COMMIT_NUMBER=$(git rev-list `git rev-list --parents HEAD | egrep "^[a-f0-9]{40}$"`..HEAD --count) | ||
CURRENT_COMMIT=$(git rev-parse --short=7 HEAD) | ||
|
||
# Build container version | ||
VERSION_MAJOR=0 | ||
VERSION_MINOR=1 | ||
CONTAINER_VERSION="v$VERSION_MAJOR.$VERSION_MINOR.$COMMIT_NUMBER-$CURRENT_COMMIT" | ||
|
||
TMP_MANIFEST=$(mktemp) | ||
echo "Created $TMP_MANIFEST" | ||
cat deploy/60-osd-ready.Job.yaml | sed "s/openshift-sre/${IMAGE_REPOSITORY}/" > $TMP_MANIFEST | ||
sed -i "s/\/osd-cluster-ready/\/osd-cluster-ready:${CONTAINER_VERSION}/" $TMP_MANIFEST | ||
sed -i "s/value: \"240\"/value: \"339860\"/" $TMP_MANIFEST | ||
|
||
TMP_MANIFEST=$(mktemp -t osd-cluster-ready-Job.XXXXX.yaml) | ||
trap "rm -fr $TMP_MANIFEST" EXIT | ||
sed "s,\(^ *image: \).*,\1${IMAGE_URI}," deploy/60-osd-ready.Job.yaml > $TMP_MANIFEST | ||
sed -i 's/value: "240"/value: "339860"/' $TMP_MANIFEST | ||
echo "===== $TMP_MANIFEST =====" | ||
cat $TMP_MANIFEST | ||
echo "=========================" | ||
|
||
# In case the job is already deleted, don't let -e fail this, and don't wait | ||
# for the pod to go away. | ||
WAIT_FOR_POD=yes | ||
maybe oc delete job -n openshift-monitoring osd-cluster-ready || WAIT_FOR_POD=no | ||
|
||
if [[ -z "$JOB_ONLY" ]]; then | ||
echo "Deploying all the things. Set JOB_ONLY=1 to deploy only the Job." | ||
for manifest in $(ls deploy/ | grep -v "60-osd-ready.Job.yaml") | ||
do | ||
maybe oc apply -f deploy/${manifest} | ||
done | ||
else | ||
echo "Deploying only the Job. To redeploy RBAC etc., unset JOB_ONLY." | ||
fi | ||
|
||
oc delete job -n openshift-monitoring osd-cluster-ready | ||
# Before deploying the new job, make sure the pod from the old one is gone | ||
if [[ $WAIT_FOR_POD == "yes" ]]; then | ||
maybe oc wait --for=delete pod -l job-name=osd-cluster-ready --timeout=30s | ||
fi | ||
|
||
for manifest in $(ls deploy/ | grep -v "60-osd-ready.Job.yaml") | ||
do | ||
oc apply -f deploy/${manifest} | ||
done | ||
maybe oc create -f $TMP_MANIFEST | ||
|
||
oc apply -f $TMP_MANIFEST | ||
if [[ -z "$DRY_RUN" ]]; then | ||
POD=$(oc get po -l job-name=osd-cluster-ready -o name) | ||
else | ||
POD=osd-cluster-ready-XXXXX | ||
fi | ||
|
||
# oc logs -f jobs/osd-cluster-ready -n openshift-monitoring | ||
maybe oc wait --for=condition=Ready $POD --timeout=15s | ||
if [[ $? -eq 0 ]]; then | ||
maybe oc logs -f jobs/osd-cluster-ready -n openshift-monitoring | ||
fi |