@@ -25,11 +25,12 @@ import (
2525 "github.com/pkg/errors"
2626 "github.com/replicatedhq/troubleshoot/cmd/util"
2727 analyzer "github.com/replicatedhq/troubleshoot/pkg/analyze"
28- troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1 "
28+ troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2 "
2929 "github.com/replicatedhq/troubleshoot/pkg/client/troubleshootclientset/scheme"
3030 troubleshootclientsetscheme "github.com/replicatedhq/troubleshoot/pkg/client/troubleshootclientset/scheme"
3131 "github.com/replicatedhq/troubleshoot/pkg/collect"
3232 "github.com/replicatedhq/troubleshoot/pkg/convert"
33+ "github.com/replicatedhq/troubleshoot/pkg/docrewrite"
3334 "github.com/replicatedhq/troubleshoot/pkg/redact"
3435 "github.com/spf13/viper"
3536 spin "github.com/tj/go-spin"
@@ -57,7 +58,7 @@ func runTroubleshoot(v *viper.Viper, arg string) error {
5758 return errors .Wrap (err , "failed to load collector spec" )
5859 }
5960
60- multidocs := strings .Split (string (collectorContent ), "---" )
61+ multidocs := strings .Split (string (collectorContent ), "\n ---\n " )
6162
6263 // we suppory both raw collector kinds and supportbundle kinds here
6364 supportBundleSpec , err := parseSupportBundleFromDoc ([]byte (multidocs [0 ]))
@@ -68,31 +69,42 @@ func runTroubleshoot(v *viper.Viper, arg string) error {
6869 troubleshootclientsetscheme .AddToScheme (scheme .Scheme )
6970 decode := scheme .Codecs .UniversalDeserializer ().Decode
7071
71- additionalRedactors := & troubleshootv1beta1 .Redactor {}
72+ additionalRedactors := & troubleshootv1beta2 .Redactor {}
7273 for idx , redactor := range v .GetStringSlice ("redactors" ) {
7374 redactorContent , err := loadSpec (v , redactor )
7475 if err != nil {
7576 return errors .Wrapf (err , "failed to load redactor spec #%d" , idx )
7677 }
78+ redactorContent , err = docrewrite .ConvertToV1Beta2 (redactorContent )
79+ if err != nil {
80+ return errors .Wrap (err , "failed to convert to v1beta2" )
81+ }
7782 obj , _ , err := decode ([]byte (redactorContent ), nil , nil )
7883 if err != nil {
7984 return errors .Wrapf (err , "failed to parse redactors %s" , redactor )
8085 }
81- loopRedactors , ok := obj .(* troubleshootv1beta1 .Redactor )
86+ loopRedactors , ok := obj .(* troubleshootv1beta2 .Redactor )
8287 if ! ok {
83- return fmt .Errorf ("%s is not a troubleshootv1beta1 redactor type" , redactor )
88+ return fmt .Errorf ("%s is not a troubleshootv1beta2 redactor type" , redactor )
8489 }
8590 if loopRedactors != nil {
8691 additionalRedactors .Spec .Redactors = append (additionalRedactors .Spec .Redactors , loopRedactors .Spec .Redactors ... )
8792 }
8893 }
8994
90- for i , additionalDoc := range multidocs [1 :] {
91- obj , _ , err := decode ([]byte (additionalDoc ), nil , nil )
95+ for i , additionalDoc := range multidocs {
96+ if i == 0 {
97+ continue
98+ }
99+ additionalDoc , err := docrewrite .ConvertToV1Beta2 ([]byte (additionalDoc ))
100+ if err != nil {
101+ return errors .Wrap (err , "failed to convert to v1beta2" )
102+ }
103+ obj , _ , err := decode (additionalDoc , nil , nil )
92104 if err != nil {
93105 return errors .Wrapf (err , "failed to parse additional doc %d" , i )
94106 }
95- multidocRedactors , ok := obj .(* troubleshootv1beta1 .Redactor )
107+ multidocRedactors , ok := obj .(* troubleshootv1beta2 .Redactor )
96108 if ! ok {
97109 continue
98110 }
@@ -274,7 +286,12 @@ func loadSpec(v *viper.Viper, arg string) ([]byte, error) {
274286 }
275287}
276288
277- func parseSupportBundleFromDoc (doc []byte ) (* troubleshootv1beta1.SupportBundle , error ) {
289+ func parseSupportBundleFromDoc (doc []byte ) (* troubleshootv1beta2.SupportBundle , error ) {
290+ doc , err := docrewrite .ConvertToV1Beta2 (doc )
291+ if err != nil {
292+ return nil , errors .Wrap (err , "failed to convert to v1beta2" )
293+ }
294+
278295 troubleshootclientsetscheme .AddToScheme (scheme .Scheme )
279296 decode := scheme .Codecs .UniversalDeserializer ().Decode
280297
@@ -283,25 +300,25 @@ func parseSupportBundleFromDoc(doc []byte) (*troubleshootv1beta1.SupportBundle,
283300 return nil , errors .Wrap (err , "failed to parse document" )
284301 }
285302
286- collector , ok := obj .(* troubleshootv1beta1 .Collector )
303+ collector , ok := obj .(* troubleshootv1beta2 .Collector )
287304 if ok {
288- supportBundle := troubleshootv1beta1 .SupportBundle {
305+ supportBundle := troubleshootv1beta2 .SupportBundle {
289306 TypeMeta : metav1.TypeMeta {
290- APIVersion : "troubleshoot.replicated.com/v1beta1 " ,
307+ APIVersion : "troubleshoot.sh/v1beta2 " ,
291308 Kind : "SupportBundle" ,
292309 },
293310 ObjectMeta : collector .ObjectMeta ,
294- Spec : troubleshootv1beta1 .SupportBundleSpec {
311+ Spec : troubleshootv1beta2 .SupportBundleSpec {
295312 Collectors : collector .Spec .Collectors ,
296- Analyzers : []* troubleshootv1beta1 .Analyze {},
313+ Analyzers : []* troubleshootv1beta2 .Analyze {},
297314 AfterCollection : collector .Spec .AfterCollection ,
298315 },
299316 }
300317
301318 return & supportBundle , nil
302319 }
303320
304- supportBundle , ok := obj .(* troubleshootv1beta1 .SupportBundle )
321+ supportBundle , ok := obj .(* troubleshootv1beta2 .SupportBundle )
305322 if ok {
306323 return supportBundle , nil
307324 }
@@ -326,7 +343,7 @@ func canTryInsecure(v *viper.Viper) bool {
326343 return true
327344}
328345
329- func runCollectors (v * viper.Viper , collectors []* troubleshootv1beta1 .Collect , additionalRedactors * troubleshootv1beta1 .Redactor , progressChan chan interface {}) (string , error ) {
346+ func runCollectors (v * viper.Viper , collectors []* troubleshootv1beta2 .Collect , additionalRedactors * troubleshootv1beta2 .Redactor , progressChan chan interface {}) (string , error ) {
330347 bundlePath , err := ioutil .TempDir ("" , "troubleshoot" )
331348 if err != nil {
332349 return "" , errors .Wrap (err , "create temp dir" )
@@ -337,10 +354,10 @@ func runCollectors(v *viper.Viper, collectors []*troubleshootv1beta1.Collect, ad
337354 return "" , errors .Wrap (err , "write version file" )
338355 }
339356
340- collectSpecs := make ([]* troubleshootv1beta1 .Collect , 0 , 0 )
357+ collectSpecs := make ([]* troubleshootv1beta2 .Collect , 0 , 0 )
341358 collectSpecs = append (collectSpecs , collectors ... )
342- collectSpecs = ensureCollectorInList (collectSpecs , troubleshootv1beta1 .Collect {ClusterInfo : & troubleshootv1beta1 .ClusterInfo {}})
343- collectSpecs = ensureCollectorInList (collectSpecs , troubleshootv1beta1 .Collect {ClusterResources : & troubleshootv1beta1 .ClusterResources {}})
359+ collectSpecs = ensureCollectorInList (collectSpecs , troubleshootv1beta2 .Collect {ClusterInfo : & troubleshootv1beta2 .ClusterInfo {}})
360+ collectSpecs = ensureCollectorInList (collectSpecs , troubleshootv1beta2 .Collect {ClusterResources : & troubleshootv1beta2 .ClusterResources {}})
344361
345362 config , err := KubernetesConfigFlags .ToRESTConfig ()
346363 if err != nil {
@@ -374,7 +391,7 @@ func runCollectors(v *viper.Viper, collectors []*troubleshootv1beta1.Collect, ad
374391 return "" , errors .New ("insufficient permissions to run all collectors" )
375392 }
376393
377- globalRedactors := []* troubleshootv1beta1 .Redact {}
394+ globalRedactors := []* troubleshootv1beta2 .Redact {}
378395 if additionalRedactors != nil {
379396 globalRedactors = additionalRedactors .Spec .Redactors
380397 }
@@ -441,6 +458,7 @@ func saveCollectorOutput(output map[string][]byte, bundlePath string, c *collect
441458
442459 return nil
443460}
461+
444462func untarAndSave (tarFile []byte , bundlePath string ) error {
445463 keys := make ([]string , 0 )
446464 dirs := make (map [string ]* tar.Header )
@@ -494,7 +512,7 @@ func untarAndSave(tarFile []byte, bundlePath string) error {
494512 }
495513 return nil
496514}
497- func uploadSupportBundle (r * troubleshootv1beta1 .ResultRequest , archivePath string ) error {
515+ func uploadSupportBundle (r * troubleshootv1beta2 .ResultRequest , archivePath string ) error {
498516 contentType := getExpectedContentType (r .URI )
499517 if contentType != "" && contentType != "application/tar+gzip" {
500518 return fmt .Errorf ("cannot upload content type %s" , contentType )
@@ -567,7 +585,7 @@ func getExpectedContentType(uploadURL string) string {
567585 return parsedURL .Query ().Get ("Content-Type" )
568586}
569587
570- func callbackSupportBundleAPI (r * troubleshootv1beta1 .ResultRequest , archivePath string ) error {
588+ func callbackSupportBundleAPI (r * troubleshootv1beta2 .ResultRequest , archivePath string ) error {
571589 req , err := http .NewRequest (r .Method , r .URI , nil )
572590 if err != nil {
573591 return errors .Wrap (err , "create request" )
@@ -615,6 +633,6 @@ func tarSupportBundleDir(inputDir, outputFilename string) error {
615633}
616634
617635type CollectorFailure struct {
618- Collector * troubleshootv1beta1 .Collect
636+ Collector * troubleshootv1beta2 .Collect
619637 Failure string
620638}
0 commit comments