Skip to content

Commit

Permalink
Merge pull request #2397 from johnbelamaric/query-prr-request-file
Browse files Browse the repository at this point in the history
Look at PRR approval request when querying KEPs
  • Loading branch information
k8s-ci-robot committed Feb 2, 2021
2 parents cc54049 + cf7d2fb commit 5d6d935
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
35 changes: 35 additions & 0 deletions pkg/kepctl/kepctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (

"k8s.io/enhancements/api"
"k8s.io/enhancements/pkg/kepval/keps"
"k8s.io/enhancements/pkg/kepval/prrs"
"k8s.io/test-infra/prow/git"
)

Expand Down Expand Up @@ -373,6 +374,40 @@ func (c *Client) loadKEPFromYaml(kepPath string) (*api.Proposal, error) {
return nil, fmt.Errorf("unable to load KEP metadata: %s", err)
}
p.Name = filepath.Base(filepath.Dir(kepPath))

// Read the PRR approval file and add any listed PRR approvers in there
// to the PRR approvers list in the KEP. this is a hack while we transition
// away from PRR approvers listed in kep.yaml
prrPath := filepath.Dir(kepPath)
prrPath = filepath.Dir(prrPath)
sig := filepath.Base(prrPath)
prrPath = filepath.Join(filepath.Dir(prrPath),
"prod-readiness",
sig,
p.Number+".yaml")
prrFile, err := os.Open(prrPath)
if os.IsNotExist(err) {
return &p, nil
}
if err != nil {
return nil, fmt.Errorf("could not open file %s: %v\n", prrPath, err)
}

parser := &prrs.Parser{}
approval := parser.Parse(prrFile)
if approval.Error != nil {
fmt.Fprintf(c.Err, "WARNING: could not parse prod readiness request for KEP %s: %s\n", p.Number, approval.Error)
}

approver := approval.ApproverForStage(p.Stage)
for _, a := range p.PRRApprovers {
if a == approver {
approver = ""
}
}
if approver != "" {
p.PRRApprovers = append(p.PRRApprovers, approver)
}
return &p, nil
}

Expand Down
14 changes: 13 additions & 1 deletion pkg/kepval/prrs/approvals.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Approval struct {
Beta Milestone `json:"beta" yaml:"beta"`
Stable Milestone `json:"stable" yaml:"stable"`

Error error `json:"-" yaml:"-"`
Error error `json:"-" yaml:"-"`
}

type Parser struct{}
Expand Down Expand Up @@ -75,3 +75,15 @@ func (p *Parser) Parse(in io.Reader) *Approval {
approval.Error = yaml.UnmarshalStrict(body.Bytes(), approval)
return approval
}

func (a *Approval) ApproverForStage(stage string) string {
switch stage {
case "alpha":
return a.Alpha.Approver
case "beta":
return a.Beta.Approver
case "stable":
return a.Stable.Approver
}
return ""
}

0 comments on commit 5d6d935

Please sign in to comment.