Skip to content

Commit dfd76be

Browse files
committed
pkg/repo: Make PRR validation errors non-blocking when querying
Signed-off-by: Stephen Augustus <[email protected]>
1 parent 523604d commit dfd76be

File tree

4 files changed

+50
-46
lines changed

4 files changed

+50
-46
lines changed

pkg/proposal/create.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type CreateOpts struct {
5454
// kep # and name to populate the create opts
5555
func (c *CreateOpts) Validate(args []string) error {
5656
// TODO: Populate logic
57+
// nolint:gocritic
5758
/*
5859
err := repoOpts.ValidateAndPopulateKEP(args)
5960
if err != nil {

pkg/proposal/promote.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ type PromoteOpts struct {
3939
// Validate checks the args provided to the promote command populates the promote opts
4040
func (o *PromoteOpts) Validate(args []string) error {
4141
// TODO: Populate logic
42-
return nil //o.Repo.ValidateAndPopulateKEP(args)
42+
// nolint:gocritic
43+
return nil // o.Repo.ValidateAndPopulateKEP(args)
4344
}
4445

4546
// Promote changes the stage and target release for a specified KEP based on the

pkg/repo/repo.go

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"gopkg.in/yaml.v3"
3636

3737
"k8s.io/enhancements/api"
38+
"k8s.io/enhancements/pkg/kepval"
3839
krgh "k8s.io/release/pkg/github"
3940
"k8s.io/test-infra/prow/git"
4041
)
@@ -264,9 +265,9 @@ func (r *Repo) LoadLocalKEPs(sig string) ([]*api.Proposal, error) {
264265
"reading KEP %s from yaml",
265266
k,
266267
)
267-
} else {
268-
allKEPs = append(allKEPs, kep)
269268
}
269+
270+
allKEPs = append(allKEPs, kep)
270271
} else {
271272
kep, err := r.loadKEPFromOldStyle(k)
272273
if err != nil {
@@ -275,9 +276,9 @@ func (r *Repo) LoadLocalKEPs(sig string) ([]*api.Proposal, error) {
275276
"reading KEP %s from markdown",
276277
k,
277278
)
278-
} else {
279-
allKEPs = append(allKEPs, kep)
280279
}
280+
281+
allKEPs = append(allKEPs, kep)
281282
}
282283
}
283284

@@ -458,54 +459,55 @@ func (r *Repo) loadKEPFromYaml(kepPath string) (*api.Proposal, error) {
458459
// Read the PRR approval file and add any listed PRR approvers in there
459460
// to the PRR approvers list in the KEP. this is a hack while we transition
460461
// away from PRR approvers listed in kep.yaml
461-
prrPath := filepath.Dir(kepPath)
462-
prrPath = filepath.Dir(prrPath)
463-
sig := filepath.Base(prrPath)
464-
prrPath = filepath.Join(
465-
filepath.Dir(prrPath),
466-
PRRApprovalPathStub,
467-
sig,
468-
p.Number+".yaml",
469-
)
470-
471-
prrFile, err := os.Open(prrPath)
472-
if os.IsNotExist(err) {
473-
return &p, nil
474-
}
475-
462+
handler := r.PRRHandler
463+
err = kepval.ValidatePRR(&p, handler, r.PRRApprovalPath)
476464
if err != nil {
477-
return nil, errors.Wrapf(err, "opening PRR approval %s", prrPath)
478-
}
465+
logrus.Errorf(
466+
"%v",
467+
errors.Wrapf(err, "validating PRR for %s", p.Name),
468+
)
469+
} else {
470+
prrPath := filepath.Dir(kepPath)
471+
prrPath = filepath.Dir(prrPath)
472+
sig := filepath.Base(prrPath)
473+
prrPath = filepath.Join(
474+
filepath.Dir(prrPath),
475+
PRRApprovalPathStub,
476+
sig,
477+
p.Number+".yaml",
478+
)
479479

480-
handler := r.PRRHandler
480+
prrFile, err := os.Open(prrPath)
481+
if os.IsNotExist(err) {
482+
return &p, nil
483+
}
481484

482-
approval, err := handler.Parse(prrFile)
483-
if err != nil {
484-
return nil, errors.Wrapf(err, "parsing PRR")
485-
}
485+
if err != nil {
486+
return nil, errors.Wrapf(err, "opening PRR approval %s", prrPath)
487+
}
486488

487-
if approval.Error != nil {
488-
fmt.Fprintf(
489-
r.Err,
490-
"WARNING: could not parse prod readiness request for KEP %s: %s\n",
491-
p.Number,
492-
approval.Error,
493-
)
494-
}
489+
approval, err := handler.Parse(prrFile)
490+
if err != nil {
491+
return nil, errors.Wrapf(err, "parsing PRR")
492+
}
495493

496-
approver, err := approval.ApproverForStage(p.Stage)
497-
if err != nil {
498-
return nil, errors.Wrapf(err, "getting PRR approver for %s stage", p.Stage)
499-
}
494+
approver, err := approval.ApproverForStage(p.Stage)
495+
if err != nil {
496+
logrus.Errorf(
497+
"%v",
498+
errors.Wrapf(err, "getting PRR approver for %s stage", p.Stage),
499+
)
500+
}
500501

501-
for _, a := range p.PRRApprovers {
502-
if a == approver {
503-
approver = ""
502+
for _, a := range p.PRRApprovers {
503+
if a == approver {
504+
approver = ""
505+
}
504506
}
505-
}
506507

507-
if approver != "" {
508-
p.PRRApprovers = append(p.PRRApprovers, approver)
508+
if approver != "" {
509+
p.PRRApprovers = append(p.PRRApprovers, approver)
510+
}
509511
}
510512

511513
return &p, nil

pkg/repo/validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (r *Repo) Validate() (
3838
err error,
3939
) {
4040
kepDir := r.ProposalPath
41-
var files = []string{}
41+
files := []string{}
4242

4343
// Find all the KEPs
4444
err = filepath.Walk(

0 commit comments

Comments
 (0)