Skip to content

Commit 9b9103a

Browse files
committed
ci: add ut and e2e test
- add model-csi-driver helm chart - install and test chart in kind cluster Signed-off-by: imeoer <yansong.ys@antgroup.com>
1 parent 18269c6 commit 9b9103a

File tree

16 files changed

+564
-2
lines changed

16 files changed

+564
-2
lines changed

.github/workflows/e2e.yml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Run E2E Test
2+
3+
on:
4+
push:
5+
branches: [main, release-*]
6+
paths-ignore: ['**.md', '**.png', '**.jpg', '**.svg', '**/docs/**']
7+
pull_request:
8+
branches: [main, release-*]
9+
paths-ignore: ['**.md', '**.png', '**.jpg', '**.svg', '**/docs/**']
10+
schedule:
11+
- cron: '0 4 * * *'
12+
13+
jobs:
14+
run-e2e-test:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Cache Go modules
22+
uses: actions/cache@v4
23+
with:
24+
path: |
25+
~/.cache/go-build
26+
~/go/pkg/mod
27+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
28+
restore-keys: |
29+
${{ runner.os }}-go-
30+
31+
- name: Cache Docker layers
32+
uses: actions/cache@v4
33+
with:
34+
path: /tmp/.buildx-cache
35+
key: ${{ runner.os }}-docker-buildx-${{ github.sha }}
36+
restore-keys: |
37+
${{ runner.os }}-docker-buildx-
38+
39+
- name: Set up QEMU
40+
uses: docker/setup-qemu-action@v3
41+
42+
- name: Set up Docker Buildx
43+
uses: docker/setup-buildx-action@v3
44+
45+
- name: Build Docker Image
46+
uses: docker/build-push-action@v5
47+
with:
48+
context: .
49+
file: build/Dockerfile
50+
build-args: |
51+
HOME=${{ env.HOME }}
52+
tags: model-csi-driver:latest
53+
load: true
54+
push: false
55+
cache-from: type=local,src=/tmp/.buildx-cache
56+
cache-to: type=local,dest=/tmp/.buildx-cache-new
57+
58+
- name: Move Docker Build Cache
59+
run: |
60+
rm -rf /tmp/.buildx-cache
61+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache || true
62+
63+
- name: Install Kind
64+
run: |
65+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.30.0/kind-linux-amd64
66+
chmod +x ./kind
67+
sudo mv ./kind /usr/local/bin/kind
68+
69+
- name: Create Kind Cluster
70+
run: |
71+
kind create cluster --wait 120s
72+
73+
- name: Load docker image into kind
74+
run: |
75+
kind load docker-image model-csi-driver:latest
76+
77+
- name: Load docker image into kind
78+
run: |
79+
kind load docker-image model-csi-driver:latest
80+
81+
- name: Install Helm
82+
run: |
83+
curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
84+
85+
- name: Check cluster and helm
86+
run: |
87+
kubectl get nodes
88+
kubectl cluster-info
89+
helm version
90+
91+
- name: Deploy model-csi-driver chart
92+
run: |
93+
helm upgrade --install model-csi-driver ./charts/model-csi-driver --namespace model-csi --create-namespace
94+
95+
- name: Wait for model-csi-driver pods to be ready
96+
run: |
97+
kubectl wait --for=condition=Ready pods --all --namespace model-csi --timeout=120s
98+
99+
- name: Run Test Pod
100+
run: |
101+
kubectl apply -f test/testdata/pod.test.yaml
102+
kubectl wait --for=condition=Ready pod/model-csi-driver-test --timeout=120s
103+
kubectl delete pod model-csi-driver-test
104+
105+
# # Keep for debug purpose
106+
# - name: Start tmate session
107+
# uses: mxschmitt/action-tmate@v3

.github/workflows/lint.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ name: Lint
33
on:
44
push:
55
branches: [main, release-*]
6+
paths-ignore: ['**.md', '**.png', '**.jpg', '**.svg', '**/docs/**']
67
pull_request:
78
branches: [main, release-*]
9+
paths-ignore: ['**.md', '**.png', '**.jpg', '**.svg', '**/docs/**']
10+
schedule:
11+
- cron: '0 4 * * *'
812

913
permissions:
1014
contents: read

.github/workflows/ut.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Run Unit Test
2+
3+
on:
4+
push:
5+
branches: [main, release-*]
6+
paths-ignore: ['**.md', '**.png', '**.jpg', '**.svg', '**/docs/**']
7+
pull_request:
8+
branches: [main, release-*]
9+
paths-ignore: ['**.md', '**.png', '**.jpg', '**.svg', '**/docs/**']
10+
schedule:
11+
- cron: '0 4 * * *'
12+
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
run-unit-test:
18+
runs-on: ubuntu-latest
19+
timeout-minutes: 60
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Cache Go modules
25+
uses: actions/cache@v4
26+
with:
27+
path: |
28+
~/.cache/go-build
29+
~/go/pkg/mod
30+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
31+
restore-keys: |
32+
${{ runner.os }}-go-
33+
34+
- name: Run Unit tests
35+
run: |-
36+
sudo make test

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ test:
2525

2626
test-local:
2727
go test -tags disable_libgit2 -race -c -o ./unit.test github.com/modelpack/model-csi-driver/pkg/server
28-
sudo CONFIG_PATH=./misc/config.test.yaml ./unit.test -test.timeout 1h -test.v -test.run ^TestServer$
28+
sudo CONFIG_PATH=./test/testdata/config.test.yaml ./unit.test -test.timeout 1h -test.v -test.run ^TestServer$

build/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM golang:1.24 AS builder
2+
WORKDIR /app
3+
4+
COPY . .
5+
RUN --mount=type=cache,target=$HOME/.cache/go-build \
6+
--mount=type=cache,target=$HOME/go/pkg/mod \
7+
make release
8+
9+
FROM ubuntu:24.04
10+
COPY --from=builder /app/model-csi-driver /usr/bin/model-csi-driver
11+
ENTRYPOINT ["/usr/bin/model-csi-driver"]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

charts/model-csi-driver/Chart.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: v2
2+
name: model-csi-driver
3+
description: Kubernetes CSI Driver for serving OCI model artifacts
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 0.1.0
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
# It is recommended to use it with quotes.
24+
appVersion: "0.1.0"
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "model-csi-driver.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "model-csi-driver.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "model-csi-driver.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "model-csi-driver.labels" -}}
37+
helm.sh/chart: {{ include "model-csi-driver.chart" . }}
38+
{{ include "model-csi-driver.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "model-csi-driver.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "model-csi-driver.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "model-csi-driver.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "model-csi-driver.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: config
5+
namespace: model-csi
6+
data:
7+
config.yaml: |-
8+
service_name: {{ .Values.config.serviceName }}
9+
root_dir: {{ .Values.config.rootDir }}
10+
csi_endpoint: unix:///csi/csi.sock
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: model-csi-driver
5+
namespace: model-csi
6+
7+
---
8+
9+
apiVersion: storage.k8s.io/v1
10+
kind: CSIDriver
11+
metadata:
12+
name: {{ .Values.config.serviceName }}
13+
spec:
14+
attachRequired: false
15+
podInfoOnMount: true
16+
volumeLifecycleModes:
17+
- Persistent
18+
- Ephemeral
19+
20+
---
21+
22+
apiVersion: storage.k8s.io/v1
23+
kind: StorageClass
24+
metadata:
25+
name: model-image
26+
provisioner: {{ .Values.config.serviceName }}
27+
reclaimPolicy: Delete
28+
volumeBindingMode: WaitForFirstConsumer

0 commit comments

Comments
 (0)