Skip to content

Commit

Permalink
Better marshaling
Browse files Browse the repository at this point in the history
  • Loading branch information
marccampbell committed Mar 6, 2020
1 parent c9b01f9 commit 6c212e2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
14 changes: 10 additions & 4 deletions cmd/preflight/cli/run.go
Expand Up @@ -16,9 +16,11 @@ import (
"github.com/pkg/errors"
analyzerunner "github.com/replicatedhq/troubleshoot/pkg/analyze"
troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
troubleshootclientsetscheme "github.com/replicatedhq/troubleshoot/pkg/client/troubleshootclientset/scheme"
"github.com/replicatedhq/troubleshoot/pkg/collect"
"github.com/spf13/viper"
spin "github.com/tj/go-spin"
"k8s.io/client-go/kubernetes/scheme"
)

func runPreflights(v *viper.Viper, arg string) error {
Expand Down Expand Up @@ -57,11 +59,15 @@ func runPreflights(v *viper.Viper, arg string) error {
preflightContent = string(body)
}

preflight := troubleshootv1beta1.Preflight{}
if err := json.Unmarshal([]byte(preflightContent), &preflight); err != nil {
return errors.Wrapf(err, "failed to parse %s as a preflight", arg)
troubleshootclientsetscheme.AddToScheme(scheme.Scheme)
decode := scheme.Codecs.UniversalDeserializer().Decode
obj, _, err := decode([]byte(preflightContent), nil, nil)
if err != nil {
return errors.Wrapf(err, "failed to parse %s", arg)
}

preflight := obj.(*troubleshootv1beta1.Preflight)

s := spin.New()
finishedCh := make(chan bool, 1)
progressChan := make(chan interface{}, 0) // non-zero buffer will result in missed messages
Expand Down Expand Up @@ -92,7 +98,7 @@ func runPreflights(v *viper.Viper, arg string) error {
close(finishedCh)
}()

allCollectedData, err := runCollectors(v, preflight, progressChan)
allCollectedData, err := runCollectors(v, *preflight, progressChan)
if err != nil {
return err
}
Expand Down
19 changes: 12 additions & 7 deletions cmd/troubleshoot/cli/run.go
Expand Up @@ -19,11 +19,12 @@ import (
"github.com/mattn/go-isatty"
"github.com/mholt/archiver"
"github.com/pkg/errors"
"github.com/spf13/viper"
spin "github.com/tj/go-spin"

troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
"github.com/replicatedhq/troubleshoot/pkg/client/troubleshootclientset/scheme"
troubleshootclientsetscheme "github.com/replicatedhq/troubleshoot/pkg/client/troubleshootclientset/scheme"
"github.com/replicatedhq/troubleshoot/pkg/collect"
"github.com/spf13/viper"
spin "github.com/tj/go-spin"
)

var (
Expand All @@ -47,11 +48,15 @@ func runTroubleshoot(v *viper.Viper, arg string) error {
return errors.Wrap(err, "failed to load collector spec")
}

collector := troubleshootv1beta1.Collector{}
if err := json.Unmarshal(collectorContent, &collector); err != nil {
return errors.Wrapf(err, "failed to parse %s collectors", arg)
troubleshootclientsetscheme.AddToScheme(scheme.Scheme)
decode := scheme.Codecs.UniversalDeserializer().Decode
obj, _, err := decode([]byte(collectorContent), nil, nil)
if err != nil {
return errors.Wrapf(err, "failed to parse %s", arg)
}

collector := obj.(*troubleshootv1beta1.Collector)

s := spin.New()
finishedCh := make(chan bool, 1)
progressChan := make(chan interface{}, 0) // non-zero buffer can result in missed messages
Expand Down Expand Up @@ -83,7 +88,7 @@ func runTroubleshoot(v *viper.Viper, arg string) error {
close(finishedCh)
}()

archivePath, err := runCollectors(v, collector, progressChan)
archivePath, err := runCollectors(v, *collector, progressChan)
if err != nil {
return errors.Wrap(err, "run collectors")
}
Expand Down

0 comments on commit 6c212e2

Please sign in to comment.