Skip to content

Commit d81cff0

Browse files
committed
BoolString can only unmarshal as json
1 parent 62d12d8 commit d81cff0

File tree

5 files changed

+7
-9
lines changed

5 files changed

+7
-9
lines changed

cmd/preflight/cli/run.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"github.com/replicatedhq/troubleshoot/pkg/collect"
2020
"github.com/spf13/viper"
2121
spin "github.com/tj/go-spin"
22-
"gopkg.in/yaml.v2"
2322
)
2423

2524
func runPreflights(v *viper.Viper, arg string) error {
@@ -59,7 +58,7 @@ func runPreflights(v *viper.Viper, arg string) error {
5958
}
6059

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

cmd/troubleshoot/cli/run.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/pkg/errors"
2222
"github.com/spf13/viper"
2323
spin "github.com/tj/go-spin"
24-
"gopkg.in/yaml.v2"
2524

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

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

pkg/apis/troubleshoot/v1beta1/analyzer_shared_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package v1beta1
22

33
import (
4+
"encoding/json"
45
"testing"
56

67
"github.com/stretchr/testify/assert"
78
"github.com/stretchr/testify/require"
89
"go.undefinedlabs.com/scopeagent"
9-
"gopkg.in/yaml.v2"
1010
)
1111

1212
func TestAnalyze_Unmarshal(t *testing.T) {
@@ -49,7 +49,7 @@ func TestAnalyze_Unmarshal(t *testing.T) {
4949
req := require.New(t)
5050

5151
a := Analyze{}
52-
err := yaml.Unmarshal([]byte(test.spec), &a)
52+
err := json.Unmarshal([]byte(test.spec), &a)
5353
req.NoError(err)
5454

5555
assert.Equal(t, test.expectObject, a)

pkg/apis/troubleshoot/v1beta1/collector_shared.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
type CollectorMeta struct {
1212
CollectorName string `json:"collectorName,omitempty" yaml:"collectorName,omitempty"`
1313
// +optional
14-
Exclude multitype.BoolOrString `json:"exclude,omitmempty" yaml:"exclude,omitempty"`
14+
Exclude multitype.BoolOrString `json:"exclude,omitempty" yaml:"exclude,omitempty"`
1515
}
1616

1717
type ClusterInfo struct {

pkg/collect/collector.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package collect
22

33
import (
4+
"encoding/json"
45
"strconv"
56

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

197-
if err := yaml.Unmarshal([]byte(specContents), &collect); err != nil {
197+
if err := json.Unmarshal([]byte(specContents), &collect); err != nil {
198198
return nil, err
199199
}
200200

0 commit comments

Comments
 (0)