Skip to content

Commit b6b7028

Browse files
authored
Merge pull request kubernetes#2991 from spiffxp/add-stage-status
api: add Stage and Status types, require more fields
2 parents fe1ab76 + 6ea8d9e commit b6b7028

File tree

23 files changed

+204
-103
lines changed

23 files changed

+204
-103
lines changed

api/approval.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,29 @@ func (prr *PRRApproval) Validate() error {
5454
return nil
5555
}
5656

57-
func (prr *PRRApproval) ApproverForStage(stage string) (string, error) {
58-
isValidStage := IsOneOf(stage, ValidStages)
59-
if !isValidStage {
60-
return "", ErrKEPStageIsInvalid(stage)
57+
func (prr *PRRApproval) ApproverForStage(stage Stage) (string, error) {
58+
if err := stage.IsValid(); err != nil {
59+
return "", err
6160
}
6261

6362
if prr.Alpha == nil && prr.Beta == nil && prr.Stable == nil {
6463
return "", ErrPRRMilestonesAllEmpty
6564
}
6665

6766
switch stage {
68-
case "alpha":
67+
case AlphaStage:
6968
if prr.Alpha == nil {
7069
return "", ErrPRRMilestoneIsNil
7170
}
7271

7372
return prr.Alpha.Approver, nil
74-
case "beta":
73+
case BetaStage:
7574
if prr.Beta == nil {
7675
return "", ErrPRRMilestoneIsNil
7776
}
7877

7978
return prr.Beta.Approver, nil
80-
case "stable":
79+
case StableStage:
8180
if prr.Stable == nil {
8281
return "", ErrPRRMilestoneIsNil
8382
}

api/approval_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var (
4646
func TestPRRApproval_ApproverForStage(t *testing.T) {
4747
testcases := []struct {
4848
name string
49-
stage string
49+
stage api.Stage
5050
prr *api.PRRApproval
5151
wantApprover string
5252
wantErr bool

api/error.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ limitations under the License.
1717
package api
1818

1919
import (
20-
"fmt"
21-
2220
"github.com/pkg/errors"
2321
)
2422

@@ -37,14 +35,3 @@ var (
3735
"an unknown error occurred while trying to determine a PRR approver",
3836
)
3937
)
40-
41-
// KEP errors
42-
func ErrKEPStageIsInvalid(stage string) error {
43-
return errors.New(
44-
fmt.Sprintf(
45-
"the specified stage (%s) should be one of the following: %v",
46-
stage,
47-
ValidStages,
48-
),
49-
)
50-
}

api/proposal.go

Lines changed: 74 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,58 @@ import (
3030
"k8s.io/enhancements/pkg/yaml"
3131
)
3232

33-
var ValidStages = []string{
34-
"alpha",
35-
"beta",
36-
"stable",
33+
type Stage string
34+
35+
const (
36+
AlphaStage Stage = "alpha"
37+
BetaStage Stage = "beta"
38+
StableStage Stage = "stable"
39+
)
40+
41+
var ValidStages = []Stage{
42+
AlphaStage,
43+
BetaStage,
44+
StableStage,
45+
}
46+
47+
func (s Stage) IsValid() error {
48+
for _, s2 := range ValidStages {
49+
if s == s2 {
50+
return nil
51+
}
52+
}
53+
return fmt.Errorf("invalid stage: %v, should be one of %v", s, ValidStages)
54+
}
55+
56+
type Status string
57+
58+
const (
59+
ProvisionalStatus Status = "provisional"
60+
ImplementableStatus Status = "implementable"
61+
ImplementedStatus Status = "implemented"
62+
DeferredStatus Status = "deferred"
63+
RejectedStatus Status = "rejected"
64+
WithdrawnStatus Status = "withdrawn"
65+
ReplacedStatus Status = "replaced"
66+
)
67+
68+
var ValidStatuses = []Status{
69+
ProvisionalStatus,
70+
ImplementableStatus,
71+
ImplementedStatus,
72+
DeferredStatus,
73+
RejectedStatus,
74+
WithdrawnStatus,
75+
ReplacedStatus,
76+
}
77+
78+
func (s Status) IsValid() error {
79+
for _, s2 := range ValidStatuses {
80+
if s == s2 {
81+
return nil
82+
}
83+
}
84+
return fmt.Errorf("invalid status: %v, should be one of %v", s, ValidStatuses)
3785
}
3886

3987
type Proposals []*Proposal
@@ -50,21 +98,21 @@ type Proposal struct {
5098

5199
Title string `json:"title" yaml:"title" validate:"required"`
52100
Number string `json:"kep-number" yaml:"kep-number" validate:"required"`
53-
Authors []string `json:"authors" yaml:",flow"`
101+
Authors []string `json:"authors" yaml:",flow" validate:"required"`
54102
OwningSIG string `json:"owningSig" yaml:"owning-sig" validate:"required"`
55103
ParticipatingSIGs []string `json:"participatingSigs" yaml:"participating-sigs,flow,omitempty"`
56104
Reviewers []string `json:"reviewers" yaml:",flow"`
57-
Approvers []string `json:"approvers" yaml:",flow"`
105+
Approvers []string `json:"approvers" yaml:",flow" validate:"required"`
58106
PRRApprovers []string `json:"prrApprovers" yaml:"prr-approvers,flow"`
59107
Editor string `json:"editor" yaml:"editor,omitempty"`
60108
CreationDate string `json:"creationDate" yaml:"creation-date"`
61109
LastUpdated string `json:"lastUpdated" yaml:"last-updated"`
62-
Status string `json:"status" yaml:"status" validate:"required"`
110+
Status Status `json:"status" yaml:"status" validate:"required"`
63111
SeeAlso []string `json:"seeAlso" yaml:"see-also,omitempty"`
64112
Replaces []string `json:"replaces" yaml:"replaces,omitempty"`
65113
SupersededBy []string `json:"supersededBy" yaml:"superseded-by,omitempty"`
66114

67-
Stage string `json:"stage" yaml:"stage"`
115+
Stage Stage `json:"stage" yaml:"stage"`
68116
LatestMilestone string `json:"latestMilestone" yaml:"latest-milestone"`
69117
Milestone Milestone `json:"milestone" yaml:"milestone"`
70118

@@ -85,6 +133,18 @@ func (p *Proposal) IsMissingStage() bool {
85133
return p.Stage == ""
86134
}
87135

136+
type Milestone struct {
137+
Alpha string `json:"alpha" yaml:"alpha"`
138+
Beta string `json:"beta" yaml:"beta"`
139+
Stable string `json:"stable" yaml:"stable"`
140+
Deprecated string `json:"deprecated" yaml:"deprecated,omitempty"`
141+
Removed string `json:"removed" yaml:"removed,omitempty"`
142+
}
143+
144+
type FeatureGate struct {
145+
Name string `json:"name" yaml:"name"`
146+
Components []string `json:"components" yaml:"components"`
147+
}
88148
type KEPHandler Parser
89149

90150
// TODO(api): Make this a generic parser for all `Document` types
@@ -191,22 +251,15 @@ func (k *KEPHandler) Validate(p *Proposal) []error {
191251
if errs := k.validatePRRApprovers(p); errs != nil {
192252
allErrs = append(allErrs, errs...)
193253
}
254+
if err := p.Status.IsValid(); err != nil {
255+
allErrs = append(allErrs, err)
256+
}
257+
if err := p.Stage.IsValid(); err != nil {
258+
allErrs = append(allErrs, err)
259+
}
194260
return allErrs
195261
}
196262

197-
type Milestone struct {
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"`
203-
}
204-
205-
type FeatureGate struct {
206-
Name string `json:"name" yaml:"name"`
207-
Components []string `json:"components" yaml:"components"`
208-
}
209-
210263
func hash(s string) string {
211264
return fmt.Sprintf("%x", md5.Sum([]byte(s)))
212265
}

keps/sig-network/2449-move-externalDNS-out-of-kubernetes-incubator/kep.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@ title: Move ExternalDNS out of Kubernetes incubator
22
kep-number: 2449
33
authors:
44
- "@njuettner"
5+
approvers:
6+
- bowei
7+
- thockin
58
owning-sig: sig-network
69
status: implemented

keps/sig-scheduling/964-binpacking-priority/kep.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
title: "Extending RequestedToCapacityRatio Priority Function to support Resource Bin Packing of Extended Resources - @sudeshsh"
22
kep-number: 964
33
owning-sig: sig-scheduling
4+
authors:
5+
- sudeshsh
46
participating-sigs:
57
- sig-scheduling
68
reviewers:

pkg/kepctl/commands/create.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/pkg/errors"
2121
"github.com/spf13/cobra"
2222

23+
"k8s.io/enhancements/api"
2324
"k8s.io/enhancements/pkg/proposal"
2425
"k8s.io/enhancements/pkg/repo"
2526
)
@@ -89,7 +90,7 @@ func addCreate(topLevel *cobra.Command) {
8990
&co.State,
9091
"state",
9192
"s",
92-
"provisional",
93+
string(api.ProvisionalStatus),
9394
"KEP State",
9495
)
9596

pkg/kepval/approval.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,10 @@ func ValidatePRR(kep *api.Proposal, h *api.PRRHandler, prrDir string) error {
100100
func isPRRRequired(kep *api.Proposal) (required, missingMilestone, missingStage bool, err error) {
101101
logrus.Debug("checking if PRR is required")
102102

103-
required = true
103+
required = kep.Status == api.ImplementableStatus
104104
missingMilestone = kep.IsMissingMilestone()
105105
missingStage = kep.IsMissingStage()
106106

107-
if kep.Status != "implementable" {
108-
required = false
109-
return required, missingMilestone, missingStage, nil
110-
}
111-
112107
if missingMilestone {
113108
logrus.Warnf("Missing the latest milestone field: %s", kep.Filename)
114109
return required, missingMilestone, missingStage, nil

pkg/output/output.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ func DefaultPrintConfigs(names ...string) []PrintConfig {
210210

211211
return k.OwningSIG
212212
}},
213-
"Stage": {"Stage", func(k *api.Proposal) string { return k.Stage }},
214-
"Status": {"Status", func(k *api.Proposal) string { return k.Status }},
213+
"Stage": {"Stage", func(k *api.Proposal) string { return string(k.Stage) }},
214+
"Status": {"Status", func(k *api.Proposal) string { return string(k.Status) }},
215215
"Title": {"Title", func(k *api.Proposal) string {
216216
if k.PRNumber == "" {
217217
return k.Title

pkg/proposal/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func populateProposal(p *api.Proposal, opts *CreateOpts) {
124124
p.Name = opts.Name
125125

126126
if opts.State != "" {
127-
p.Status = opts.State
127+
p.Status = api.Status(opts.State)
128128
}
129129

130130
now := time.Now()

0 commit comments

Comments
 (0)