Skip to content

Commit 94c4434

Browse files
authoredFeb 27, 2023
ci: Add a linkerd install workflow (#2268)
We don't currently test that proxy changes are at least usable in a basic Linkerd installation. This adds a CI workflow to test all Linkerd code changes against a real k8s cluster with the control plane from the most recent edge release.
1 parent 31276e5 commit 94c4434

File tree

4 files changed

+150
-46
lines changed

4 files changed

+150
-46
lines changed
 

‎.github/workflows/docker.yml

-21
This file was deleted.

‎.github/workflows/k8s.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: k8s
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
pull_request:
8+
paths:
9+
- Cargo.lock
10+
- Dockerfile
11+
- "**/*.rs"
12+
- "**/*.toml"
13+
- justfile
14+
- .github/workflows/k8s.yml
15+
16+
jobs:
17+
k3d-linkerd-install:
18+
timeout-minutes: 20
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- uses: linkerd/dev/actions/setup-tools@v39
23+
24+
- name: Install linkerd CLI (edge)
25+
id: linkerd
26+
run: |
27+
scurl https://run.linkerd.io/install-edge | sh
28+
echo "PATH=$PATH:$HOME/.linkerd2/bin" >> "$GITHUB_ENV"
29+
export PATH="$PATH:$HOME/.linkerd2/bin"
30+
tag=$(linkerd version --client --short)
31+
echo "linkerd $tag"
32+
echo "LINKERD_TAG=$tag" >> "$GITHUB_ENV"
33+
34+
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c
35+
- run: just docker
36+
37+
- run: just-k3d create
38+
- run: just k3d-load-linkerd
39+
40+
- run: just linkerd-install
41+
- run: just linkerd-check-contol-plane-proxy
42+
env:
43+
TMPDIR: ${{ runner.temp }}

‎Dockerfile

+10-20
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,15 @@
1-
# syntax=docker/dockerfile:experimental
1+
# syntax=docker/dockerfile:1.4
22

3-
# Proxy build and runtime
4-
#
53
# This is intended **DEVELOPMENT ONLY**, i.e. so that proxy developers can
64
# easily test the proxy in the context of the larger `linkerd2` project.
7-
#
8-
# This Dockerfile requires expirmental features to be enabled in both the
9-
# Docker client and daemon. You MUST use buildkit to build this image. The
10-
# simplest way to do this is to set the `DOCKER_BUILDKIT` environment variable:
11-
#
12-
# :; DOCKER_BUILDKIT=1 docker build .
13-
#
14-
# Alternatively, you can use `buildx`, which supports more complicated build
15-
# configurations:
16-
#
17-
# :; docker buildx build . --load
185

196
ARG RUST_IMAGE=ghcr.io/linkerd/dev:v39-rust
207

218
# Use an arbitrary ~recent edge release image to get the proxy
229
# identity-initializing and linkerd-await wrappers.
2310
ARG RUNTIME_IMAGE=ghcr.io/linkerd/proxy:edge-22.12.1
2411

25-
# Build the proxy, leveraging (new, experimental) cache mounting.
26-
#
27-
# See: https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/experimental.md#run---mounttypecache
12+
# Build the proxy.
2813
FROM --platform=$BUILDPLATFORM $RUST_IMAGE as build
2914

3015
ARG PROXY_FEATURES=""
@@ -35,6 +20,11 @@ RUN apt-get update && \
3520
fi && \
3621
rm -rf /var/lib/apt/lists/*
3722

23+
ENV CARGO_INCREMENTAL=0
24+
ENV CARGO_NET_RETRY=10
25+
ENV RUSTFLAGS="-D warnings -A deprecated"
26+
ENV RUSTUP_MAX_RETRIES=10
27+
3828
WORKDIR /usr/src/linkerd2-proxy
3929
COPY . .
4030
RUN --mount=type=cache,id=cargo,target=/usr/local/cargo/registry \
@@ -43,9 +33,9 @@ ARG TARGETARCH="amd64"
4333
ARG PROFILE="release"
4434
RUN --mount=type=cache,id=target,target=target \
4535
--mount=type=cache,id=cargo,target=/usr/local/cargo/registry \
46-
just arch=$TARGETARCH features=$PROXY_FEATURES profile=$PROFILE build && \
47-
bin=$(just --evaluate profile="$PROFILE" _target_bin) ; \
48-
mkdir -p /out && mv $bin /out/linkerd2-proxy
36+
just arch="$TARGETARCH" features="$PROXY_FEATURES" profile="$PROFILE" build && \
37+
mkdir -p /out && \
38+
mv $(just --evaluate profile="$PROFILE" _target_bin) /out/linkerd2-proxy
4939

5040
## Install the proxy binary into the base runtime image.
5141
FROM $RUNTIME_IMAGE as runtime

‎justfile

+97-5
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ features := ""
1919
package_version := `git rev-parse --short HEAD`
2020

2121
# Docker image name & tag.
22-
docker_repo := "localhost/linkerd/proxy"
23-
docker_tag := `git rev-parse --abbrev-ref HEAD | sed 's|/|.|'` + "." + `git rev-parse --short HEAD`
24-
docker_image := docker_repo + ":" + docker_tag
22+
docker-repo := "localhost/linkerd/proxy"
23+
docker-tag := `git rev-parse --abbrev-ref HEAD | sed 's|/|.|'` + "." + `git rev-parse --short HEAD`
24+
docker-image := docker-repo + ":" + docker-tag
2525

2626
# The architecture name to use for packages. Either 'amd64', 'arm64', or 'arm'.
2727
arch := "amd64"
@@ -167,15 +167,22 @@ fuzzers:
167167
)
168168
done
169169

170+
export DOCKER_BUILDX_CACHE_DIR := env_var_or_default('DOCKER_BUILDX_CACHE_DIR', '')
171+
170172
# Build a docker image (FOR TESTING ONLY)
171-
docker *args='--output=type=docker':
173+
docker *args='--output=type=docker': && _clean-cache
172174
docker buildx build . \
173175
--pull \
174-
--tag={{ docker_image }} \
176+
--tag={{ docker-image }} \
175177
--build-arg PROFILE='{{ profile }}' \
178+
{{ if linkerd-tag == '' { '' } else { '--build-arg=RUNTIME_IMAGE=ghcr.io/linkerd/proxy:' + linkerd-tag } }} \
176179
{{ if features != "" { "--build-arg PROXY_FEATURES=" + features } else { "" } }} \
180+
{{ if DOCKER_BUILDX_CACHE_DIR == '' { '' } else { '--cache-from=type=local,src=' + DOCKER_BUILDX_CACHE_DIR + ' --cache-to=type=local,dest=' + DOCKER_BUILDX_CACHE_DIR } }} \
177181
{{ args }}
178182

183+
_clean-cache:
184+
@{{ if DOCKER_BUILDX_CACHE_DIR == '' { 'true' } else { 'just-dev prune-action-cache ' + DOCKER_BUILDX_CACHE_DIR } }}
185+
179186
# Lints all shell scripts in the repo.
180187
sh-lint:
181188
@just-sh
@@ -189,3 +196,88 @@ action-lint:
189196

190197
action-dev-check:
191198
@just-dev check-action-images
199+
200+
##
201+
## Linkerd
202+
##
203+
204+
linkerd-tag := env_var_or_default('LINKERD_TAG', '')
205+
_controller-image := 'ghcr.io/linkerd/controller'
206+
_policy-image := 'ghcr.io/linkerd/policy-controller'
207+
_init-image := 'ghcr.io/linkerd/proxy-init'
208+
_init-tag := 'v2.2.0'
209+
210+
_kubectl := 'just-k3d kubectl'
211+
212+
_tag-set:
213+
#!/usr/bin/env bash
214+
if [ -z '{{ linkerd-tag }}' ]; then
215+
echo "linkerd-tag must be set" >&2
216+
exit 1
217+
fi
218+
219+
_k3d-ready:
220+
@just-k3d ready
221+
222+
k3d-load-linkerd: _tag-set _k3d-ready
223+
for i in \
224+
'{{ _controller-image }}:{{ linkerd-tag }}' \
225+
'{{ _policy-image }}:{{ linkerd-tag }}' \
226+
'{{ _init-image }}:{{ _init-tag }}' \
227+
; do \
228+
docker pull -q "$i" ; \
229+
done
230+
@just-k3d import \
231+
'{{ docker-image }}' \
232+
'{{ _controller-image }}:{{ linkerd-tag }}' \
233+
'{{ _policy-image }}:{{ linkerd-tag }}' \
234+
'{{ _init-image }}:{{ _init-tag }}'
235+
236+
# Install crds on the test cluster.
237+
_linkerd-crds-install: _k3d-ready
238+
linkerd install --crds \
239+
| {{ _kubectl }} apply -f -
240+
{{ _kubectl }} wait crd --for condition=established \
241+
--selector='linkerd.io/control-plane-ns' \
242+
--timeout=1m
243+
244+
# Install linkerd on the test cluster using test images.
245+
linkerd-install *args='': _tag-set k3d-load-linkerd _linkerd-crds-install && _linkerd-ready
246+
linkerd install \
247+
--set='imagePullPolicy=Never' \
248+
--set='controllerImage={{ _controller-image }}' \
249+
--set='linkerdVersion={{ linkerd-tag }}' \
250+
--set='policyController.image.name={{ _policy-image }}' \
251+
--set='policyController.image.version={{ linkerd-tag }}' \
252+
--set='proxy.image.name={{ docker-repo }}' \
253+
--set='proxy.image.version={{ docker-tag }}' \
254+
--set='proxy.logLevel=linkerd=debug\,info' \
255+
--set='proxyInit.image.name={{ _init-image }}' \
256+
--set='proxyInit.image.version={{ _init-tag }}' \
257+
{{ args }} \
258+
| {{ _kubectl }} apply -f -
259+
260+
linkerd-uninstall:
261+
linkerd uninstall \
262+
| {{ _kubectl }} delete -f -
263+
264+
linkerd-check-contol-plane-proxy:
265+
#!/usr/bin/env bash
266+
set -euo pipefail
267+
check=$(mktemp --tmpdir check-XXXX.json)
268+
linkerd check -o json > "$check"
269+
result=$(jq -r \
270+
'.categories[] | select(.categoryName == "linkerd-control-plane-proxy") | .checks[] | select(.description == "control plane proxies are healthy") | .result' \
271+
"$check")
272+
if [ "$result" != "success" ]; then
273+
jq '.categories[] | .checks[] | select(.result != "success") | select(.hint | contains("-version") | not)' \
274+
"$check" >&2
275+
{{ _kubectl }} describe po -n linkerd >&2
276+
exit 1
277+
fi
278+
rm "$check"
279+
280+
_linkerd-ready:
281+
{{ _kubectl }} wait pod --for=condition=ready \
282+
--namespace=linkerd --selector='linkerd.io/control-plane-component' \
283+
--timeout=1m

0 commit comments

Comments
 (0)
Please sign in to comment.