Skip to content

Commit 249e52d

Browse files
authored
Merge pull request #576 from replicatedhq/emosbaugh/fix-run-collector-text-analyze
Fix run collector text analyze file path mismatch
2 parents 24096b0 + 6b5b929 commit 249e52d

File tree

5 files changed

+193
-26
lines changed

5 files changed

+193
-26
lines changed

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

Lines changed: 86 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ on:
77
- "main"
88
tags:
99
- "v*.*.*"
10-
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
14+
1115
jobs:
12-
build:
16+
test:
1317
runs-on: ubuntu-18.04
1418
steps:
1519
- uses: actions/setup-go@v1
@@ -24,11 +28,10 @@ jobs:
2428

2529
- uses: actions/checkout@v2
2630

27-
- run: make
28-
31+
- run: make test
32+
2933
compile-preflight:
3034
runs-on: ubuntu-latest
31-
needs: build
3235
steps:
3336
- uses: actions/setup-go@v1
3437
with:
@@ -39,22 +42,25 @@ jobs:
3942
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
4043
shell: bash
4144
- uses: actions/checkout@master
42-
- run: make preflight
45+
- run: make generate preflight
4346
- uses: actions/upload-artifact@v1
4447
with:
4548
name: preflight
4649
path: bin/preflight
47-
50+
4851
validate-preflight:
4952
runs-on: ubuntu-latest
5053
needs: compile-preflight
5154
steps:
55+
- uses: replicatedhq/action-k3s@main
56+
id: k3s
57+
with:
58+
version: v1.23.6-k3s1
5259
- name: Download preflight binary
5360
uses: actions/download-artifact@v1
5461
with:
5562
name: preflight
5663
path: bin/
57-
- uses: engineerd/[email protected]
5864
- run: chmod +x bin/preflight
5965
- run: |
6066
./bin/preflight --interactive=false --format=json https://preflight.replicated.com > result.json
@@ -83,9 +89,50 @@ jobs:
8389
8490
exit $EXIT_STATUS
8591
92+
validate-preflight-e2e:
93+
runs-on: ubuntu-latest
94+
needs: compile-preflight
95+
steps:
96+
- uses: actions/checkout@master
97+
- uses: replicatedhq/action-k3s@main
98+
id: k3s
99+
with:
100+
version: v1.23.6-k3s1
101+
- name: Download preflight binary
102+
uses: actions/download-artifact@v1
103+
with:
104+
name: preflight
105+
path: bin/
106+
- run: chmod +x bin/preflight
107+
- run: |
108+
./bin/preflight --interactive=false --format=json examples/preflight/e2e.yaml > result.json
109+
cat result.json
110+
111+
EXIT_STATUS=0
112+
if grep -q "was not collected" result.json; then
113+
echo "Some files were not collected"
114+
EXIT_STATUS=1
115+
fi
116+
117+
if (( `jq '.pass | length' result.json` < 1 )); then
118+
echo "No passing preflights found"
119+
EXIT_STATUS=1
120+
fi
121+
122+
if (( `jq '.warn | length' result.json` > 0 )); then
123+
echo "Warnings found"
124+
EXIT_STATUS=1
125+
fi
126+
127+
if (( `jq '.fail | length' result.json` > 0 )); then
128+
echo "Failed preflights found"
129+
EXIT_STATUS=1
130+
fi
131+
132+
exit $EXIT_STATUS
133+
86134
compile-supportbundle:
87135
runs-on: ubuntu-latest
88-
needs: build
89136
steps:
90137
- uses: actions/setup-go@v1
91138
with:
@@ -96,7 +143,7 @@ jobs:
96143
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
97144
shell: bash
98145
- uses: actions/checkout@master
99-
- run: make support-bundle
146+
- run: make generate support-bundle
100147
- uses: actions/upload-artifact@v1
101148
with:
102149
name: support-bundle
@@ -107,27 +154,48 @@ jobs:
107154
needs: compile-supportbundle
108155
steps:
109156
- uses: actions/checkout@v1
157+
- uses: replicatedhq/action-k3s@main
158+
id: k3s
159+
with:
160+
version: v1.23.6-k3s1
110161
- name: Download support-bundle binary
111162
uses: actions/download-artifact@v1
112163
with:
113164
name: support-bundle
114165
path: bin/
115-
- uses: engineerd/[email protected]
116166
- run: chmod +x bin/support-bundle
117167
- run: ./bin/support-bundle ./examples/support-bundle/sample-collectors.yaml
118168
- run: ./bin/support-bundle ./examples/support-bundle/sample-supportbundle.yaml
119169
- run: ./bin/support-bundle https://kots.io
120170

171+
compile-collect:
172+
runs-on: ubuntu-latest
173+
steps:
174+
- uses: actions/setup-go@v1
175+
with:
176+
go-version: '1.17'
177+
- name: setup env
178+
run: |
179+
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
180+
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
181+
shell: bash
182+
- uses: actions/checkout@master
183+
- run: make generate collect
184+
- uses: actions/upload-artifact@v1
185+
with:
186+
name: collect
187+
path: bin/collect
188+
121189
goreleaser-test:
122190
runs-on: ubuntu-latest
123191
if: startsWith(github.ref, 'refs/tags/v') != true
124192
steps:
125193
- name: Checkout
126194
uses: actions/checkout@v2
127-
195+
128196
- name: Unshallow
129197
run: git fetch --prune --unshallow
130-
198+
131199
- uses: actions/setup-go@v1
132200
with:
133201
go-version: "1.17"
@@ -142,20 +210,21 @@ jobs:
142210
runs-on: ubuntu-latest
143211
needs:
144212
- validate-preflight
213+
- validate-preflight-e2e
145214
- validate-supportbundle
146215
if: startsWith(github.ref, 'refs/tags/v')
147216
steps:
148217
- name: Checkout
149218
uses: actions/checkout@v2
150-
219+
151220
- uses: azure/docker-login@v1
152221
with:
153222
username: repldeploy2
154223
password: ${{ secrets.DOCKERHUB_PASSWORD }}
155224

156225
- name: Unshallow
157226
run: git fetch --prune --unshallow
158-
227+
159228
- uses: actions/setup-go@v1
160229
with:
161230
go-version: "1.17"
@@ -169,14 +238,14 @@ jobs:
169238
echo $COSIGN_KEY | base64 -d > ./cosign.key
170239
env:
171240
COSIGN_KEY: ${{secrets.COSIGN_KEY}}
172-
241+
173242
- name: Generate SBOM
174243
run: |
175244
make sbom
176245
env:
177246
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
178247
COSIGN_KEY: ${{ secrets.COSIGN_KEY }}
179-
248+
180249
- name: Run GoReleaser
181250
uses: goreleaser/goreleaser-action@v2
182251
with:

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ endef
3535

3636
BUILDFLAGS = -tags "netgo containers_image_ostree_stub exclude_graphdriver_devicemapper exclude_graphdriver_btrfs containers_image_openpgp" -installsuffix netgo
3737

38-
all: test
38+
all: test support-bundle preflight collect
3939

4040
.PHONY: ffi
4141
ffi: fmt vet
@@ -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

pkg/collect/run.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ func Run(c *Collector, runCollector *troubleshootv1beta2.Run) (CollectorResult,
3232
}
3333

3434
runPodCollector := &troubleshootv1beta2.RunPod{
35-
Name: runCollector.CollectorName,
35+
CollectorMeta: troubleshootv1beta2.CollectorMeta{
36+
CollectorName: runCollector.CollectorName,
37+
},
38+
Name: runCollector.Name,
3639
Namespace: namespace,
3740
Timeout: runCollector.Timeout,
3841
ImagePullSecret: runCollector.ImagePullSecret,
@@ -189,9 +192,6 @@ func runWithoutTimeout(ctx context.Context, c *Collector, pod *corev1.Pod, runPo
189192
output := NewResult()
190193

191194
collectorName := runPodCollector.Name
192-
if collectorName == "" {
193-
collectorName = runPodCollector.CollectorName
194-
}
195195

196196
limits := troubleshootv1beta2.LogLimits{
197197
MaxLines: 10000,
File renamed without changes.

0 commit comments

Comments
 (0)