Skip to content

Commit 7d30ba4

Browse files
authored
Merge pull request #26 from dweomer/testing/sonobuoy
testing: sonobuoy plugin for e2e testing
2 parents 3c4cdd7 + b53bd3b commit 7d30ba4

File tree

1,529 files changed

+343214
-77
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,529 files changed

+343214
-77
lines changed

.drone.yml

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ steps:
1111
image: rancher/dapper:v0.4.2
1212
commands:
1313
- dapper ci
14+
- dapper e2e-verify
1415
volumes:
1516
- name: docker
1617
path: /var/run/docker.sock
1718

18-
- name: github_binary_release
19+
- name: upload-artifacts
1920
image: ibuildthecloud/github-release:v0.0.1
2021
settings:
2122
api_key:
@@ -36,7 +37,7 @@ steps:
3637
event:
3738
- tag
3839

39-
- name: docker-publish
40+
- name: push-controller
4041
image: plugins/docker
4142
settings:
4243
dockerfile: package/Dockerfile
@@ -55,6 +56,26 @@ steps:
5556
event:
5657
- tag
5758

59+
- name: push-e2e-tests
60+
image: plugins/docker
61+
settings:
62+
dockerfile: package/Dockerfile
63+
target: e2e-tests
64+
password:
65+
from_secret: docker_password
66+
repo: "rancher/system-upgrade-controller"
67+
tag: "${DRONE_TAG}-amd64-e2e-tests"
68+
username:
69+
from_secret: docker_username
70+
when:
71+
instance:
72+
- drone-publish.rancher.io
73+
ref:
74+
- refs/head/master
75+
- refs/tags/*
76+
event:
77+
- tag
78+
5879
volumes:
5980
- name: docker
6081
host:
@@ -77,7 +98,7 @@ steps:
7798
- name: docker
7899
path: /var/run/docker.sock
79100

80-
- name: github_binary_release
101+
- name: upload-artifacts
81102
image: ibuildthecloud/github-release:v0.0.1
82103
settings:
83104
api_key:
@@ -98,7 +119,7 @@ steps:
98119
event:
99120
- tag
100121

101-
- name: docker-publish
122+
- name: push-controller
102123
image: plugins/docker
103124
settings:
104125
dockerfile: package/Dockerfile
@@ -117,6 +138,26 @@ steps:
117138
event:
118139
- tag
119140

141+
- name: push-e2e-tests
142+
image: plugins/docker
143+
settings:
144+
dockerfile: package/Dockerfile
145+
target: e2e-tests
146+
password:
147+
from_secret: docker_password
148+
repo: "rancher/system-upgrade-controller"
149+
tag: "${DRONE_TAG}-arm64-e2e-tests"
150+
username:
151+
from_secret: docker_username
152+
when:
153+
instance:
154+
- drone-publish.rancher.io
155+
ref:
156+
- refs/head/master
157+
- refs/tags/*
158+
event:
159+
- tag
160+
120161
volumes:
121162
- name: docker
122163
host:
@@ -139,7 +180,7 @@ steps:
139180
- name: docker
140181
path: /var/run/docker.sock
141182

142-
- name: github_binary_release
183+
- name: upload-artifacts
143184
image: ibuildthecloud/github-release:v0.0.1
144185
settings:
145186
api_key:
@@ -160,7 +201,7 @@ steps:
160201
event:
161202
- tag
162203

163-
- name: docker-publish
204+
- name: push-controller
164205
image: plugins/docker
165206
settings:
166207
dockerfile: package/Dockerfile
@@ -193,7 +234,7 @@ platform:
193234
arch: amd64
194235

195236
steps:
196-
- name: manifest
237+
- name: controller
197238
image: plugins/manifest:1.0.2
198239
settings:
199240
username:
@@ -215,6 +256,27 @@ steps:
215256
event:
216257
- tag
217258

259+
- name: e2e-tests
260+
image: plugins/manifest:1.0.2
261+
settings:
262+
username:
263+
from_secret: docker_username
264+
password:
265+
from_secret: docker_password
266+
platforms:
267+
- linux/amd64
268+
- linux/arm64
269+
target: "rancher/system-upgrade-controller:${DRONE_TAG}-e2e-tests"
270+
template: "rancher/system-upgrade-controller:${DRONE_TAG}-ARCH-e2e-tests"
271+
when:
272+
instance:
273+
- drone-publish.rancher.io
274+
ref:
275+
- refs/head/master
276+
- refs/tags/*
277+
event:
278+
- tag
279+
218280
depends_on:
219281
- amd64
220282
- arm64

Dockerfile.dapper

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
ARG KUBECTL=rancher/kubectl:v1.17.0
2+
# ARG SONOBUOY=sonobuoy/sonobuoy:v0.17.2
3+
# FROM ${SONOBUOY} AS sonobuoy
4+
FROM ${KUBECTL} AS kubectl
5+
16
FROM golang:1.13-alpine
27

8+
COPY --from=kubectl /bin/kubectl /usr/local/bin/kubectl
9+
# COPY --from=sonobuoy /sonobuoy /usr/local/bin/sonobuoy
10+
311
ARG DAPPER_HOST_ARCH
412
ENV ARCH $DAPPER_HOST_ARCH
513

6-
RUN apk -U add bash expect git gcc jq musl-dev docker vim less file curl wget ca-certificates
14+
RUN apk -U add coreutils bash expect git gcc jq musl-dev docker docker-compose vim less file curl wget ca-certificates iproute2
715
RUN go get -d golang.org/x/lint/golint && \
816
git -C /go/src/golang.org/x/lint/golint checkout -b current 06c8688daad7faa9da5a0c2f163a3d14aac986ca && \
917
go install golang.org/x/lint/golint && \
@@ -16,13 +24,21 @@ RUN rm -rf /go/src /go/pkg
1624
RUN if [ "${ARCH}" == "amd64" ]; then \
1725
curl -sL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s v1.15.0; \
1826
fi
27+
ARG SONOBUOY_VERSION=0.17.2
28+
RUN if [ "${ARCH}" != "arm" ]; then \
29+
set -x; \
30+
curl -sL "https://github.com/vmware-tanzu/sonobuoy/releases/download/v${SONOBUOY_VERSION}/sonobuoy_${SONOBUOY_VERSION}_linux_${ARCH}.tar.gz" \
31+
| tar -xz -C /usr/local/bin; \
32+
chmod +x /usr/local/bin/sonobuoy; \
33+
fi
1934

2035
# ENV DAPPER_RUN_ARGS --privileged
2136
ENV DAPPER_ENV REPO TAG DRONE_TAG
2237
ENV DAPPER_SOURCE /go/src/github.com/rancher/system-upgrade-controller/
2338
ENV DAPPER_OUTPUT ./bin ./dist
2439
ENV DAPPER_DOCKER_SOCKET true
2540
ENV HOME ${DAPPER_SOURCE}
41+
ENV KUBECONFIG /root/.kube/config
2642
ENV GO111MODULE off
2743
WORKDIR ${DAPPER_SOURCE}
2844

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ TARGETS := $(shell ls scripts)
1010
$(TARGETS): .dapper
1111
./.dapper $@
1212

13-
e2e:
14-
./scripts/verify
13+
e2e: e2e-verify
14+
15+
clean:
16+
rm -rvf ./bin ./dist
1517

1618
.DEFAULT_GOAL := ci
1719

18-
.PHONY: $(TARGETS) e2e
20+
.PHONY: $(TARGETS) e2e clean

README.md

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ spec:
5252
5353
# The value for `channel` is assumed to be a URL that returns HTTP 302 with the last path element of the value
5454
# returned in the Location header assumed to be an image tag.
55-
# SEE https://github.com/rancher/system-upgrade-controller/blob/v0.1.0/pkg/upgrade/plan/plan.go#L177
5655
channel: https://github.com/rancher/k3os/releases/latest
5756
5857
# Providing a value for `version` will prevent polling/resolution of the `channel` if specified.
@@ -63,10 +62,8 @@ spec:
6362
matchExpressions:
6463
# This limits application of this upgrade only to nodes that have opted in by applying this label.
6564
# Additionally, a value of `disabled` for this label on a node will cause the controller to skip over the node.
66-
# SEE https://github.com/rancher/system-upgrade-controller/blob/v0.1.0/pkg/upgrade/plan/plan.go#L216
6765
# NOTICE THAT THE NAME PORTION OF THIS LABEL MATCHES THE PLAN NAME. This is related to the fact that the
68-
# system-upgrade-controller will tag the node with this very label having the value of the applied version.
69-
# SEE https://github.com/rancher/system-upgrade-controller/blob/v0.1.0/pkg/upgrade/plan/plan.go#L112-L115
66+
# system-upgrade-controller will tag the node with this very label having the value of the applied plan.status.latestHash.
7067
- {key: plan.upgrade.cattle.io/k3os-latest, operator: Exists}
7168
# This label is set by k3OS, therefore a node without it should not apply this upgrade.
7269
- {key: k3os.io/mode, operator: Exists}
@@ -83,15 +80,13 @@ spec:
8380
# image: alpine:3.11
8481
# command: [sh, -c]
8582
# args: [" echo '### ENV ###'; env | sort; echo '### RUN ###'; find /run/system-upgrade | sort"]
86-
# SEE https://github.com/rancher/system-upgrade-controller/blob/v0.1.0/pkg/apis/upgrade.cattle.io/v1/types.go#L58
8783
8884
# See https://kubernetes.io/docs/tasks/administer-cluster/safely-drain-node/#use-kubectl-drain-to-remove-a-node-from-service
8985
drain:
9086
# deleteLocalData: true
9187
# ignoreDaemonSets: true
9288
force: true
9389
94-
# SEE https://github.com/rancher/system-upgrade-controller/blob/v0.1.0/pkg/apis/upgrade.cattle.io/v1/types.go#L51
9590
upgrade:
9691
# The tag portion of the image will be overridden with the value from `.status.latestVersion` a.k.a. the resolved version.
9792
# SEE https://github.com/rancher/system-upgrade-controller/blob/v0.1.0/pkg/apis/upgrade.cattle.io/v1/types.go#L47
@@ -112,7 +107,10 @@ spec:
112107
```
113108

114109
## Building
115-
`make`
110+
111+
```shell script
112+
make
113+
```
116114

117115
### Local Execution
118116

@@ -122,6 +120,27 @@ Also see [`manifests/system-upgrade-controller.yaml`](manifests/system-upgrade-c
122120
"typical" deployment might look like with default environment variables that parameterize various operational aspects
123121
of the controller and the resources spawned by it.
124122

123+
### End-to-End Testing
124+
125+
Integration tests are bundled as a [Sonobuoy plugin](https://sonobuoy.io/docs/v0.17.2/plugins/) that expects to be run within a pod.
126+
To verify locally:
127+
128+
```shell script
129+
make e2e
130+
```
131+
132+
This will, via Dapper, stand up a local cluster (using docker-compose) and then run the Sonobuoy plugin against/within it.
133+
The Sonobuoy results are parsed and a `Status: passed` results in a clean exit, whereas `Status: failed` exits non-zero.
134+
See [scripts/e2e-results](scripts/e2e-results) called by [scripts/e2e-verify](scripts/e2e-verify).
135+
136+
Alternatively, if you have a working cluster and Sonobuoy installation, provided you've pushed the images (consider building with
137+
something like `make REPO=dweomer TAG=dev`), then you can run the e2e tests thusly:
138+
139+
```shell script
140+
sonobuoy run --plugin dist/artifacts/system-upgrade-controller-e2e-tests.yaml --wait
141+
sonobuoy results $(sonobuoy retrieve)
142+
```
143+
125144
## License
126145
Copyright (c) 2019-2020 [Rancher Labs, Inc.](http://rancher.com)
127146

e2e/cluster/local/docker-compose.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
version: "3.7"
2+
3+
volumes:
4+
kubeconfig:
5+
name: e2e-local-kubeconfig
6+
7+
services:
8+
9+
leader:
10+
container_name: local-leader
11+
image: "e2e/cluster/local/k3s"
12+
build:
13+
context: ./images/k3s/.
14+
args:
15+
- ARCH=${ARCH}
16+
command: server --no-deploy=traefik,metrics-server
17+
environment:
18+
- K3S_TOKEN=e2e
19+
hostname: local-leader
20+
privileged: true
21+
ports:
22+
- "172.17.0.1:6443:6443" # k3s
23+
volumes:
24+
- source: kubeconfig
25+
target: /etc/rancher/k3s
26+
type: volume
27+
28+
worker:
29+
depends_on:
30+
- leader
31+
container_name: local-worker
32+
image: "e2e/cluster/local/k3s"
33+
# build:
34+
# context: ./images/k3s/.
35+
# args:
36+
# - ARCH=${ARCH}
37+
command: agent --server https://local-leader:6443
38+
environment:
39+
- K3S_TOKEN=e2e
40+
hostname: local-worker
41+
privileged: true
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Install the all-in-one binary so we can copy our run-time images into the image
2+
# which helps avoid pulling them when running e2e tests.
3+
ARG ALPINE="library/alpine:3.11"
4+
FROM ${ALPINE} AS k3s
5+
ARG ARCH
6+
ARG K3S_VERSION="v1.17.2+k3s1"
7+
RUN set -x \
8+
&& apk --no-cache add \
9+
bash \
10+
ca-certificates \
11+
curl \
12+
&& if [ "${ARCH?required}" != "amd64" ]; then \
13+
K3S_SUFFIX="-${ARCH}"; \
14+
fi \
15+
&& curl -fsSL "https://github.com/rancher/k3s/releases/download/${K3S_VERSION}/k3s${K3S_SUFFIX}" > /bin/k3s \
16+
&& chmod +x /bin/k3s \
17+
&& ln -s /bin/k3s /bin/kubectl \
18+
&& ln -s /bin/k3s /bin/ctr \
19+
&& k3s --version
20+
21+
COPY scratch/*-${ARCH}.tar /var/lib/rancher/k3s/agent/images/
22+
23+
VOLUME /var/lib/cni
24+
VOLUME /var/lib/kubelet
25+
VOLUME /var/lib/rancher/k3s
26+
VOLUME /var/log
27+
28+
ENTRYPOINT ["k3s"]
29+
CMD ["server"]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
cd $(dirname $0)/..
6+
7+
docker-compose down \
8+
--remove-orphans \
9+
--rmi local \
10+
--volumes
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
set -e -o pipefail
4+
5+
cd $(dirname $0)/..
6+
7+
mkdir -vp "$(dirname ${KUBECONFIG:="${HOME}/.kube/config"})"
8+
docker exec local-leader kubectl config view --raw | sed -e 's/127.0.0.1/172.17.0.1/g' > "${KUBECONFIG}"
9+
#echo "${KUBECONFIG}" >&2
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
docker ps \
4+
--filter label=com.docker.compose.project=local \
5+
--format='{{.Image}} ' \
6+
| grep 'e2e/cluster/local/k3s' | wc -l | awk '{print $1}' | tr -d '[:space:]'

0 commit comments

Comments
 (0)