Skip to content

Commit 9c77a0e

Browse files
Add sbctl integration proposal and move design directory into docs (#893)
* add sbctl integration proposal and move design directory into docs Co-authored-by: Evans Mungai <[email protected]>
1 parent c8820b3 commit 9c77a0e

File tree

7 files changed

+120
-0
lines changed

7 files changed

+120
-0
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Integrate SBCTL with Troubleshoot
2+
3+
## Goals
4+
5+
Make sbctl easier to maintain by consolidating code bases.
6+
7+
Reduce code duplication.
8+
9+
Improve end-user experience and improve discoverability of sbctl.
10+
11+
## Non Goals
12+
13+
## Background
14+
sbctl is our command line tool for examining K8s resources inside of Support Bundles generated by our troubleshoot project. With both projects having separate code bases we see the following problems:
15+
16+
* Most users are familiar with the binaries from troubleshoot (support-bundle, preflight, etc.), but are unaware of the existince of sbctl because it's a separate project
17+
* sbctl and troubleshoot are naturally coupled together due to sbctl's reliance on support bundles to operate. Them being in separate repos leads to duplication of code in both projects increasing maintenance burden.
18+
19+
## High-Level Design
20+
Because the functionality of sbctl and Troubleshoot are so tightly coupled together, they should live in the same repository. Moreover, as opposed to maintaing a separate binary for sbctl, all sbctl commands should become subcommands of `support-bundle`
21+
22+
## Detailed Design
23+
The `serve` and `shell` commands become subcommands of the `support-bundle` CLI.
24+
25+
```
26+
./bin/support-bundle --help
27+
A support bundle is an archive of files, output, metrics and state
28+
from a server that can be used to assist when troubleshooting a Kubernetes cluster.
29+
30+
Usage:
31+
support-bundle [url] [flags]
32+
support-bundle [command]
33+
34+
Available Commands:
35+
analyze analyze a support bundle
36+
serve Start API server
37+
shell Start interractive shell
38+
completion Generate the autocompletion script for the specified shell
39+
...
40+
```
41+
42+
Similiar to the [Analyze](https://github.com/replicatedhq/troubleshoot/blob/main/cmd/troubleshoot/cli/analyze.go) subcommand, we add `serve.go` and `shell.go` to `cmd/troubleshoot/cli`
43+
44+
### Standardize Cluster Resources Collector
45+
* In `pkg/collect` standardize the root directory location of the Cluster Resources collector with a variable instead of repeatedly specifying it as a string - https://github.com/replicatedhq/troubleshoot/blob/main/pkg/collect/cluster_resources.go#L121.
46+
* Import the directory the Cluster Resources collector uses from `pkg/collect` for usage in the APIs - https://github.com/replicatedhq/sbctl/blob/main/pkg/api/server.go#L220. This is an example of the way we can start making the sbctl code more efficient with this change.
47+
48+
cluster_resources.go
49+
```go
50+
const ClusterResourcesPath = `cluster-resources`
51+
...
52+
53+
path := filepath.Join(ClusterResourcesPath, "namespaces.json")
54+
output.SaveResult(c.BundlePath, path, bytes.NewBuffer(namespaces))
55+
```
56+
57+
sbctl-server.go
58+
```go
59+
import (
60+
...
61+
"github.com/replicatedhq/troubleshoot/pkg/collect"
62+
...
63+
)
64+
...
65+
66+
dirName := filepath.Join(collect.ClusterResourcesPath, fmt.Sprintf("%s", resource))
67+
```
68+
69+
### Package Structure
70+
```
71+
cmd
72+
serve/
73+
shell/
74+
pkg
75+
serve/
76+
shell/
77+
tests # API tests, integration tests etc reside here.
78+
serve/ # sbctl BDD tests.
79+
# all tests and test fixtures moved here
80+
```
81+
82+
### Makefile Changes
83+
84+
We'll need to add make targets specific to these commands similar to the current ones
85+
```
86+
make serve run-serve
87+
make shell run-shell
88+
make ginkgo
89+
```
90+
91+
### Docs
92+
In troubleshoot.sh docs, add a new sub section under "Support Bundle" describing then new serve & shell subcommands.
93+
94+
### Other Changes
95+
We would need to merge some of the support bundle functionality we see in both projects like so
96+
97+
- Create a new sbutil module to store reusable support bundle functionality. At least `analyze` & `serve` modules will depend on this module
98+
99+
```
100+
pkg
101+
sbutil/
102+
```
103+
104+
- Merge `troubleshoot/pkg/analyze/download.ExtractTroubleshootBundle` & `sbctl/pkg/sbctl/support-bundle.ExtractBundle` that duplicate support bundle archive extraction
105+
- Build on `sbctl/pkg/sbctl/support-bundle.ClusterData` to have it expose well known paths (ClusterResourcesDir, Version files, analysis results etc) and unmarshalled resources (this bit can be built on a need to have basis) in a support bundle especially once [Add generic kubernetes resource analyzer #780 PR](https://github.com/replicatedhq/troubleshoot/pull/780) is merged.
106+
- Build on `sbctl/pkg/sbctl/support-bundle.FindClusterData` to perform pre-validation of a support bundle to ensure it is valid before running any applications.
107+
108+
## Limitations
109+
110+
## Assumptions
111+
112+
## Testing
113+
We will need to have a separate directory for sbctl (ginkgo BDD) tests. The test harness used is ginkgo cli instead of go test and there is no straight forward way of separating these tests. Also, from a directory structure point of view, such integration tests usually reside in modules in a root level tests directory. Changes to the test code need to be minimal, ideally no change, cause they will be used to ensure any refactored code does not break. We could now easily introduce tests which ensure that changes to collectors don't break APIs in sbctl.
114+
115+
## Alternatives Considered
116+
* Have troubleshoot as a library dependency in sbctl keeping it as a separate binary and repo
117+
* Move sbctl to the Troubleshoot library "as is" and continue maintaing a separate binary
118+
* Leave things as they are
119+
120+
## Security Considerations
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)