Created
May 3, 2018 14:42
-
-
Save smarterclayton/4d6ce0ee8395ce33d21e68f4540edb97 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
kind: Pod | |
apiVersion: v1 | |
metadata: | |
name: image-registry-ci-operator | |
spec: | |
restartPolicy: Never | |
terminationGracePeriodSeconds: 1 | |
serviceAccountName: ci-operator | |
volumes: | |
- name: job-definition | |
configMap: | |
name: prow-job-cluster-launch-e2e | |
- name: cluster-profile | |
projected: | |
sources: | |
- secret: | |
name: cluster-secrets-gcp | |
- configMap: | |
name: cluster-profile-gcp | |
- name: cli | |
emptyDir: {} | |
initContainers: | |
- name: cli | |
image: docker-registry.default.svc:5000/openshift/origin-v3.10:control-plane | |
volumeMounts: | |
- name: cli | |
mountPath: /mount/cli | |
command: | |
- /bin/bash | |
- -c | |
- cp /usr/bin/oc /mount/cli/ | |
containers: | |
- name: test | |
image: docker-registry.default.svc:5000/ci/ci-operator:latest | |
volumeMounts: | |
- name: cli | |
mountPath: /usr/bin/oc | |
subPath: oc | |
- name: job-definition | |
mountPath: /usr/local/job | |
- name: cluster-profile | |
mountPath: /usr/local/profile | |
env: | |
- name: CLUSTER_TYPE | |
value: gcp | |
- name: CONFIG | |
valueFrom: | |
configMapKeyRef: | |
name: ci-operator-image-registry | |
key: config.json | |
- name: REPO_BASEURL_REF | |
value: https://storage.googleapis.com/origin-ci-test/releases/openshift/origin/master/.latest-rpms | |
- name: JOB_SPEC | |
value: '{"type":"postsubmit","job":"build_sample_image","buildid":"f506c368-39d5-11e8-a837-0a58ac100475","refs":{"org":"openshift","repo":"image-registry","base_ref":"master","base_sha":"1c82db343d8a3ef7b08f5c0a21d2f5f4961e0121"}}' | |
- name: CLONEREFS_OPTIONS | |
value: $(JOB_SPEC) | |
command: | |
- /bin/bash | |
- -c | |
- | | |
#!bin/bash | |
set -euo pipefail | |
function logs() { | |
set +e | |
if [[ -n "${NAMESPACE-}" ]]; then | |
set +o pipefail | |
# replace with the log controller | |
for i in `oc -n "${NAMESPACE}" get "pod/${JOB_NAME}" --template '{{ range .spec.containers }}{{ .name }}{{ "\n" }}{{ end }}'`; do | |
echo "--- ${NAMESPACE} ${JOB_NAME} $i" | |
oc logs -n "${NAMESPACE}" "pod/${JOB_NAME}" -c "$i" | |
echo | |
echo | |
done | |
oc delete -n "${NAMESPACE}" "pod/${JOB_NAME}" --ignore-not-found | |
fi | |
} | |
trap logs EXIT | |
trap 'kill $(jobs -p); exit 1' TERM | |
# build images | |
ci-operator --build-config "${CONFIG}" --delete-when-idle=5m --dry-run=false --write-params=/tmp/params | |
# build parameters for nested jobs | |
echo "RPM_REPO=$( curl -q "${REPO_BASEURL_REF}" 2>/dev/null )" >> /tmp/params | |
set -o allexport | |
source /tmp/params | |
JOB_HASH="$( echo $JOB_NAME | md5sum )" | |
JOB_HASH="${JOB_HASH:0:5}" | |
JOB_NAME="${JOB_NAME//_/-}" | |
echo "JOB_NAME=${JOB_NAME}" >> /tmp/params | |
echo "ANSIBLE_IMAGE=${IMAGE_FORMAT/\$\{component\}/ansible}" >> /tmp/params | |
echo "INSTANCE_PREFIX=${NAMESPACE}-${JOB_HASH}" >> /tmp/params | |
echo "CLUSTER_TYPE=${CLUSTER_TYPE}" >> /tmp/params | |
# cleanup the previous run of this particular job | |
oc delete -n "${NAMESPACE}" "pod/${JOB_NAME}" --ignore-not-found | |
while oc get -n "${NAMESPACE}" "pod/${JOB_NAME}" --template='{{ "." }}' 2>/dev/null; do | |
sleep 1 & wait | |
continue | |
done | |
echo "Deploying to cluster" | |
# create a secret in the target namespace that contains information for launching clusters | |
oc create secret generic ${JOB_NAME}-cluster-profile -n "${NAMESPACE}" $( ls /usr/local/profile | xargs -n1 -I {} echo -n "--from-file=/usr/local/profile/{} " ) --dry-run -o yaml > /tmp/secrets | |
# create the provided job definition into the target namespace | |
oc process --local -f /usr/local/job --param-file=/tmp/params -o yaml > /tmp/objects | |
oc apply -f /tmp/objects -f /tmp/secrets | |
# loop until the pod fails, succeeds, or has a single container that terminates | |
while true; do | |
phase="$( oc get -n "${NAMESPACE}" "pod/${JOB_NAME}" --template '{{.status.phase}}' )" | |
if [[ "${phase}" == "Failed" ]]; then | |
exit 1 | |
fi | |
if [[ "${phase}" == "Succeeded" ]]; then | |
exit 0 | |
fi | |
failed="$( oc get -n "${NAMESPACE}" "pod/${JOB_NAME}" --template '{{ range .status.containerStatuses }}{{ if exists .state "terminated" }}{{ if ne .state.terminated.exitCode 0.0 }} {{ .name }}{{ end }}{{ end }}{{ end }}{{ "\n" }}' )" | |
if [[ -n "${failed}" ]]; then | |
exit 1 | |
fi | |
sleep 15 & wait | |
continue | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment