Skip to content

Commit 5d6d935

Browse files
authored
Merge pull request kubernetes#2397 from johnbelamaric/query-prr-request-file
Look at PRR approval request when querying KEPs
2 parents cc54049 + cf7d2fb commit 5d6d935

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

pkg/kepctl/kepctl.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737

3838
"k8s.io/enhancements/api"
3939
"k8s.io/enhancements/pkg/kepval/keps"
40+
"k8s.io/enhancements/pkg/kepval/prrs"
4041
"k8s.io/test-infra/prow/git"
4142
)
4243

@@ -373,6 +374,40 @@ func (c *Client) loadKEPFromYaml(kepPath string) (*api.Proposal, error) {
373374
return nil, fmt.Errorf("unable to load KEP metadata: %s", err)
374375
}
375376
p.Name = filepath.Base(filepath.Dir(kepPath))
377+
378+
// Read the PRR approval file and add any listed PRR approvers in there
379+
// to the PRR approvers list in the KEP. this is a hack while we transition
380+
// away from PRR approvers listed in kep.yaml
381+
prrPath := filepath.Dir(kepPath)
382+
prrPath = filepath.Dir(prrPath)
383+
sig := filepath.Base(prrPath)
384+
prrPath = filepath.Join(filepath.Dir(prrPath),
385+
"prod-readiness",
386+
sig,
387+
p.Number+".yaml")
388+
prrFile, err := os.Open(prrPath)
389+
if os.IsNotExist(err) {
390+
return &p, nil
391+
}
392+
if err != nil {
393+
return nil, fmt.Errorf("could not open file %s: %v\n", prrPath, err)
394+
}
395+
396+
parser := &prrs.Parser{}
397+
approval := parser.Parse(prrFile)
398+
if approval.Error != nil {
399+
fmt.Fprintf(c.Err, "WARNING: could not parse prod readiness request for KEP %s: %s\n", p.Number, approval.Error)
400+
}
401+
402+
approver := approval.ApproverForStage(p.Stage)
403+
for _, a := range p.PRRApprovers {
404+
if a == approver {
405+
approver = ""
406+
}
407+
}
408+
if approver != "" {
409+
p.PRRApprovers = append(p.PRRApprovers, approver)
410+
}
376411
return &p, nil
377412
}
378413

pkg/kepval/prrs/approvals.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type Approval struct {
4242
Beta Milestone `json:"beta" yaml:"beta"`
4343
Stable Milestone `json:"stable" yaml:"stable"`
4444

45-
Error error `json:"-" yaml:"-"`
45+
Error error `json:"-" yaml:"-"`
4646
}
4747

4848
type Parser struct{}
@@ -75,3 +75,15 @@ func (p *Parser) Parse(in io.Reader) *Approval {
7575
approval.Error = yaml.UnmarshalStrict(body.Bytes(), approval)
7676
return approval
7777
}
78+
79+
func (a *Approval) ApproverForStage(stage string) string {
80+
switch stage {
81+
case "alpha":
82+
return a.Alpha.Approver
83+
case "beta":
84+
return a.Beta.Approver
85+
case "stable":
86+
return a.Stable.Approver
87+
}
88+
return ""
89+
}

0 commit comments

Comments
 (0)