Skip to content

Commit dd2c2f8

Browse files
authored
Merge pull request #352 from replicatedhq/jelena-analyze-supportbundle
Analyze kind support bundle
2 parents 45decfc + a2f4041 commit dd2c2f8

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

pkg/analyze/download.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package analyzer
33
import (
44
"archive/tar"
55
"compress/gzip"
6+
"fmt"
67
"io"
78
"io/ioutil"
89
"os"
@@ -14,6 +15,7 @@ import (
1415
troubleshootscheme "github.com/replicatedhq/troubleshoot/pkg/client/troubleshootclientset/scheme"
1516
"github.com/replicatedhq/troubleshoot/pkg/docrewrite"
1617
"github.com/replicatedhq/troubleshoot/pkg/logger"
18+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1719
"k8s.io/client-go/kubernetes/scheme"
1820
)
1921

@@ -180,13 +182,35 @@ func parseAnalyzers(spec string) ([]*troubleshootv1beta2.Analyze, error) {
180182
return nil, errors.Wrap(err, "failed to convert to v1beta2")
181183
}
182184

183-
obj, _, err := decode(convertedSpec, nil, nil)
185+
obj, gvk, err := decode(convertedSpec, nil, nil)
184186
if err != nil {
185187
return nil, errors.Wrap(err, "failed to decode analyzers")
186188
}
187189

188-
analyzer := obj.(*troubleshootv1beta2.Analyzer)
189-
return analyzer.Spec.Analyzers, nil
190+
// SupportBundle overwrites Analyzer if defined
191+
if gvk.String() == "troubleshoot.sh/v1beta2, Kind=SupportBundle" {
192+
supportBundle := obj.(*troubleshootv1beta2.SupportBundle)
193+
analyzer := supportBundleToAnalyzer(supportBundle)
194+
return analyzer.Spec.Analyzers, nil
195+
} else {
196+
analyzer := obj.(*troubleshootv1beta2.Analyzer)
197+
return analyzer.Spec.Analyzers, nil
198+
}
199+
}
200+
201+
func supportBundleToAnalyzer(sb *troubleshootv1beta2.SupportBundle) *troubleshootv1beta2.Analyzer {
202+
return &troubleshootv1beta2.Analyzer{
203+
TypeMeta: metav1.TypeMeta{
204+
APIVersion: "troubleshoot.sh/v1beta2",
205+
Kind: "Analyzer",
206+
},
207+
ObjectMeta: metav1.ObjectMeta{
208+
Name: fmt.Sprintf("%s-analyzer", sb.Name),
209+
},
210+
Spec: troubleshootv1beta2.AnalyzerSpec{
211+
Analyzers: sb.Spec.Analyzers,
212+
},
213+
}
190214
}
191215

192216
func getDefaultAnalyzers() ([]*troubleshootv1beta2.Analyze, error) {

0 commit comments

Comments
 (0)