From cf7d2fb7851c4f86211c1c8cdb5f1ee3479dbb49 Mon Sep 17 00:00:00 2001 From: John Belamaric Date: Mon, 1 Feb 2021 12:01:52 -0800 Subject: [PATCH] Look at PRR approval request when querying KEPs --- pkg/kepctl/kepctl.go | 35 +++++++++++++++++++++++++++++++++++ pkg/kepval/prrs/approvals.go | 14 +++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/pkg/kepctl/kepctl.go b/pkg/kepctl/kepctl.go index 17d2cf60dd3..d77fa3580a9 100644 --- a/pkg/kepctl/kepctl.go +++ b/pkg/kepctl/kepctl.go @@ -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" ) @@ -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 } diff --git a/pkg/kepval/prrs/approvals.go b/pkg/kepval/prrs/approvals.go index 59eb6d6caa5..6dde640e8c5 100644 --- a/pkg/kepval/prrs/approvals.go +++ b/pkg/kepval/prrs/approvals.go @@ -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{} @@ -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 "" +}