Skip to content

Commit c1c772e

Browse files
Merge pull request #617 from replicatedhq/diamonwiggins/sc-48402/support-bundle-host-analyzers
Add HostAnalyzers to Support Bundles
2 parents 1820c40 + a1533d5 commit c1c772e

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

pkg/analyze/download.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type fileContentProvider struct {
2222
}
2323

2424
// Analyze local will analyze a locally available (already downloaded) bundle
25-
func AnalyzeLocal(localBundlePath string, analyzers []*troubleshootv1beta2.Analyze) ([]*AnalyzeResult, error) {
25+
func AnalyzeLocal(localBundlePath string, analyzers []*troubleshootv1beta2.Analyze, hostAnalyzers []*troubleshootv1beta2.HostAnalyze) ([]*AnalyzeResult, error) {
2626
rootDir, err := FindBundleRootDir(localBundlePath)
2727
if err != nil {
2828
return nil, errors.Wrap(err, "failed to find root dir")
@@ -46,6 +46,11 @@ func AnalyzeLocal(localBundlePath string, analyzers []*troubleshootv1beta2.Analy
4646
}
4747
}
4848

49+
for _, hostAnalyzer := range hostAnalyzers {
50+
analyzeResult := HostAnalyze(hostAnalyzer, fcp.getFileContents, fcp.getChildFileContents)
51+
analyzeResults = append(analyzeResults, analyzeResult...)
52+
}
53+
4954
return analyzeResults, nil
5055
}
5156

@@ -71,22 +76,24 @@ func DownloadAndAnalyze(bundleURL string, analyzersSpec string) ([]*AnalyzeResul
7176
}
7277

7378
analyzers := []*troubleshootv1beta2.Analyze{}
79+
hostAnalyzers := []*troubleshootv1beta2.HostAnalyze{}
7480

7581
if analyzersSpec == "" {
76-
defaultAnalyzers, err := getDefaultAnalyzers()
82+
defaultAnalyzers, _, err := getDefaultAnalyzers()
7783
if err != nil {
7884
return nil, errors.Wrap(err, "failed to get default analyzers")
7985
}
8086
analyzers = defaultAnalyzers
8187
} else {
82-
parsedAnalyzers, err := parseAnalyzers(analyzersSpec)
88+
parsedAnalyzers, parsedHostAnalyzers, err := parseAnalyzers(analyzersSpec)
8389
if err != nil {
8490
return nil, errors.Wrap(err, "failed to parse analyzers")
8591
}
8692
analyzers = parsedAnalyzers
93+
hostAnalyzers = parsedHostAnalyzers
8794
}
8895

89-
return AnalyzeLocal(rootDir, analyzers)
96+
return AnalyzeLocal(rootDir, analyzers, hostAnalyzers)
9097
}
9198

9299
func downloadTroubleshootBundle(bundleURL string, destDir string) error {
@@ -174,33 +181,33 @@ func ExtractTroubleshootBundle(reader io.Reader, destDir string) error {
174181
return nil
175182
}
176183

177-
func parseAnalyzers(spec string) ([]*troubleshootv1beta2.Analyze, error) {
184+
func parseAnalyzers(spec string) ([]*troubleshootv1beta2.Analyze, []*troubleshootv1beta2.HostAnalyze, error) {
178185
troubleshootscheme.AddToScheme(scheme.Scheme)
179186
decode := scheme.Codecs.UniversalDeserializer().Decode
180187

181188
convertedSpec, err := docrewrite.ConvertToV1Beta2([]byte(spec))
182189
if err != nil {
183-
return nil, errors.Wrap(err, "failed to convert to v1beta2")
190+
return nil, nil, errors.Wrap(err, "failed to convert to v1beta2")
184191
}
185192

186193
obj, gvk, err := decode(convertedSpec, nil, nil)
187194
if err != nil {
188-
return nil, errors.Wrap(err, "failed to decode analyzers")
195+
return nil, nil, errors.Wrap(err, "failed to decode analyzers")
189196
}
190197

191198
// SupportBundle overwrites Analyzer if defined
192199
if gvk.Group == "troubleshoot.sh" && gvk.Version == "v1beta2" && gvk.Kind == "SupportBundle" {
193200
supportBundle := obj.(*troubleshootv1beta2.SupportBundle)
194-
return supportBundle.Spec.Analyzers, nil
201+
return supportBundle.Spec.Analyzers, supportBundle.Spec.HostAnalyzers, nil
195202
} else if gvk.Group == "troubleshoot.sh" && gvk.Version == "v1beta2" && gvk.Kind == "Analyzer" {
196203
analyzer := obj.(*troubleshootv1beta2.Analyzer)
197-
return analyzer.Spec.Analyzers, nil
204+
return analyzer.Spec.Analyzers, analyzer.Spec.HostAnalyzers, nil
198205
}
199206

200-
return nil, errors.Errorf("invalid gvk %q", gvk)
207+
return nil, nil, errors.Errorf("invalid gvk %q", gvk)
201208
}
202209

203-
func getDefaultAnalyzers() ([]*troubleshootv1beta2.Analyze, error) {
210+
func getDefaultAnalyzers() ([]*troubleshootv1beta2.Analyze, []*troubleshootv1beta2.HostAnalyze, error) {
204211
spec := `apiVersion: troubleshoot.sh/v1beta2
205212
kind: Analyzer
206213
metadata:

pkg/apis/troubleshoot/v1beta2/analyzer_types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import (
2222

2323
// AnalyzerSpec defines the desired state of Analyzer
2424
type AnalyzerSpec struct {
25-
Analyzers []*Analyze `json:"analyzers,omitempty"`
25+
Analyzers []*Analyze `json:"analyzers,omitempty"`
26+
HostAnalyzers []*HostAnalyze `json:"hostAnalyzers,omitempty" yaml:"hostAnalyzers,omitempty"`
2627
}
2728

2829
// AnalyzerStatus defines the observed state of Analyzer

pkg/apis/troubleshoot/v1beta2/supportbundle_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type SupportBundleSpec struct {
2626
Collectors []*Collect `json:"collectors,omitempty" yaml:"collectors,omitempty"`
2727
HostCollectors []*HostCollect `json:"hostCollectors,omitempty" yaml:"hostCollectors,omitempty"`
2828
Analyzers []*Analyze `json:"analyzers,omitempty" yaml:"analyzers,omitempty"`
29+
HostAnalyzers []*HostAnalyze `json:"hostAnalyzers,omitempty" yaml:"hostAnalyzers,omitempty"`
2930
}
3031

3132
// SupportBundleStatus defines the observed state of SupportBundle

pkg/supportbundle/supportbundle.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ func ProcessSupportBundleAfterCollection(spec *troubleshootv1beta2.SupportBundle
201201
// AnalyzeSupportBundle performs analysis on a support bundle using the support bundle spec and an already unpacked support
202202
// bundle on disk
203203
func AnalyzeSupportBundle(spec *troubleshootv1beta2.SupportBundleSpec, tmpDir string) ([]*analyzer.AnalyzeResult, error) {
204-
if len(spec.Analyzers) == 0 {
204+
if len(spec.Analyzers) == 0 && len(spec.HostAnalyzers) == 0 {
205205
return nil, nil
206206
}
207-
analyzeResults, err := analyzer.AnalyzeLocal(tmpDir, spec.Analyzers)
207+
analyzeResults, err := analyzer.AnalyzeLocal(tmpDir, spec.Analyzers, spec.HostAnalyzers)
208208
if err != nil {
209209
return nil, errors.Wrap(err, "failed to analyze support bundle")
210210
}

0 commit comments

Comments
 (0)