Skip to content

Commit f70678f

Browse files
authored
Merge pull request kubernetes#2184 from wojtek-t/new_kep_validation_1
Extend kepval to validate milestones
2 parents 493607c + 24e14ce commit f70678f

File tree

8 files changed

+74
-9
lines changed

8 files changed

+74
-9
lines changed

keps/sig-network/1453-ingress-api/kep.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ latest-milestone: "v1.19"
3030

3131
# The milestone at which this feature was, or is targeted to be, at each stage.
3232
milestone:
33-
alpha: "pre-1.0"
3433
beta: "v1.1"
3534
stable: "v1.19"
3635

keps/sig-node/1898-hardened-exec/kep.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ latest-milestone: "v1.20"
3131
# The milestone at which this feature was, or is targeted to be, at each stage.
3232
milestone:
3333
alpha: "v1.20"
34-
beta: TBD
35-
stable: TBD
3634

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

keps/sig-node/2000-graceful-node-shutdown/kep.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ latest-milestone: "v1.20"
1818
# The milestone at which this feature was, or is targeted to be, at each stage.
1919
milestone:
2020
alpha: "v1.20"
21-
beta: "x.y"
22-
stable: "x.y"
2321

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

keps/sig-node/2040-kubelet-cri/kep.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ latest-milestone: "v1.20"
2727
milestone:
2828
alpha: "v1.5"
2929
beta: "v1.20"
30-
stable: TBD
3130

3231
# The following PRR answers are required at beta release
3332
metrics:

keps/sig-storage/1698-generic-ephemeral-volumes/kep.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ stage: alpha
1515
latest-milestone: "v1.19"
1616
milestone:
1717
alpha: "v1.19"
18-
beta: ""
19-
stable: ""
2018
feature-gates:
2119
- name: GenericEphemeralVolumes
2220
components:

pkg/kepval/keps/proposals.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ type Proposal struct {
7575
DisableSupported bool `json:"disableSupported" yaml:"disable-supported"`
7676
Metrics []string `json:"metrics" yaml:"metrics"`
7777

78-
Filename string `json:"-" yaml:"-"`
7978
Error error `json:"-" yaml:"-"`
8079
Contents string `json:"markdown" yaml:"-"`
8180
}

pkg/kepval/keps/validations/yaml.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var (
3030
reStatus = regexp.MustCompile(strings.Join(statuses, "|"))
3131
stages = []string{"alpha", "beta", "stable"}
3232
reStages = regexp.MustCompile(strings.Join(stages, "|"))
33+
reMilestone = regexp.MustCompile("v1\\.[1-9][0-9]*")
3334
)
3435

3536
func ValidateStructure(parsed map[interface{}]interface{}) error {
@@ -151,6 +152,47 @@ func ValidateStructure(parsed map[interface{}]interface{}) error {
151152
case interface{}:
152153
return util.NewValueMustBeListOfStrings(k, values)
153154
}
155+
case "latest-milestone":
156+
switch v := value.(type) {
157+
case []interface{}:
158+
return util.NewValueMustBeString(k, v)
159+
}
160+
v, _ := value.(string)
161+
if !reMilestone.Match([]byte(v)) {
162+
return util.NewValueMustBeMilestone(k, v)
163+
}
164+
case "milestone":
165+
switch v := value.(type) {
166+
case map[interface{}]interface{}:
167+
if err := validateMilestone(v); err != nil {
168+
return err
169+
}
170+
case interface{}:
171+
return util.NewValueMustBeStruct(k, v)
172+
}
173+
}
174+
}
175+
return nil
176+
}
177+
178+
func validateMilestone(parsed map[interface{}]interface{}) error {
179+
for key, value := range parsed {
180+
// First off the key has to be a string. fact.
181+
k, ok := key.(string)
182+
if !ok {
183+
return util.NewKeyMustBeString(k)
184+
}
185+
186+
switch strings.ToLower(k) {
187+
case "alpha", "beta", "stable":
188+
switch v := value.(type) {
189+
case []interface{}:
190+
return util.NewValueMustBeString(k, v)
191+
}
192+
v, _ := value.(string)
193+
if !reMilestone.Match([]byte(v)) {
194+
return util.NewValueMustBeMilestone(k, v)
195+
}
154196
}
155197
}
156198
return nil

pkg/kepval/util/errors.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,38 @@ func NewValueMustBeString(key string, value interface{}) error {
8181
}
8282
}
8383

84+
type ValueMustBeStruct struct {
85+
key string
86+
value interface{}
87+
}
88+
89+
func (v *ValueMustBeStruct) Error() string {
90+
return fmt.Sprintf("%q must be a struct but it is a %T: %v", v.key, v.value, v.value)
91+
}
92+
93+
func NewValueMustBeStruct(key string, value interface{}) error {
94+
return &ValueMustBeStruct{
95+
key: key,
96+
value: value,
97+
}
98+
}
99+
100+
type ValueMustBeMilestone struct {
101+
key string
102+
value interface{}
103+
}
104+
105+
func (v *ValueMustBeMilestone) Error() string {
106+
return fmt.Sprintf("%q must be a milestone but it is a %T: %v", v.key, v.value, v.value)
107+
}
108+
109+
func NewValueMustBeMilestone(key string, value interface{}) error {
110+
return &ValueMustBeMilestone{
111+
key: key,
112+
value: value,
113+
}
114+
}
115+
84116
type ValueMustBeOneOf struct {
85117
key string
86118
value string

0 commit comments

Comments
 (0)