Skip to content

Commit d037553

Browse files
authored
Merge pull request kubernetes#2870 from spiffxp/unmarshal-strict
keps: centralize yaml calls, use UnmarshalStrict
2 parents 0ec64c8 + 1bee1d9 commit d037553

File tree

12 files changed

+70
-24
lines changed

12 files changed

+70
-24
lines changed

api/approval.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import (
2323

2424
"github.com/go-playground/validator/v10"
2525
"github.com/pkg/errors"
26-
"gopkg.in/yaml.v3"
26+
27+
"k8s.io/enhancements/pkg/yaml"
2728
)
2829

2930
type PRRApprovals []*PRRApproval
@@ -108,7 +109,7 @@ func (p *PRRHandler) Parse(in io.Reader) (*PRRApproval, error) {
108109
return approval, errors.Wrap(err, "reading file")
109110
}
110111

111-
if err := yaml.Unmarshal(body.Bytes(), &approval); err != nil {
112+
if err := yaml.UnmarshalStrict(body.Bytes(), &approval); err != nil {
112113
p.Errors = append(p.Errors, errors.Wrap(err, "error unmarshalling YAML"))
113114
return approval, errors.Wrap(err, "unmarshalling YAML")
114115
}

api/groups.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626

2727
"github.com/pkg/errors"
2828

29-
"sigs.k8s.io/yaml"
29+
"k8s.io/enhancements/pkg/yaml"
3030
)
3131

3232
// GroupFetcher is responsible for getting informationg about groups in the
@@ -147,9 +147,10 @@ func (f *RemoteGroupFetcher) FetchPRRApprovers() ([]string, error) {
147147
}
148148

149149
config := &struct {
150-
Data map[string][]string `json:"aliases,omitempty"`
150+
Data map[string][]string `json:"aliases,omitempty" yaml:"aliases,omitempty"`
151151
}{}
152-
if err := yaml.Unmarshal(body, config); err != nil {
152+
153+
if err := yaml.UnmarshalStrict(body, config); err != nil {
153154
return nil, errors.Wrap(err, "unmarshalling owners aliases")
154155
}
155156

api/proposal.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ import (
2626

2727
"github.com/go-playground/validator/v10"
2828
"github.com/pkg/errors"
29-
"gopkg.in/yaml.v3"
29+
30+
"k8s.io/enhancements/pkg/yaml"
3031
)
3132

3233
var ValidStages = []string{
@@ -119,7 +120,7 @@ func (k *KEPHandler) Parse(in io.Reader) (*Proposal, error) {
119120
kep.Contents = ""
120121
}
121122

122-
if err := yaml.Unmarshal(metadata, &kep); err != nil {
123+
if err := yaml.UnmarshalStrict(metadata, &kep); err != nil {
123124
k.Errors = append(k.Errors, errors.Wrap(err, "error unmarshalling YAML"))
124125
return kep, errors.Wrap(err, "unmarshalling YAML")
125126
}
@@ -194,9 +195,11 @@ func (k *KEPHandler) Validate(p *Proposal) []error {
194195
}
195196

196197
type Milestone struct {
197-
Alpha string `json:"alpha" yaml:"alpha"`
198-
Beta string `json:"beta" yaml:"beta"`
199-
Stable string `json:"stable" yaml:"stable"`
198+
Alpha string `json:"alpha" yaml:"alpha"`
199+
Beta string `json:"beta" yaml:"beta"`
200+
Stable string `json:"stable" yaml:"stable"`
201+
Deprecated string `json:"deprecated" yaml:"deprecated,omitempty"`
202+
Removed string `json:"removed" yaml:"removed,omitempty"`
200203
}
201204

202205
type FeatureGate struct {

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@ require (
1818
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
1919
k8s.io/release v0.7.1-0.20210218090651-d71805402dab
2020
k8s.io/test-infra v0.0.0-20200813194141-e9678d500461
21-
sigs.k8s.io/yaml v1.2.0
2221
)

keps/sig-network/2595-expanded-dns-config/kep.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ latest-milestone: "v1.22"
3131
milestone:
3232
alpha: "v1.22"
3333
beta: "x.y"
34-
GA: "x.y"
34+
stable: "x.y"
3535

3636
# The following PRR answers are required at alpha release
3737
# List the feature gate name and the components for which it must be enabled

keps/sig-node/2727-grpc-probe/kep.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ participating-sigs:
99
- sig-network
1010
status: implementable
1111
creation-date: 2020-04-04
12-
modified-date: 2021-05-12
12+
last-updated: 2021-05-12
1313
reviewers:
1414
- "@thockin"
1515
- "@mrunalp"

pkg/output/output.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ import (
2424
"strings"
2525

2626
"github.com/olekukonko/tablewriter"
27-
"gopkg.in/yaml.v3"
2827

2928
"k8s.io/enhancements/api"
29+
"k8s.io/enhancements/pkg/yaml"
3030
)
3131

3232
const (

pkg/repo/repo.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ import (
3030
"github.com/pkg/errors"
3131
"github.com/sirupsen/logrus"
3232
"golang.org/x/oauth2"
33-
"gopkg.in/yaml.v3"
3433

35-
"k8s.io/enhancements/api"
36-
"k8s.io/enhancements/pkg/kepval"
3734
krgh "k8s.io/release/pkg/github"
3835
"k8s.io/test-infra/prow/git"
36+
37+
"k8s.io/enhancements/api"
38+
"k8s.io/enhancements/pkg/kepval"
39+
"k8s.io/enhancements/pkg/yaml"
3940
)
4041

4142
const (
@@ -439,7 +440,7 @@ func (r *Repo) loadKEPFromYaml(kepPath string) (*api.Proposal, error) {
439440
}
440441

441442
var p api.Proposal
442-
err = yaml.Unmarshal(b, &p)
443+
err = yaml.UnmarshalStrict(b, &p)
443444
if err != nil {
444445
return nil, fmt.Errorf("unable to load KEP metadata: %s", err)
445446
}

pkg/repo/repo_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ import (
2424
"testing"
2525

2626
"github.com/stretchr/testify/require"
27-
"gopkg.in/yaml.v3"
27+
"k8s.io/release/pkg/log"
2828

2929
"k8s.io/enhancements/api"
3030
"k8s.io/enhancements/pkg/repo"
31-
"k8s.io/release/pkg/log"
31+
"k8s.io/enhancements/pkg/yaml"
3232
)
3333

3434
var fixture = struct {
@@ -91,7 +91,7 @@ func TestProposalValidate(t *testing.T) {
9191
require.NoError(t, err)
9292

9393
var p api.Proposal
94-
err = yaml.Unmarshal(b, &p)
94+
err = yaml.UnmarshalStrict(b, &p)
9595
require.NoError(t, err)
9696

9797
errs := parser.Validate(&p)

pkg/repo/write.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ import (
2424
"path/filepath"
2525

2626
"github.com/sirupsen/logrus"
27-
"gopkg.in/yaml.v3"
2827
"k8s.io/enhancements/api"
28+
29+
"k8s.io/enhancements/pkg/yaml"
2930
)
3031

3132
func (r *Repo) WriteKEP(kep *api.Proposal) error {

0 commit comments

Comments
 (0)