Skip to content

Commit

Permalink
Merge pull request #145 from replicatedhq/json-yaml-json-yaml
Browse files Browse the repository at this point in the history
BoolString can only unmarshal as json
  • Loading branch information
marccampbell authored Mar 6, 2020
2 parents 62d12d8 + d81cff0 commit 4fca3ff
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 9 deletions.
3 changes: 1 addition & 2 deletions cmd/preflight/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/replicatedhq/troubleshoot/pkg/collect"
"github.com/spf13/viper"
spin "github.com/tj/go-spin"
"gopkg.in/yaml.v2"
)

func runPreflights(v *viper.Viper, arg string) error {
Expand Down Expand Up @@ -59,7 +58,7 @@ func runPreflights(v *viper.Viper, arg string) error {
}

preflight := troubleshootv1beta1.Preflight{}
if err := yaml.Unmarshal([]byte(preflightContent), &preflight); err != nil {
if err := json.Unmarshal([]byte(preflightContent), &preflight); err != nil {
return errors.Wrapf(err, "failed to parse %s as a preflight", arg)
}

Expand Down
3 changes: 1 addition & 2 deletions cmd/troubleshoot/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/pkg/errors"
"github.com/spf13/viper"
spin "github.com/tj/go-spin"
"gopkg.in/yaml.v2"

troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
"github.com/replicatedhq/troubleshoot/pkg/collect"
Expand Down Expand Up @@ -49,7 +48,7 @@ func runTroubleshoot(v *viper.Viper, arg string) error {
}

collector := troubleshootv1beta1.Collector{}
if err := yaml.Unmarshal(collectorContent, &collector); err != nil {
if err := json.Unmarshal(collectorContent, &collector); err != nil {
return errors.Wrapf(err, "failed to parse %s collectors", arg)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/troubleshoot/v1beta1/analyzer_shared_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package v1beta1

import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.undefinedlabs.com/scopeagent"
"gopkg.in/yaml.v2"
)

func TestAnalyze_Unmarshal(t *testing.T) {
Expand Down Expand Up @@ -49,7 +49,7 @@ func TestAnalyze_Unmarshal(t *testing.T) {
req := require.New(t)

a := Analyze{}
err := yaml.Unmarshal([]byte(test.spec), &a)
err := json.Unmarshal([]byte(test.spec), &a)
req.NoError(err)

assert.Equal(t, test.expectObject, a)
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/troubleshoot/v1beta1/collector_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
type CollectorMeta struct {
CollectorName string `json:"collectorName,omitempty" yaml:"collectorName,omitempty"`
// +optional
Exclude multitype.BoolOrString `json:"exclude,omitmempty" yaml:"exclude,omitempty"`
Exclude multitype.BoolOrString `json:"exclude,omitempty" yaml:"exclude,omitempty"`
}

type ClusterInfo struct {
Expand Down
4 changes: 2 additions & 2 deletions pkg/collect/collector.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package collect

import (
"encoding/json"
"strconv"

"github.com/pkg/errors"
"github.com/replicatedhq/kots/kotskinds/multitype"
troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
"gopkg.in/yaml.v2"
authorizationv1 "k8s.io/api/authorization/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -194,7 +194,7 @@ func (cs Collectors) CheckRBAC() error {
func ParseSpec(specContents string) (*troubleshootv1beta1.Collect, error) {
collect := troubleshootv1beta1.Collect{}

if err := yaml.Unmarshal([]byte(specContents), &collect); err != nil {
if err := json.Unmarshal([]byte(specContents), &collect); err != nil {
return nil, err
}

Expand Down

0 comments on commit 4fca3ff

Please sign in to comment.