-
Notifications
You must be signed in to change notification settings - Fork 30
239 lines (215 loc) · 8.01 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
name: ci
on:
pull_request:
push:
branches:
- main
tags:
- '*'
jobs:
docker-base:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Build and push with docker buildx
- name: Setup docker buildx
uses: docker/setup-buildx-action@v3
- name: Configure tags based on git tags + latest
uses: docker/metadata-action@v5
id: meta
with:
images: clux/controller
tags: |
type=pep440,pattern={{version}}
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=pr
- name: Docker login on main origin
uses: docker/login-action@v3
if: github.event_name != 'pull_request'
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: actions/cache@v4
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: musl-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Compile base features
run: |
mkdir -p ~/.cargo/{git,registry}
docker run --rm -t \
--mount type=bind,source=${{ github.workspace }},target=/volume \
--mount type=bind,source=$HOME/.cargo/registry,target=/root/.cargo/registry \
--mount type=bind,source=$HOME/.cargo/git,target=/root/.cargo/git \
clux/muslrust:stable \
cargo build --release --bin controller
cp target/x86_64-unknown-linux-musl/release/controller .
- name: Docker buildx and push with base features
uses: docker/build-push-action@v6
with:
context: .
cache-from: type=gha,scope=base
cache-to: type=gha,scope=base,mode=max
push: ${{ github.ref == 'refs/heads/main' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64
- name: Persist base image build to a tarball
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha,scope=base
outputs: type=docker,dest=/tmp/image.tar
- name: Upload base docker image as artifact for e2e tests
uses: actions/upload-artifact@v4
with:
name: controller-image
path: /tmp/image.tar
docker-otel:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Build and push with docker buildx
- name: Setup docker buildx
uses: docker/setup-buildx-action@v3
- name: Configure tags based on git tags for otel
uses: docker/metadata-action@v5
id: meta
with:
images: clux/controller
tags: |
type=pep440,pattern={{version}},prefix=otel-
type=raw,value=otel,enable={{is_default_branch}}
type=ref,event=pr,prefix=otel-
- uses: actions/cache@v4
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: musl-cargo-otel-${{ hashFiles('**/Cargo.lock') }}
- name: Compile with telemetry
run: |
mkdir -p ~/.cargo/{git,registry}
docker run --rm -t \
--mount type=bind,source=${{ github.workspace }},target=/volume \
--mount type=bind,source=$HOME/.cargo/registry,target=/root/.cargo/registry \
--mount type=bind,source=$HOME/.cargo/git,target=/root/.cargo/git \
clux/muslrust:stable \
cargo build --features=telemetry --release --bin controller
cp target/x86_64-unknown-linux-musl/release/controller .
- name: Docker login on main origin
uses: docker/login-action@v3
if: github.event_name != 'pull_request'
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker buildx and push with telemetry
uses: docker/build-push-action@v6
with:
context: .
cache-from: type=gha,scope=otel
cache-to: type=gha,scope=otel,mode=max
push: ${{ github.ref == 'refs/heads/main' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64
e2e:
runs-on: ubuntu-latest
needs: [docker-base]
steps:
- uses: actions/checkout@v4
- uses: nolar/setup-k3d-k3s@v1
with:
version: v1.27
k3d-name: kube
k3d-args: "--no-lb --no-rollback --k3s-arg --disable=traefik,servicelb,metrics-server@server:*"
- run: kubectl apply -f yaml/crd.yaml
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Download docker image artifact from docker job
uses: actions/download-artifact@v4
with:
name: controller-image
path: /tmp
- name: Load docker image from tarball
run: docker load --input /tmp/image.tar
- name: helm template | kubctl apply
run: |
apiserver="$(kubectl get endpoints kubernetes -ojson | jq '.subsets[0].addresses[0].ip' -r)"
helm template charts/doc-controller \
--set version=latest \
--set networkPolicy.enabled=true \
--set networkPolicy.apiserver.0=${apiserver}/32 \
| kubectl apply -f -
- run: kubectl wait --for=condition=available deploy/doc-controller --timeout=30s
- run: kubectl apply -f yaml/instance-samuel.yaml
- run: sleep 2 # TODO: add condition on status and wait for it instead
# verify reconcile actions have happened
- run: kubectl get netpol doc-controller -oyaml
- run: kubectl logs deploy/doc-controller
- run: kubectl get event --field-selector "involvedObject.kind=Document,involvedObject.name=samuel" | grep "HideRequested"
- run: kubectl get doc -oyaml | grep -A1 finalizers | grep documents.kube.rs
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install protoc
run: sudo apt-get install -y protobuf-compiler
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly
components: rustfmt,clippy
- run: cargo +nightly fmt -- --check
- uses: giraffate/clippy-action@v1
with:
reporter: 'github-pr-review'
github_token: ${{ secrets.GITHUB_TOKEN }}
clippy_flags: --all-features
integration:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- uses: nolar/setup-k3d-k3s@v1
with:
version: v1.25
k3d-name: kube
k3d-args: "--no-lb --no-rollback --k3s-arg --disable=traefik,servicelb,metrics-server@server:*"
- name: Build workspace
run: cargo build
- name: Install crd
run: cargo run --bin crdgen | kubectl apply -f -
- name: Run all default features integration library tests
run: cargo test --lib --all -- --ignored
unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
# Real CI work starts here
- name: Build workspace
run: cargo build
- name: Run workspace unit tests
run: cargo test
- name: Generate crd.yaml
run: cargo run --bin crdgen > yaml/crd.yaml
- name: Generate deployment.yaml
run: helm template charts/doc-controller > yaml/deployment.yaml
- name: Ensure generated output is committed
run: |
if ! git diff --exit-code yaml/; then
echo "Uncommitted changes in yaml directory"
echo "Please run 'just generate' and commit the results"
exit 1
fi