forked from kubernetes/enhancements
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Merge pull request kubernetes#2425 from justaugustus/refactor…
- Loading branch information
1 parent
fd57a85
commit 8a5c584
Showing
34 changed files
with
869 additions
and
375 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
Copyright 2021 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package api | ||
|
||
import ( | ||
"bufio" | ||
"bytes" | ||
"io" | ||
|
||
"github.com/go-playground/validator/v10" | ||
"github.com/pkg/errors" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
type PRRApprovals []*PRRApproval | ||
|
||
func (p *PRRApprovals) AddPRRApproval(prrApproval *PRRApproval) { | ||
*p = append(*p, prrApproval) | ||
} | ||
|
||
type PRRApproval struct { | ||
Number string `json:"kep-number" yaml:"kep-number"` | ||
Alpha PRRMilestone `json:"alpha" yaml:"alpha,omitempty"` | ||
Beta PRRMilestone `json:"beta" yaml:"beta,omitempty"` | ||
Stable PRRMilestone `json:"stable" yaml:"stable,omitempty"` | ||
|
||
// TODO(api): Move to separate struct for handling document parsing | ||
Error error `json:"-" yaml:"-"` | ||
} | ||
|
||
func (prr *PRRApproval) Validate() error { | ||
v := validator.New() | ||
if err := v.Struct(prr); err != nil { | ||
return errors.Wrap(err, "running validation") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (prr *PRRApproval) ApproverForStage(stage string) string { | ||
switch stage { | ||
case "alpha": | ||
return prr.Alpha.Approver | ||
case "beta": | ||
return prr.Beta.Approver | ||
case "stable": | ||
return prr.Stable.Approver | ||
} | ||
|
||
return "" | ||
} | ||
|
||
// TODO(api): Can we refactor the proposal `Milestone` to retrieve this? | ||
type PRRMilestone struct { | ||
Approver string `json:"approver" yaml:"approver"` | ||
} | ||
|
||
type PRRHandler Parser | ||
|
||
// TODO(api): Make this a generic parser for all `Document` types | ||
func (p *PRRHandler) Parse(in io.Reader) (*PRRApproval, error) { | ||
scanner := bufio.NewScanner(in) | ||
var body bytes.Buffer | ||
for scanner.Scan() { | ||
line := scanner.Text() + "\n" | ||
body.WriteString(line) | ||
} | ||
|
||
approval := &PRRApproval{} | ||
if err := scanner.Err(); err != nil { | ||
return approval, errors.Wrap(err, "reading file") | ||
} | ||
|
||
if err := yaml.Unmarshal(body.Bytes(), &approval); err != nil { | ||
p.Errors = append(p.Errors, errors.Wrap(err, "error unmarshalling YAML")) | ||
return approval, errors.Wrap(err, "unmarshalling YAML") | ||
} | ||
|
||
if valErr := approval.Validate(); valErr != nil { | ||
p.Errors = append(p.Errors, errors.Wrap(valErr, "validating PRR")) | ||
return approval, errors.Wrap(valErr, "validating PRR") | ||
} | ||
|
||
return approval, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
Copyright 2020 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
|
||
"k8s.io/enhancements/pkg/kepctl" | ||
) | ||
|
||
// TODO: Struct literal instead? | ||
var createOpts = kepctl.CreateOpts{} | ||
|
||
var createCmd = &cobra.Command{ | ||
Use: "create [KEP]", | ||
Short: "Create a new KEP", | ||
Long: "Create a new KEP using the current KEP template for the given type", | ||
Example: ` kepctl create sig-architecture/000-mykep`, | ||
SilenceUsage: true, | ||
SilenceErrors: true, | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
return createOpts.Validate(args) | ||
}, | ||
RunE: func(*cobra.Command, []string) error { | ||
return runCreate(createOpts) | ||
}, | ||
} | ||
|
||
func init() { | ||
// TODO: Should these all be global args? | ||
createCmd.PersistentFlags().StringVar( | ||
&createOpts.Title, | ||
"title", | ||
"", | ||
"KEP Title", | ||
) | ||
|
||
createCmd.PersistentFlags().StringArrayVar( | ||
&createOpts.Authors, | ||
"authors", | ||
[]string{}, | ||
"Authors", | ||
) | ||
|
||
createCmd.PersistentFlags().StringArrayVar( | ||
&createOpts.Reviewers, | ||
"reviewers", | ||
[]string{}, | ||
"Reviewers", | ||
) | ||
|
||
createCmd.PersistentFlags().StringVar( | ||
&createOpts.Type, | ||
"type", | ||
"feature", | ||
"KEP Type", | ||
) | ||
|
||
createCmd.PersistentFlags().StringVarP( | ||
&createOpts.State, | ||
"state", | ||
"s", | ||
"provisional", | ||
"KEP State", | ||
) | ||
|
||
createCmd.PersistentFlags().StringArrayVar( | ||
&createOpts.SIGS, | ||
"sigs", | ||
[]string{}, | ||
"Participating SIGs", | ||
) | ||
|
||
createCmd.PersistentFlags().StringArrayVar( | ||
&createOpts.PRRApprovers, | ||
"prr-approver", | ||
[]string{}, | ||
"PRR Approver", | ||
) | ||
|
||
rootCmd.AddCommand(createCmd) | ||
} | ||
|
||
func runCreate(createOpts kepctl.CreateOpts) error { | ||
k, err := kepctl.New(createOpts.RepoPath) | ||
if err != nil { | ||
return errors.Wrap(err, "creating kepctl client") | ||
} | ||
|
||
return k.Create(&createOpts) | ||
} |
Oops, something went wrong.