Skip to content

Commit

Permalink
fix: yaml unmarshal by gopkg.in/yaml.v3 v3.0.1 (#15)
Browse files Browse the repository at this point in the history
* fix: yaml unmarshal by gopkg.in/yaml.v3 v3.0.1
  • Loading branch information
kilosonc authored Feb 15, 2023
1 parent 7cc3e34 commit c1721d1
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 79 deletions.
4 changes: 2 additions & 2 deletions core/controller/cluster/controller_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"github.com/horizoncd/horizon/pkg/util/wlog"

"github.com/Masterminds/sprig"
"github.com/go-yaml/yaml"
"gopkg.in/yaml.v3"
kyaml "sigs.k8s.io/yaml"
)

Expand Down Expand Up @@ -339,7 +339,7 @@ func RenderOutputObject(outPutStr, templateName string,
if clusterValueFile.Content != nil {
if content, ok := clusterValueFile.Content[templateName]; ok {
// if content is empty or {}, continue
if contentMap, ok := content.(map[interface{}]interface{}); !ok || len(contentMap) == 0 {
if contentMap, ok := content.(map[string]interface{}); !ok || len(contentMap) == 0 {
continue
}
binaryContent, err := yaml.Marshal(content)
Expand Down
10 changes: 3 additions & 7 deletions core/controller/cluster/controller_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,22 +682,18 @@ func (c *controller) updateTagsFromFile(ctx context.Context,
if err != nil {
return err
}
midMap := file.Content[release.ChartName].(map[interface{}]interface{})
tagsMap := midMap[common.GitopsKeyTags].(map[interface{}]interface{})
midMap := file.Content[release.ChartName].(map[string]interface{})
tagsMap := midMap[common.GitopsKeyTags].(map[string]interface{})
tags := make([]*tmodels.Tag, 0, len(tagsMap))
for k, v := range tagsMap {
key, ok := k.(string)
if !ok {
continue
}
value, ok := v.(string)
if !ok {
continue
}
tags = append(tags, &tmodels.Tag{
ResourceID: cluster.ID,
ResourceType: common.ResourceCluster,
Key: key,
Key: k,
Value: value,
})
}
Expand Down
28 changes: 15 additions & 13 deletions core/controller/cluster/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ import (
userservice "github.com/horizoncd/horizon/pkg/user/service"
v1 "k8s.io/api/core/v1"

"github.com/go-yaml/yaml"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"gopkg.in/yaml.v3"
)

// nolint
Expand Down Expand Up @@ -1013,17 +1013,16 @@ func test(t *testing.T) {
b, _ = json.Marshal(shellResp)
t.Logf("%s", string(b))

valueFile := gitrepo.ClusterValueFile{
FileName: common.GitopsFileTags,
}
err = yaml.Unmarshal([]byte(`javaapp:
tags:
test_key: test_value`), &valueFile.Content)
assert.Nil(t, err)

clusterGitRepo.EXPECT().GetClusterValueFiles(gomock.Any(), gomock.Any(), gomock.Any()).
Return([]gitrepo.ClusterValueFile{
{
FileName: common.GitopsFileTags,
Content: map[interface{}]interface{}{
"javaapp": map[interface{}]interface{}{
common.GitopsKeyTags: map[interface{}]interface{}{"test_key": "test_value"},
},
},
},
}, nil)
Return([]gitrepo.ClusterValueFile{valueFile}, nil)
// test rollback
clusterGitRepo.EXPECT().Rollback(ctx, gomock.Any(), gomock.Any(), gomock.Any()).
Return("rollback-commit", nil).AnyTimes()
Expand Down Expand Up @@ -1494,13 +1493,16 @@ syncDomainName:

renderObect, err := c.GetClusterOutput(context.TODO(), 123)
assert.Nil(t, err)
out, err := yaml.Marshal(renderObect)
builder := &strings.Builder{}
encoder := yaml.NewEncoder(builder)
encoder.SetIndent(2)
err = encoder.Encode(renderObect)
assert.Nil(t, err)
var ExpectOutPutStr = `syncDomainName:
Description: sync domain name
Value: app-cluster-demo.cloudnative.com
`
assert.Equal(t, string(out), ExpectOutPutStr)
assert.Equal(t, ExpectOutPutStr, builder.String())
}

var envValue = `
Expand Down
2 changes: 1 addition & 1 deletion core/controller/group/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strconv"
"strings"

"github.com/go-yaml/yaml"
"github.com/horizoncd/horizon/core/common"
herrors "github.com/horizoncd/horizon/core/errors"
appmanager "github.com/horizoncd/horizon/pkg/application/manager"
Expand All @@ -25,6 +24,7 @@ import (
trmanager "github.com/horizoncd/horizon/pkg/templaterelease/manager"
"github.com/horizoncd/horizon/pkg/util/errors"
"github.com/horizoncd/horizon/pkg/util/wlog"
"gopkg.in/yaml.v3"
)

const (
Expand Down
7 changes: 2 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/horizoncd/horizon
go 1.15

require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/sprig v2.22.0+incompatible
github.com/argoproj/argo-cd v1.8.7
github.com/argoproj/argo-rollouts v1.0.7
Expand All @@ -12,7 +11,6 @@ require (
github.com/coreos/go-oidc/v3 v3.2.0
github.com/gin-gonic/gin v1.7.7
github.com/go-redis/redis/v8 v8.3.3
github.com/go-yaml/yaml v2.1.0+incompatible
github.com/golang-jwt/jwt/v4 v4.4.3
github.com/golang/mock v1.6.0
github.com/google/go-github/v41 v41.0.0
Expand All @@ -21,7 +19,6 @@ require (
github.com/gorilla/sessions v1.2.0
github.com/hashicorp/go-retryablehttp v0.6.8
github.com/igm/sockjs-go v3.0.2+incompatible // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/johannesboyne/gofakes3 v0.0.0-20210819161434-5c8dfcfe5310
github.com/mozillazg/go-pinyin v0.18.0
github.com/pkg/errors v0.9.1
Expand All @@ -40,8 +37,7 @@ require (
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/igm/sockjs-go.v3 v3.0.1
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
gopkg.in/yaml.v3 v3.0.1
gorm.io/driver/mysql v1.1.2
gorm.io/driver/sqlite v1.1.5
gorm.io/gorm v1.21.15
Expand Down Expand Up @@ -77,6 +73,7 @@ replace (
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.20.10
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.20.10
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.20.10
k8s.io/kube-openapi => k8s.io/kube-openapi v0.0.0-20200805222855-6aeccd4b50c6
k8s.io/kube-proxy => k8s.io/kube-proxy v0.20.10
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.20.10
k8s.io/kubectl => k8s.io/kubectl v0.20.10
Expand Down
Loading

0 comments on commit c1721d1

Please sign in to comment.