Skip to content

Commit 5c269e2

Browse files
committed
E2E preflight tests
1 parent 30fb4e2 commit 5c269e2

File tree

3 files changed

+173
-16
lines changed

3 files changed

+173
-16
lines changed

.github/workflows/build-test-deploy.yaml

Lines changed: 71 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
- "main"
88
tags:
99
- "v*.*.*"
10-
10+
1111
jobs:
1212
build:
1313
runs-on: ubuntu-18.04
@@ -24,8 +24,8 @@ jobs:
2424

2525
- uses: actions/checkout@v2
2626

27-
- run: make
28-
27+
- run: make
28+
2929
compile-preflight:
3030
runs-on: ubuntu-latest
3131
needs: build
@@ -39,12 +39,12 @@ jobs:
3939
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
4040
shell: bash
4141
- uses: actions/checkout@master
42-
- run: make preflight
42+
- run: make generate preflight
4343
- uses: actions/upload-artifact@v1
4444
with:
4545
name: preflight
4646
path: bin/preflight
47-
47+
4848
validate-preflight:
4949
runs-on: ubuntu-latest
5050
needs: compile-preflight
@@ -83,6 +83,45 @@ jobs:
8383
8484
exit $EXIT_STATUS
8585
86+
validate-preflight-e2e:
87+
runs-on: ubuntu-latest
88+
needs: compile-preflight
89+
steps:
90+
- uses: actions/checkout@master
91+
- name: Download preflight binary
92+
uses: actions/download-artifact@v1
93+
with:
94+
name: preflight
95+
path: bin/
96+
- uses: engineerd/[email protected]
97+
- run: chmod +x bin/preflight
98+
- run: |
99+
./bin/preflight --interactive=false --format=json examples/preflight/e2e.yaml > result.json
100+
cat result.json
101+
102+
EXIT_STATUS=0
103+
if grep -q "was not collected" result.json; then
104+
echo "Some files were not collected"
105+
EXIT_STATUS=1
106+
fi
107+
108+
if (( `jq '.pass | length' result.json` < 1 )); then
109+
echo "No passing preflights found"
110+
EXIT_STATUS=1
111+
fi
112+
113+
if (( `jq '.warn | length' result.json` > 0 )); then
114+
echo "Warnings found"
115+
EXIT_STATUS=1
116+
fi
117+
118+
if (( `jq '.fail | length' result.json` > 0 )); then
119+
echo "Failed preflights found"
120+
EXIT_STATUS=1
121+
fi
122+
123+
exit $EXIT_STATUS
124+
86125
compile-supportbundle:
87126
runs-on: ubuntu-latest
88127
needs: build
@@ -96,7 +135,7 @@ jobs:
96135
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
97136
shell: bash
98137
- uses: actions/checkout@master
99-
- run: make support-bundle
138+
- run: make generate support-bundle
100139
- uses: actions/upload-artifact@v1
101140
with:
102141
name: support-bundle
@@ -118,16 +157,35 @@ jobs:
118157
- run: ./bin/support-bundle ./examples/support-bundle/sample-supportbundle.yaml
119158
- run: ./bin/support-bundle https://kots.io
120159

160+
compile-collect:
161+
runs-on: ubuntu-latest
162+
needs: build
163+
steps:
164+
- uses: actions/setup-go@v1
165+
with:
166+
go-version: '1.17'
167+
- name: setup env
168+
run: |
169+
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
170+
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
171+
shell: bash
172+
- uses: actions/checkout@master
173+
- run: make generate collect
174+
- uses: actions/upload-artifact@v1
175+
with:
176+
name: collect
177+
path: bin/collect
178+
121179
goreleaser-test:
122180
runs-on: ubuntu-latest
123181
if: startsWith(github.ref, 'refs/tags/v') != true
124182
steps:
125183
- name: Checkout
126184
uses: actions/checkout@v2
127-
185+
128186
- name: Unshallow
129187
run: git fetch --prune --unshallow
130-
188+
131189
- uses: actions/setup-go@v1
132190
with:
133191
go-version: "1.17"
@@ -142,20 +200,21 @@ jobs:
142200
runs-on: ubuntu-latest
143201
needs:
144202
- validate-preflight
203+
- validate-preflight-e2e
145204
- validate-supportbundle
146205
if: startsWith(github.ref, 'refs/tags/v')
147206
steps:
148207
- name: Checkout
149208
uses: actions/checkout@v2
150-
209+
151210
- uses: azure/docker-login@v1
152211
with:
153212
username: repldeploy2
154213
password: ${{ secrets.DOCKERHUB_PASSWORD }}
155214

156215
- name: Unshallow
157216
run: git fetch --prune --unshallow
158-
217+
159218
- uses: actions/setup-go@v1
160219
with:
161220
go-version: "1.17"
@@ -169,14 +228,14 @@ jobs:
169228
echo $COSIGN_KEY | base64 -d > ./cosign.key
170229
env:
171230
COSIGN_KEY: ${{secrets.COSIGN_KEY}}
172-
231+
173232
- name: Generate SBOM
174233
run: |
175234
make sbom
176235
env:
177236
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
178237
COSIGN_KEY: ${{ secrets.COSIGN_KEY }}
179-
238+
180239
- name: Run GoReleaser
181240
uses: goreleaser/goreleaser-action@v2
182241
with:

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,19 @@ test: generate fmt vet
4646
go test ${BUILDFLAGS} ./pkg/... ./cmd/... -coverprofile cover.out
4747

4848
.PHONY: support-bundle
49-
support-bundle: generate fmt vet
49+
support-bundle:
5050
go build ${BUILDFLAGS} ${LDFLAGS} -o bin/support-bundle github.com/replicatedhq/troubleshoot/cmd/troubleshoot
5151

5252
.PHONY: preflight
53-
preflight: generate fmt vet
53+
preflight:
5454
go build ${BUILDFLAGS} ${LDFLAGS} -o bin/preflight github.com/replicatedhq/troubleshoot/cmd/preflight
5555

5656
.PHONY: analyze
57-
analyze: generate fmt vet
57+
analyze:
5858
go build ${BUILDFLAGS} ${LDFLAGS} -o bin/analyze github.com/replicatedhq/troubleshoot/cmd/analyze
5959

6060
.PHONY: collect
61-
collect: generate fmt vet
61+
collect:
6262
go build ${BUILDFLAGS} ${LDFLAGS} -o bin/collect github.com/replicatedhq/troubleshoot/cmd/collect
6363

6464
.PHONY: fmt

examples/preflight/e2e.yaml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
apiVersion: troubleshoot.sh/v1beta2
2+
kind: Preflight
3+
metadata:
4+
name: example
5+
spec:
6+
collectors:
7+
- data:
8+
name: config/replicas.txt
9+
data: "5"
10+
- run:
11+
collectorName: "static-hi"
12+
image: 'alpine:3.5'
13+
command: ["echo", "hi static!"]
14+
analyzers:
15+
- clusterVersion:
16+
outcomes:
17+
- fail:
18+
when: "< 1.13.0"
19+
message: This application requires at least Kubernetes 1.13.0 or later, and recommends 1.15.0.
20+
uri: https://www.kubernetes.io
21+
- warn:
22+
when: "< 1.15.0"
23+
message: Your cluster meets the minimum version of Kubernetes, but we recommend you update to 1.15.0 or later.
24+
uri: https://kubernetes.io
25+
- pass:
26+
when: ">= 1.15.0"
27+
message: Your cluster meets the recommended and required versions of Kubernetes.
28+
- distribution:
29+
outcomes:
30+
- pass:
31+
when: "== k3s"
32+
message: K3S is a supported distribution
33+
- warn:
34+
message: Unable to determine the distribution of Kubernetes
35+
- textAnalyze:
36+
checkName: Replica Count
37+
fileName: config/replicas.txt
38+
regexGroups: '(?P<Replicas>\d+)'
39+
outcomes:
40+
- fail:
41+
when: "Replicas < 5"
42+
message: That's not enough replicas!
43+
- pass:
44+
message: You have at least 5 replicas
45+
- textAnalyze:
46+
checkName: Said hi!
47+
fileName: /static-hi.log
48+
regex: 'hi static'
49+
outcomes:
50+
- fail:
51+
message: Didn't say hi.
52+
- pass:
53+
message: Said hi!
54+
- nodeResources:
55+
checkName: Must be exactly 1 node in the cluster
56+
outcomes:
57+
- pass:
58+
when: "= 1"
59+
message: This cluster has exactly 1 node
60+
- fail:
61+
message: This application requires exactly 1 node
62+
- nodeResources:
63+
checkName: Must have 1 node with at least 2 cores
64+
filters:
65+
cpuCapacity: "2"
66+
outcomes:
67+
- pass:
68+
when: "= 1"
69+
message: This cluster has exactly 1 node with at least 2 cores
70+
- fail:
71+
message: This application requires exactly 1 node with at least 2 cores
72+
- nodeResources:
73+
checkName: Must have 1 node with 2Gi (available) memory and at least 2 cores (on a single node)
74+
filters:
75+
allocatableMemory: 2Gi
76+
cpuCapacity: "2"
77+
outcomes:
78+
- pass:
79+
when: "= 1"
80+
message: This cluster has exactly 1 node with at least 2Gi available memory and 2 cores
81+
- fail:
82+
message: This application requires exactly 1 node with at least 2Gi available memory and 2 cores
83+
- nodeResources:
84+
checkName: There must be exactly 1 node in the cluster
85+
outcomes:
86+
- pass:
87+
when: "count() = 1"
88+
message: This has exactly 1 node in the cluster
89+
- fail:
90+
message: This application requires exactly 1 node in the cluster
91+
- nodeResources:
92+
checkName: There must be a total of at least 2Gi of memory on all nodes
93+
outcomes:
94+
- fail:
95+
when: "sum(memoryCapacity) < 2Gi"
96+
message: This application requires that 2Gi or more memory be available to the cluster
97+
- pass:
98+
message: This cluster has sufficient memory

0 commit comments

Comments
 (0)