Skip to content

Commit 4444305

Browse files
committed
feat: improved self-test capability (launch codeflare tests such that they run within the cluster)
i.e. this provides the capability for codeflare to launch itself as a Job within a chosen cluster
1 parent fb02cae commit 4444305

File tree

8 files changed

+170
-134
lines changed

8 files changed

+170
-134
lines changed

Diff for: .github/workflows/self-test.yml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Testing of the self-test capability
2+
name: Self-test
3+
4+
on:
5+
push:
6+
branches: [ main ]
7+
pull_request:
8+
branches: [ main ]
9+
10+
jobs:
11+
kind:
12+
runs-on: ${{ matrix.os }}
13+
14+
strategy:
15+
matrix:
16+
os: [ubuntu-latest]
17+
node-version: [16.x]
18+
19+
steps:
20+
- uses: actions/checkout@v3
21+
22+
- name: Create k8s Kind Cluster
23+
uses: helm/[email protected]
24+
with:
25+
install_only: true
26+
27+
- name: Use Node.js ${{ matrix.node-version }}
28+
uses: actions/setup-node@v3
29+
with:
30+
node-version: ${{ matrix.node-version }}
31+
cache: 'npm'
32+
33+
- name: Setup
34+
env:
35+
TERM: xterm
36+
run: ./tests/kind/setup-ci.sh
37+
38+
- name: Run Test with profile ${{ matrix.profile }}
39+
env:
40+
EXECUTABLE_PATH: github-actions-production
41+
TERM: xterm
42+
DEBUG_KUBERNETES: true
43+
TEST_LOG_AGGREGATOR: true
44+
run: ./deploy/self-test/run.sh

Diff for: deploy/self-test/Dockerfile

+19-10
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,31 @@ FROM node:lts-bullseye-slim
33
LABEL org.opencontainers.image.source https://github.com/project-codeflare/codeflare-cli
44

55
ENV DEBIAN_FRONTEND=noninteractive
6+
ENV KUI_HEADLESS=true
7+
ENV KUI_HEADLESS_WEBPACK=true
8+
ENV NO_KIND=true
9+
ENV ROOT=/usr/local
10+
ENV CODEFLARE_HEADLESS_HOME=/usr/local/CodeFlare
611

7-
ENV GITHUB=github.com
8-
ENV ORG=project-codeflare
9-
ENV REPO=codeflare-cli
10-
ENV BRANCH=main
12+
ADD dist/headless /usr/local/CodeFlare
13+
ADD bin/codeflare /usr/local/bin/codeflare
14+
ADD node_modules/@guidebooks/store/dist/store /usr/local/CodeFlare/store
1115

12-
RUN apt update && apt -y install git python3 python3-pip build-essential curl sudo \
16+
RUN apt update && apt -y install sudo curl python3 python3-pip git \
1317
&& pip3 install --no-cache-dir -U pip && pip3 install --no-cache-dir -U setuptools \
14-
&& apt -y autoclean && apt -y clean && rm -rf /var/lib/apt/lists/* \
15-
&& usermod -aG sudo node \
16-
&& echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
18+
&& apt -y clean && rm -rf /var/lib/apt/lists/* \
19+
&& codeflare -n util/jq \
20+
&& codeflare -n util/websocat \
21+
&& codeflare -n ml/ray/install/cli \
22+
&& codeflare -n openshift/oc \
23+
&& codeflare -n kubernetes/helm3 \
24+
&& codeflare -n kubernetes/kubectl
1725

18-
USER node
26+
#USER codeflare
1927
WORKDIR /home/node
2028

21-
ADD self-test.sh /home/node/self-test.sh
29+
ADD tests/kind /home/node/tests/kind
30+
ADD deploy/self-test/self-test.sh /home/node/self-test.sh
2231

2332
ENTRYPOINT ["bash"]
2433
CMD ["./self-test.sh"]

Diff for: deploy/self-test/run.sh

+63-44
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,103 @@
11
#!/usr/bin/env bash
22

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+
318
SCRIPTDIR=$(cd $(dirname "$0") && pwd)
419

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)
724

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
1627

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+
}
1933

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
2543
}
2644

2745
# delete the job and configmap (etc.)
28-
function cleanup() {
46+
function cleanup {
47+
echo "[Self-Test] Cleaning up prior deployments of self-test"
2948
tput setaf 5
30-
kubectl delete cm $CM
31-
kubectl delete -f "$SCRIPTDIR"/self-test.yaml
49+
(kubectl delete -f $YAML || exit 0)
3250
tput sgr0
3351
}
3452

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+
}
5265

53-
kubectl apply -f "$SCRIPTDIR"/self-test.yaml
66+
function start {
67+
tput setaf 3
68+
echo "[Self-Test] Deploying self-test image"
5469
tput sgr0
70+
kubectl apply -f "$YAML"
5571
}
5672

5773
# wait for a pod (of the job) to be ready
5874
function waitForReady() {
5975
tput setaf 3
60-
echo "Waiting for job to start"
76+
echo "[Self-Test] Waiting for job to start"
6177
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
6379
}
6480

6581
# stream out the logs of our job's pod(s)
6682
function logs() {
6783
tput setaf 3
68-
echo "Streaming out job logs"
84+
echo "[Self-test] Streaming out job logs"
6985
tput sgr0
7086
kubectl logs -l job-name=codeflare-self-test -f
7187
}
7288

89+
# wait for the self-test to complete
7390
function waitForComplete() {
7491
tput setaf 3
75-
echo "Waiting for job completion"
92+
echo "[Self-test] Waiting for job completion"
7693
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
7895
}
7996

80-
kind
97+
start_kind
98+
yaml
8199
cleanup
100+
build
82101
start
83102
waitForReady
84103
logs

Diff for: deploy/self-test/self-test.sh

+2-22
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,15 @@ set -o pipefail
55

66
SCRIPTDIR=$(cd $(dirname "$0") && pwd)
77

8-
if [ -n "$GITHUB_REF" ]; then
9-
echo "Cloning org=$ORG ref=$GITHUB_REF"
10-
mkdir test
11-
git init
12-
git remote add origin https://github.com/${ORG}/${REPO}
13-
git clone -c 'remote.origin.fetch=+refs/changes/*:${GITHUB_REF%/merge}/changes/*' https://${GITHUB_ACTOR_PREFIX}${GITHUB}/${ORG}/${REPO}.git test
14-
git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin +${GITHUB_SHA}:${GITHUB_REF}
15-
else
16-
echo "Cloning org=$ORG branch=$BRANCH"
17-
git clone https://${GITHUB_ACTOR_PREFIX}${GITHUB}/${ORG}/${REPO}.git -b ${BRANCH} test
18-
fi
19-
cd test
20-
npm ci
21-
npm run build:headless
22-
23-
export KUI_HEADLESS=true
24-
export KUI_HEADLESS_WEBPACK=true
25-
export CODEFLARE_HEADLESS_HOME=$PWD/dist/headless
26-
27-
./bin/codeflare openshift/oc
28-
./bin/codeflare kubernetes/kubectl
8+
echo "Starting CodeFlare self-test"
299

3010
export KUBE_NS_FOR_REAL=$(kubectl get job codeflare-self-test -o custom-columns=NS:.metadata.namespace --no-headers)
3111
echo "Kubernetes namespace: $KUBE_NS_FOR_REAL"
3212

3313
if [ -n "$VARIANTS" ]; then
3414
variants=$VARIANTS
3515
else
36-
variants="gpu1 non-gpu"
16+
variants="gpu1 non-gpu1"
3717
fi
3818
echo "Using these variants: $variants"
3919

Diff for: deploy/self-test/self-test.yaml

+13-44
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ metadata:
99
name: codeflare-self-test-role
1010
rules:
1111
- apiGroups: [""]
12-
resources: ["pods", "pods/exec", "services"]
13-
verbs: ["create", "events", "get", "watch", "list"]
12+
resources: ["pods", "pods/exec", "services", "events", "secrets"]
13+
verbs: ["create", "delete", "get", "watch", "list"]
14+
- apiGroups: ["apps"]
15+
resources: ["deployments", "replicasets"]
16+
verbs: ["create", "delete", "get", "watch", "list"]
1417
- apiGroups: ["batch"]
1518
resources: ["jobs"]
1619
verbs: ["create", "get", "watch", "list"]
1720
- apiGroups: [""]
18-
resources: ["pods/exec"]
21+
resources: ["pods/exec", "pods/portforward"]
1922
verbs: ["create", "delete"]
2023
#- apiGroups: ["apps"]
2124
# resources: [deployments]
@@ -39,23 +42,19 @@ kind: Job
3942
metadata:
4043
name: codeflare-self-test
4144
spec:
45+
completions: 1
46+
parallelism: 1
4247
template:
4348
spec:
4449
serviceAccountName: codeflare-self-test-serviceaccount
4550
containers:
4651
- name: self-test
47-
image: ghcr.io/project-codeflare/codeflare-self-test:latest
48-
imagePullPolicy: Always
49-
resources:
50-
limits:
51-
cpu: 2
52-
memory: 5Gi
53-
requests:
54-
cpu: 300m
55-
memory: 5Gi
52+
image: ${SELF_TEST_IMAGE-ghcr.io/project-codeflare/codeflare-self-test:${SELF_TEST_TAG-latest}}
5653
env:
57-
- name: GUIDEBOOK_RUN_ARGS
58-
value: "-V"
54+
# - name: GUIDEBOOK_RUN_ARGS
55+
# value: "-V"
56+
- name: VARIANTS
57+
value: ${VARIANTS}
5958
- name: MODE
6059
value: development # otherwise building codeflare-cli takes a huge amount of memory
6160
- name: KUBE_CONTEXT_FOR_TEST
@@ -64,35 +63,5 @@ spec:
6463
value: default # must match with tests/kind/profiles/...
6564
- name: CODEFLARE_NAMESPACE_RESTRICTED # restrict use of cluster-scoped resources
6665
value: "true"
67-
- name: GITHUB_SHA
68-
valueFrom:
69-
configMapKeyRef:
70-
name: codeflare-self-test-config
71-
key: GITHUB_SHA
72-
- name: GITHUB_REF
73-
valueFrom:
74-
configMapKeyRef:
75-
name: codeflare-self-test-config
76-
key: GITHUB_REF
77-
- name: GITHUB_ACTOR_PREFIX
78-
valueFrom:
79-
configMapKeyRef:
80-
name: codeflare-self-test-config
81-
key: GITHUB_ACTOR_PREFIX
82-
- name: VARIANTS
83-
valueFrom:
84-
configMapKeyRef:
85-
name: codeflare-self-test-config
86-
key: VARIANTS
87-
- name: ORG
88-
valueFrom:
89-
configMapKeyRef:
90-
name: codeflare-self-test-config
91-
key: ORG
92-
- name: BRANCH
93-
valueFrom:
94-
configMapKeyRef:
95-
name: codeflare-self-test-config
96-
key: BRANCH
9766
restartPolicy: Never
9867
backoffLimit: 1

Diff for: package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
"prepare": "cross-env husky install",
2323
"build:docker:cli": "npm run build:headless-maybe && docker build -f deploy/cli/Dockerfile -t ghcr.io/project-codeflare/codeflare-cli .",
2424
"publish:docker:log-aggregator": "docker push ghcr.io/project-codeflare/codeflare-log-aggregator:${VERSION-latest}",
25-
"build:docker:log-aggregator": "npm run build:headless-maybe && docker build -f deploy/log-aggregator/Dockerfile -t ${LOG_AGGREGATOR_IMAGE-ghcr.io/project-codeflare/codeflare-log-aggregator:${version-latest}} .",
26-
"build:docker:self-test": "cd deploy/self-test && docker build -t ghcr.io/project-codeflare/codeflare-self-test .",
25+
"build:docker:log-aggregator": "npm run build:headless-maybe && docker build -f deploy/log-aggregator/Dockerfile -t ${LOG_AGGREGATOR_IMAGE-ghcr.io/project-codeflare/codeflare-log-aggregator:${VERSION-latest}} .",
26+
"publish:docker:self-test": "docker push ghcr.io/project-codeflare/codeflare-self-test:${VERSION-latest}",
27+
"build:docker:self-test": "npm run build:headless-maybe && docker build -f deploy/self-test/Dockerfile -t ${SELF_TEST_IMAGE-ghcr.io/project-codeflare/codeflare-self-test:${VERSION-latest}} .",
28+
"run:self-test": "./deploy/self-test/test-in-kind.sh",
2729
"build:headless-maybe": "if [ ! -n \"$FAST\" ]; then npm run build:headless; fi",
2830
"build:headless": "CLIENT_HOME=$PWD webpack-cli --mode=${MODE-production} --config node_modules/@kui-shell/webpack/headless-webpack.config.js",
2931
"docker:debug": "ENTRYPOINT=bash ./bin/codeflare -d",
@@ -97,9 +99,11 @@
9799
"rm -rf ./dist/headless",
98100
"npm run build:electron:all",
99101
"VERSION=$version npm run release:cask",
102+
"VERSION=$version npm run build:docker:self-test",
100103
"VERSION=$version npm run build:docker:log-aggregator"
101104
],
102105
"after:release": [
106+
"VERSION=$version npm run publish:docker:self-test",
103107
"VERSION=$version npm run publish:docker:log-aggregator"
104108
]
105109
},

0 commit comments

Comments
 (0)