Skip to content

Commit f64d98b

Browse files
authored
feat(examples): loading troubleshoot specs from helm chart example (#1252)
* feat(examples): loading troubleshoot specs from helm chart example
1 parent f0efbf6 commit f64d98b

File tree

8 files changed

+550
-0
lines changed

8 files changed

+550
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ jobs:
162162
- run: chmod +x bin/preflight
163163
- run: make preflight-e2e-test
164164

165+
run-examples:
166+
runs-on: ubuntu-latest
167+
steps:
168+
- uses: actions/checkout@v3
169+
- run: make run-examples
170+
165171
compile-supportbundle:
166172
runs-on: ubuntu-latest
167173
steps:

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ test-integration:
6262
preflight-e2e-test:
6363
./test/validate-preflight-e2e.sh
6464

65+
.PHONY: run-examples
66+
run-examples:
67+
./test/run-examples.sh
68+
6569
.PHONY: support-bundle-e2e-test
6670
support-bundle-e2e-test:
6771
./test/validate-support-bundle-e2e.sh
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Parse troubleshoot specs from a helm chart
2+
3+
This is an example of using troubleshoot's `loader.LoadSpecs` API to load specs from rendered manifests in a helm chart. The chart in this example contains a kubernetes `Secret` & `ConfigMap` with troubleshoot specs, as well as a troubleshoot custom resource. The custom resource is behind a values flag and does not get rendered by default. The code adds this flag to ensure that the manifest is rendered so as to load it.
4+
5+
The manifests are rendered with the equivalent of `helm template --values values.yaml` where the output is a YAML multidoc. `loader.LoadSpecs` will take the YAML multidoc as an input and extract troubleshoot specs inside kuberenetes `Secrets` and `ConfigMap`s, and any troubleshoot custom resources found.
6+
7+
This application always uses the local version of troubleshoot so as to build using the latest version of the library. This ensures that the example is kept in sync with new features.
8+
9+
### Running
10+
11+
```go
12+
go mod tidy # sync go modules
13+
go run main.go # run the application. This should print out a YAML multidoc of the loaded troubleshoot specs
14+
```

examples/sdk/helm-template/go.mod

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
module helm-template
2+
3+
go 1.20
4+
5+
// Always use the local version of troubleshoot so as to build using
6+
// the latest version of the library. This will ensure the example
7+
// is kept in sync with new features
8+
replace github.com/replicatedhq/troubleshoot v0.0.0 => ../../../
9+
10+
require (
11+
github.com/replicatedhq/troubleshoot v0.0.0
12+
helm.sh/helm/v3 v3.12.1
13+
sigs.k8s.io/yaml v1.3.0
14+
)
15+
16+
require (
17+
github.com/BurntSushi/toml v1.2.1 // indirect
18+
github.com/Masterminds/goutils v1.1.1 // indirect
19+
github.com/Masterminds/semver/v3 v3.2.1 // indirect
20+
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
21+
github.com/cyphar/filepath-securejoin v0.2.3 // indirect
22+
github.com/davecgh/go-spew v1.1.1 // indirect
23+
github.com/emicklei/go-restful/v3 v3.10.2 // indirect
24+
github.com/go-logr/logr v1.2.4 // indirect
25+
github.com/go-openapi/jsonpointer v0.19.6 // indirect
26+
github.com/go-openapi/jsonreference v0.20.2 // indirect
27+
github.com/go-openapi/swag v0.22.3 // indirect
28+
github.com/gobwas/glob v0.2.3 // indirect
29+
github.com/gogo/protobuf v1.3.2 // indirect
30+
github.com/golang/protobuf v1.5.3 // indirect
31+
github.com/google/gnostic v0.6.9 // indirect
32+
github.com/google/go-cmp v0.5.9 // indirect
33+
github.com/google/gofuzz v1.2.0 // indirect
34+
github.com/google/uuid v1.3.0 // indirect
35+
github.com/huandu/xstrings v1.4.0 // indirect
36+
github.com/imdario/mergo v0.3.15 // indirect
37+
github.com/josharian/intern v1.0.0 // indirect
38+
github.com/json-iterator/go v1.1.12 // indirect
39+
github.com/mailru/easyjson v0.7.7 // indirect
40+
github.com/mitchellh/copystructure v1.2.0 // indirect
41+
github.com/mitchellh/reflectwalk v1.0.2 // indirect
42+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
43+
github.com/modern-go/reflect2 v1.0.2 // indirect
44+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
45+
github.com/pkg/errors v0.9.1 // indirect
46+
github.com/shopspring/decimal v1.3.1 // indirect
47+
github.com/spf13/cast v1.5.1 // indirect
48+
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
49+
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
50+
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
51+
golang.org/x/crypto v0.9.0 // indirect
52+
golang.org/x/net v0.10.0 // indirect
53+
golang.org/x/oauth2 v0.7.0 // indirect
54+
golang.org/x/sys v0.8.0 // indirect
55+
golang.org/x/term v0.8.0 // indirect
56+
golang.org/x/text v0.10.0 // indirect
57+
golang.org/x/time v0.3.0 // indirect
58+
google.golang.org/appengine v1.6.7 // indirect
59+
google.golang.org/protobuf v1.30.0 // indirect
60+
gopkg.in/inf.v0 v0.9.1 // indirect
61+
gopkg.in/yaml.v2 v2.4.0 // indirect
62+
gopkg.in/yaml.v3 v3.0.1 // indirect
63+
k8s.io/api v0.27.3 // indirect
64+
k8s.io/apiextensions-apiserver v0.27.2 // indirect
65+
k8s.io/apimachinery v0.27.3 // indirect
66+
k8s.io/client-go v0.27.3 // indirect
67+
k8s.io/klog/v2 v2.100.1 // indirect
68+
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
69+
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
70+
sigs.k8s.io/controller-runtime v0.15.0 // indirect
71+
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
72+
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
73+
)

0 commit comments

Comments
 (0)