|
1 | 1 | #!/usr/bin/env bash |
2 | 2 |
|
| 3 | +# |
| 4 | +# This is intended only for local testing!! |
| 5 | +# |
| 6 | +# Generally speaking, self-test launches codeflare tests such that the |
| 7 | +# test launcher itself runs inside of a pod (a Job, actually; see |
| 8 | +# self-test.yaml). |
| 9 | +# |
| 10 | +# This script does so against a local kind cluster. It is helpful to |
| 11 | +# test the script and self-test capability, but is not intended for |
| 12 | +# actual self-testing in the field. |
| 13 | +# |
| 14 | + |
| 15 | +set -e |
| 16 | +set -o pipefail |
| 17 | + |
3 | 18 | SCRIPTDIR=$(cd $(dirname "$0") && pwd) |
4 | 19 |
|
5 | | -# name of the configmap |
6 | | -CM=codeflare-self-test-config |
| 20 | +KIND="$SCRIPTDIR"/../../tests/kind |
| 21 | +export SELF_TEST_IMAGE=codeflare-self-test:test |
| 22 | +export VARIANTS=${VARIANTS-non-gpu1} |
| 23 | +YAML=$(mktemp) |
7 | 24 |
|
8 | | -# we will test the latest **remote** version of the current local |
9 | | -# org+branch e.g. if your local branch is from org `starpit` and |
10 | | -# branch `fixing-bug`, then make sure to commit and push your changes |
11 | | -# to the remote, otherwise any changes you hoped to test will not be |
12 | | -# picked up |
13 | | -ORG=${GITHUB_REPOSITORY_OWNER-$(git config remote.$(git config branch.main.remote).url | cut -f2 -d: | cut -f1 -d/)} |
14 | | -BRANCH=$(git branch --show-current) |
15 | | -echo "github org=$ORG branch=$BRANCH" |
| 25 | +SCRIPTDIR=$(cd $(dirname "$0") && pwd) |
| 26 | +. "${KIND}"/values.sh |
16 | 27 |
|
17 | | -# if you hit ctrl+c, we will tear everything down |
18 | | -trap cleanup INT |
| 28 | +# start kind, if needed |
| 29 | +function start_kind { |
| 30 | + export KUBECONFIG=$("$KIND"/setup.sh) |
| 31 | + echo "[Self-Test] Using KUBECONFIG=$KUBECONFIG" |
| 32 | +} |
19 | 33 |
|
20 | | -# configure kind if needed |
21 | | -function kind() { |
22 | | - if [ -n "$NEEDS_KIND" ]; then |
23 | | - export KUBECONFIG=$("$SCRIPTDIR"/../../tests/kind/setup.sh) |
24 | | - fi |
| 34 | +# generate self-test.yaml with variable expansion |
| 35 | +function yaml { |
| 36 | + echo "[Self-Test] Creating self-test.yaml" |
| 37 | + TEMP=$(mktemp) |
| 38 | + echo 'cat <<EOF' > $TEMP |
| 39 | + cat "$SCRIPTDIR"/self-test.yaml >> $TEMP |
| 40 | + echo 'EOF' >> $TEMP |
| 41 | + bash $TEMP >> $YAML |
| 42 | + rm $TEMP |
25 | 43 | } |
26 | 44 |
|
27 | 45 | # delete the job and configmap (etc.) |
28 | | -function cleanup() { |
| 46 | +function cleanup { |
| 47 | + echo "[Self-Test] Cleaning up prior deployments of self-test" |
29 | 48 | tput setaf 5 |
30 | | - kubectl delete cm $CM |
31 | | - kubectl delete -f "$SCRIPTDIR"/self-test.yaml |
| 49 | + (kubectl delete -f $YAML || exit 0) |
32 | 50 | tput sgr0 |
33 | 51 | } |
34 | 52 |
|
35 | | -# create the job and configmap (etc.) |
36 | | -function start() { |
37 | | - # necessary to support cloning when run as a github action; the |
38 | | - # cloning happens in self-test.sh, inside the running pod (spawned |
39 | | - # by this apply) |
40 | | - if [ -n "$GITHUB_ACTOR" ] && [ -n "$GITHUB_TOKEN" ]; then |
41 | | - GITHUB_ACTOR_PREFIX="$GITHUB_ACTOR:$GITHUB_TOKEN@" |
42 | | - fi |
43 | | - |
44 | | - tput setaf 5 |
45 | | - kubectl create cm $CM \ |
46 | | - --from-literal=ORG=$ORG \ |
47 | | - --from-literal=BRANCH=$BRANCH \ |
48 | | - --from-literal=VARIANTS=$VARIANTS \ |
49 | | - --from-literal=GITHUB_ACTOR_PREFIX=$GITHUB_ACTOR_PREFIX \ |
50 | | - --from-literal=GITHUB_SHA=$GITHUB_SHA \ |
51 | | - --from-literal=GITHUB_REF=$GITHUB_REF |
| 53 | +# build docker image of self-test just for this test and load it into |
| 54 | +# kind |
| 55 | +function build { |
| 56 | + tput setaf 3 |
| 57 | + echo "[Self-Test] Building self-test image" |
| 58 | + tput sgr0 |
| 59 | + FAST=true npm run build:docker:self-test |
| 60 | + tput setaf 3 |
| 61 | + echo "[Self-Test] Loading image into kind image=$SELF_TEST_IMAGE cluster=$CLUSTER" |
| 62 | + tput sgr0 |
| 63 | + kind load docker-image $SELF_TEST_IMAGE --name $CLUSTER |
| 64 | +} |
52 | 65 |
|
53 | | - kubectl apply -f "$SCRIPTDIR"/self-test.yaml |
| 66 | +function start { |
| 67 | + tput setaf 3 |
| 68 | + echo "[Self-Test] Deploying self-test image" |
54 | 69 | tput sgr0 |
| 70 | + kubectl apply -f "$YAML" |
55 | 71 | } |
56 | 72 |
|
57 | 73 | # wait for a pod (of the job) to be ready |
58 | 74 | function waitForReady() { |
59 | 75 | tput setaf 3 |
60 | | - echo "Waiting for job to start" |
| 76 | + echo "[Self-Test] Waiting for job to start" |
61 | 77 | tput sgr0 |
62 | | - kubectl wait pod -l job-name=codeflare-self-test --for=condition=Ready |
| 78 | + kubectl wait pod -l job-name=codeflare-self-test --for=condition=Ready --timeout=240s |
63 | 79 | } |
64 | 80 |
|
65 | 81 | # stream out the logs of our job's pod(s) |
66 | 82 | function logs() { |
67 | 83 | tput setaf 3 |
68 | | - echo "Streaming out job logs" |
| 84 | + echo "[Self-test] Streaming out job logs" |
69 | 85 | tput sgr0 |
70 | 86 | kubectl logs -l job-name=codeflare-self-test -f |
71 | 87 | } |
72 | 88 |
|
| 89 | +# wait for the self-test to complete |
73 | 90 | function waitForComplete() { |
74 | 91 | tput setaf 3 |
75 | | - echo "Waiting for job completion" |
| 92 | + echo "[Self-test] Waiting for job completion" |
76 | 93 | tput sgr0 |
77 | | - kubectl wait pod -l job-name=codeflare-self-test --for=condition=Complete --timeout=-1s |
| 94 | + kubectl wait job codeflare-self-test --for=condition=complete --timeout=-1s |
78 | 95 | } |
79 | 96 |
|
80 | | -kind |
| 97 | +start_kind |
| 98 | +yaml |
81 | 99 | cleanup |
| 100 | +build |
82 | 101 | start |
83 | 102 | waitForReady |
84 | 103 | logs |
|
0 commit comments