E2E Tests for Support Bundle CLI (#761)

* adding e2e tests for support bundle cli

* update e2e.yaml
This commit is contained in:
Diamon Wiggins
2022-10-06 21:43:16 -04:00
committed by GitHub
parent 906fa88119
commit a0fb06f0b9
4 changed files with 166 additions and 3 deletions

View File

@@ -104,7 +104,7 @@ jobs:
name: preflight
path: bin/
- run: chmod +x bin/preflight
- run: make e2e-test
- run: make preflight-e2e-test
compile-supportbundle:
runs-on: ubuntu-latest
@@ -143,6 +143,23 @@ jobs:
- run: ./bin/support-bundle ./examples/support-bundle/sample-supportbundle.yaml
- run: ./bin/support-bundle https://kots.io
validate-supportbundle-e2e:
runs-on: ubuntu-latest
needs: compile-supportbundle
steps:
- uses: actions/checkout@master
- uses: replicatedhq/action-k3s@main
id: k3s
with:
version: v1.23.6-k3s1
- name: Download support bundle binary
uses: actions/download-artifact@v1
with:
name: support-bundle
path: bin/
- run: chmod +x bin/support-bundle
- run: make support-bundle-e2e-test
compile-collect:
runs-on: ubuntu-latest
steps:

View File

@@ -45,10 +45,14 @@ ffi: fmt vet
test: generate fmt vet
go test ${BUILDFLAGS} ./pkg/... ./cmd/... -coverprofile cover.out
.PHONY: e2e-test
e2e-test:
.PHONY: preflight-e2e-test
preflight-e2e-test:
./test/validate-preflight-e2e.sh
.PHONY: support-bundle-e2e-test
support-bundle-e2e-test:
./test/validate-support-bundle-e2e.sh
.PHONY: support-bundle
support-bundle:
go build ${BUILDFLAGS} ${LDFLAGS} -o bin/support-bundle github.com/replicatedhq/troubleshoot/cmd/troubleshoot

View File

@@ -0,0 +1,103 @@
apiVersion: troubleshoot.sh/v1beta2
kind: SupportBundle
metadata:
name: example
spec:
collectors:
- clusterInfo: {}
- clusterResources: {}
- data:
name: config/replicas.txt
data: "5"
- runPod:
collectorName: "static-hi"
podSpec:
containers:
- name: static-hi
image: alpine:3.5
command: ["echo", "hi static!"]
analyzers:
- clusterVersion:
outcomes:
- fail:
when: "< 1.20.0"
message: This application requires at least Kubernetes 1.13.0 or later, and recommends 1.15.0.
uri: https://www.kubernetes.io
- warn:
when: "< 1.21.0"
message: Your cluster meets the minimum version of Kubernetes, but we recommend you update to 1.15.0 or later.
uri: https://kubernetes.io
- pass:
when: ">= 1.22.0"
message: Your cluster meets the recommended and required versions of Kubernetes.
- distribution:
outcomes:
- pass:
when: "== k3s"
message: K3S is a supported distribution
- warn:
message: Unable to determine the distribution of Kubernetes
- textAnalyze:
checkName: Replica Count
fileName: config/replicas.txt
regexGroups: '(?P<Replicas>\d+)'
outcomes:
- fail:
when: "Replicas < 5"
message: That's not enough replicas!
- pass:
message: You have at least 5 replicas
- textAnalyze:
checkName: Said hi!
fileName: /static-hi.log
regex: 'hi static'
outcomes:
- fail:
message: Didn't say hi.
- pass:
message: Said hi!
- nodeResources:
checkName: Must be exactly 1 node in the cluster
outcomes:
- pass:
when: "= 1"
message: This cluster has exactly 1 node
- fail:
message: This application requires exactly 1 node
- nodeResources:
checkName: Must have 1 node with at least 2 cores
filters:
cpuCapacity: "2"
outcomes:
- pass:
when: "= 1"
message: This cluster has exactly 1 node with at least 2 cores
- fail:
message: This application requires exactly 1 node with at least 2 cores
- nodeResources:
checkName: Must have 1 node with 2Gi (available) memory and at least 2 cores (on a single node)
filters:
allocatableMemory: 2Gi
cpuCapacity: "2"
outcomes:
- pass:
when: "= 1"
message: This cluster has exactly 1 node with at least 2Gi available memory and 2 cores
- fail:
message: This application requires exactly 1 node with at least 2Gi available memory and 2 cores
- nodeResources:
checkName: There must be exactly 1 node in the cluster
outcomes:
- pass:
when: "count() = 1"
message: This has exactly 1 node in the cluster
- fail:
message: This application requires exactly 1 node in the cluster
- nodeResources:
checkName: There must be a total of at least 2Gi of memory on all nodes
outcomes:
- fail:
when: "sum(memoryCapacity) < 2Gi"
message: This application requires that 2Gi or more memory be available to the cluster
- pass:
message: This cluster has sufficient memory

View File

@@ -0,0 +1,39 @@
#!/bin/bash
set -euo pipefail
tmpdir="$(mktemp -d)"
bundle_archive_name="support-bundle.tar.gz"
bundle_directory_name="support-bundle"
./bin/support-bundle --interactive=false examples/support-bundle/e2e.yaml --output=$tmpdir/$bundle_archive_name
EXIT_STATUS=0
if ! tar -xvzf $tmpdir/$bundle_archive_name --directory $tmpdir; then
echo "A valid support bundle archive was not generated"
EXIT_STATUS=1
fi
echo "$(cat $tmpdir/$bundle_directory_name/analysis.json)"
if grep -q "No matching files" "$tmpdir/$bundle_directory_name/analysis.json"; then
echo "Some files were not collected"
EXIT_STATUS=1
fi
EXIT_STATUS=0
jq -r '.[].insight.severity' "$tmpdir/$bundle_directory_name/analysis.json" | while read i; do
if [ $i == "error" ]; then
EXIT_STATUS=1
echo "Analyzers with severity of \"error\" found"
fi
if [ $i == "warn" ]; then
EXIT_STATUS=1
echo "Analyzers with severity of \"warn\" found"
fi
done
rm -rf "$tmpdir"
exit $EXIT_STATUS