Skip to content

Commit bc7062d

Browse files
committed
cmd,pkg: Update references to Proposal struct
Signed-off-by: Stephen Augustus <[email protected]>
1 parent f9e1a0e commit bc7062d

File tree

6 files changed

+46
-42
lines changed

6 files changed

+46
-42
lines changed

cmd/kepify/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"path/filepath"
2626
"strings"
2727

28+
"k8s.io/enhancements/api"
2829
"k8s.io/enhancements/pkg/kepval/keps"
2930
)
3031

@@ -104,8 +105,8 @@ func findMarkdownFiles(dirPath *string) ([]string, error) {
104105
return files, err
105106
}
106107

107-
func parseFiles(files []string) (keps.Proposals, error) {
108-
var proposals keps.Proposals
108+
func parseFiles(files []string) (api.Proposals, error) {
109+
var proposals api.Proposals
109110
for _, filename := range files {
110111
parser := &keps.Parser{}
111112
file, err := os.Open(filename)
@@ -124,7 +125,7 @@ func parseFiles(files []string) (keps.Proposals, error) {
124125
return proposals, nil
125126
}
126127

127-
func printJSONOutput(filePath string, proposals keps.Proposals) error {
128+
func printJSONOutput(filePath string, proposals api.Proposals) error {
128129
fmt.Printf("Output file: %s\n", filePath)
129130
file, err := os.Create(filePath)
130131
if err != nil {

pkg/kepctl/create.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"strings"
2626
"time"
2727

28-
"k8s.io/enhancements/pkg/kepval/keps"
28+
"k8s.io/enhancements/api"
2929
)
3030

3131
type CreateOpts struct {
@@ -82,7 +82,7 @@ func (c *Client) Create(opts CreateOpts) error {
8282
return nil
8383
}
8484

85-
func updateTemplate(t *keps.Proposal, opts CreateOpts) {
85+
func updateTemplate(t *api.Proposal, opts CreateOpts) {
8686
if opts.State != "" {
8787
t.Status = opts.State
8888
}
@@ -134,7 +134,7 @@ func updatePersonReference(names []string) []string {
134134
return persons
135135
}
136136

137-
func (c *Client) createKEP(kep *keps.Proposal, opts CreateOpts) error {
137+
func (c *Client) createKEP(kep *api.Proposal, opts CreateOpts) error {
138138

139139
fmt.Fprintf(c.Out, "Generating new KEP %s in %s ===>\n", opts.Name, opts.SIG)
140140

pkg/kepctl/create_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import (
2525

2626
"github.com/stretchr/testify/assert"
2727
"github.com/stretchr/testify/require"
28-
"k8s.io/enhancements/pkg/kepval/keps"
28+
29+
"k8s.io/enhancements/api"
2930
"sigs.k8s.io/yaml"
3031
)
3132

@@ -87,7 +88,7 @@ func TestWriteKep(t *testing.T) {
8788
c := newTestClient(t, repoPath)
8889
b, err := ioutil.ReadFile(tc.kepFile)
8990
require.NoError(t, err)
90-
var p keps.Proposal
91+
var p api.Proposal
9192
err = yaml.Unmarshal(b, &p)
9293
require.NoError(t, err)
9394
tc.opts.CommonArgs.RepoPath = repoPath

pkg/kepctl/kepctl.go

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"golang.org/x/oauth2"
3636
"gopkg.in/yaml.v2"
3737

38+
"k8s.io/enhancements/api"
3839
"k8s.io/enhancements/pkg/kepval/keps"
3940
"k8s.io/test-infra/prow/git"
4041
)
@@ -127,8 +128,8 @@ func (c *Client) SetGitHubToken(opts CommonArgs) error {
127128
// getKepTemplate reads the kep.yaml template from the local
128129
// (per c.RepoPath) k/enhancements, but this could be replaced with a
129130
// template via packr or fetched from Github?
130-
func (c *Client) getKepTemplate(repoPath string) (*keps.Proposal, error) {
131-
var p keps.Proposal
131+
func (c *Client) getKepTemplate(repoPath string) (*api.Proposal, error) {
132+
var p api.Proposal
132133
path := filepath.Join(repoPath, "keps", "NNNN-kep-template", "kep.yaml")
133134
b, err := ioutil.ReadFile(path)
134135
if err != nil {
@@ -148,7 +149,7 @@ func (c *Client) getReadmeTemplate(repoPath string) ([]byte, error) {
148149
return ioutil.ReadFile(path)
149150
}
150151

151-
func validateKEP(p *keps.Proposal) error {
152+
func validateKEP(p *api.Proposal) error {
152153
b, err := yaml.Marshal(p)
153154
if err != nil {
154155
return err
@@ -200,14 +201,14 @@ func findLocalKEPMeta(repoPath, sig string) ([]string, error) {
200201
return keps, err
201202
}
202203

203-
func (c *Client) loadLocalKEPs(repoPath, sig string) ([]*keps.Proposal) {
204+
func (c *Client) loadLocalKEPs(repoPath, sig string) []*api.Proposal {
204205
// KEPs in the local filesystem
205206
files, err := findLocalKEPMeta(repoPath, sig)
206207
if err != nil {
207208
fmt.Fprintf(c.Err, "error searching for local KEPs from %s: %s\n", sig, err)
208209
}
209210

210-
var allKEPs []*keps.Proposal
211+
var allKEPs []*api.Proposal
211212
for _, k := range files {
212213
if filepath.Ext(k) == ".yaml" {
213214
kep, err := c.loadKEPFromYaml(k)
@@ -228,7 +229,7 @@ func (c *Client) loadLocalKEPs(repoPath, sig string) ([]*keps.Proposal) {
228229
return allKEPs
229230
}
230231

231-
func (c *Client) loadKEPPullRequests(sig string) ([]*keps.Proposal, error) {
232+
func (c *Client) loadKEPPullRequests(sig string) ([]*api.Proposal, error) {
232233
var auth *http.Client
233234
ctx := context.Background()
234235
if c.Token != "" {
@@ -280,7 +281,7 @@ func (c *Client) loadKEPPullRequests(sig string) ([]*keps.Proposal, error) {
280281

281282
// read out each PR, and create a Proposal for each KEP that is
282283
// touched by a PR. This may result in multiple versions of the same KEP.
283-
var allKEPs []*keps.Proposal
284+
var allKEPs []*api.Proposal
284285
for _, pr := range kepPRs {
285286
files, _, err := gh.PullRequests.ListFiles(context.Background(), "kubernetes", "enhancements",
286287
pr.GetNumber(), &github.ListOptions{})
@@ -329,7 +330,7 @@ func (c *Client) loadKEPPullRequests(sig string) ([]*keps.Proposal, error) {
329330
return allKEPs, nil
330331
}
331332

332-
func (c *Client) readKEP(repoPath string, sig, name string) (*keps.Proposal, error) {
333+
func (c *Client) readKEP(repoPath string, sig, name string) (*api.Proposal, error) {
333334
kepPath := filepath.Join(
334335
repoPath,
335336
"keps",
@@ -352,12 +353,12 @@ func (c *Client) readKEP(repoPath string, sig, name string) (*keps.Proposal, err
352353
return c.loadKEPFromOldStyle(kepPath)
353354
}
354355

355-
func (c *Client) loadKEPFromYaml(kepPath string) (*keps.Proposal, error) {
356+
func (c *Client) loadKEPFromYaml(kepPath string) (*api.Proposal, error) {
356357
b, err := ioutil.ReadFile(kepPath)
357358
if err != nil {
358359
return nil, fmt.Errorf("unable to read KEP metadata: %s", err)
359360
}
360-
var p keps.Proposal
361+
var p api.Proposal
361362
err = yaml.Unmarshal(b, &p)
362363
if err != nil {
363364
return nil, fmt.Errorf("unable to load KEP metadata: %s", err)
@@ -366,7 +367,7 @@ func (c *Client) loadKEPFromYaml(kepPath string) (*keps.Proposal, error) {
366367
return &p, nil
367368
}
368369

369-
func (c *Client) loadKEPFromOldStyle(kepPath string) (*keps.Proposal, error) {
370+
func (c *Client) loadKEPFromOldStyle(kepPath string) (*api.Proposal, error) {
370371
b, err := ioutil.ReadFile(kepPath)
371372
if err != nil {
372373
return nil, fmt.Errorf("no kep.yaml, but failed to read as old-style KEP: %s", err)
@@ -382,7 +383,7 @@ func (c *Client) loadKEPFromOldStyle(kepPath string) (*keps.Proposal, error) {
382383
return kep, nil
383384
}
384385

385-
func (c *Client) writeKEP(kep *keps.Proposal, opts CommonArgs) error {
386+
func (c *Client) writeKEP(kep *api.Proposal, opts CommonArgs) error {
386387
path, err := c.findEnhancementsRepo(opts)
387388
if err != nil {
388389
return fmt.Errorf("unable to write KEP: %s", err)
@@ -408,39 +409,39 @@ func (c *Client) writeKEP(kep *keps.Proposal, opts CommonArgs) error {
408409

409410
type PrintConfig interface {
410411
Title() string
411-
Value(*keps.Proposal) string
412+
Value(*api.Proposal) string
412413
}
413414

414415
type printConfig struct {
415416
title string
416-
valueFunc func(*keps.Proposal) string
417+
valueFunc func(*api.Proposal) string
417418
}
418419

419420
func (p *printConfig) Title() string { return p.title }
420-
func (p *printConfig) Value(k *keps.Proposal) string {
421+
func (p *printConfig) Value(k *api.Proposal) string {
421422
return p.valueFunc(k)
422423
}
423424

424425
var defaultConfig = map[string]printConfig{
425-
"Authors": {"Authors", func(k *keps.Proposal) string { return strings.Join(k.Authors, ", ") }},
426-
"LastUpdated": {"Updated", func(k *keps.Proposal) string { return k.LastUpdated }},
427-
"SIG": {"SIG", func(k *keps.Proposal) string {
426+
"Authors": {"Authors", func(k *api.Proposal) string { return strings.Join(k.Authors, ", ") }},
427+
"LastUpdated": {"Updated", func(k *api.Proposal) string { return k.LastUpdated }},
428+
"SIG": {"SIG", func(k *api.Proposal) string {
428429
if strings.HasPrefix(k.OwningSIG, "sig-") {
429430
return k.OwningSIG[4:]
430431
} else {
431432
return k.OwningSIG
432433
}
433434
}},
434-
"Stage": {"Stage", func(k *keps.Proposal) string { return k.Stage }},
435-
"Status": {"Status", func(k *keps.Proposal) string { return k.Status }},
436-
"Title": {"Title", func(k *keps.Proposal) string {
435+
"Stage": {"Stage", func(k *api.Proposal) string { return k.Stage }},
436+
"Status": {"Status", func(k *api.Proposal) string { return k.Status }},
437+
"Title": {"Title", func(k *api.Proposal) string {
437438
if k.PRNumber == "" {
438439
return k.Title
439440
} else {
440441
return "PR#" + k.PRNumber + " - " + k.Title
441442
}
442443
}},
443-
"Link": {"Link", func(k *keps.Proposal) string {
444+
"Link": {"Link", func(k *api.Proposal) string {
444445
if k.PRNumber == "" {
445446
return "https://git.k8s.io/enhancements/keps/" + k.OwningSIG + "/" + k.Name
446447
} else {
@@ -459,7 +460,7 @@ func DefaultPrintConfigs(names ...string) []PrintConfig {
459460
return configs
460461
}
461462

462-
func (c *Client) PrintTable(configs []PrintConfig, proposals []*keps.Proposal) {
463+
func (c *Client) PrintTable(configs []PrintConfig, proposals []*api.Proposal) {
463464
if len(configs) == 0 {
464465
return
465466
}
@@ -484,7 +485,7 @@ func (c *Client) PrintTable(configs []PrintConfig, proposals []*keps.Proposal) {
484485
}
485486

486487
// PrintYAML outputs keps array as YAML to c.Out
487-
func (c *Client) PrintYAML(proposals []*keps.Proposal) {
488+
func (c *Client) PrintYAML(proposals []*api.Proposal) {
488489
data, err := yaml.Marshal(proposals)
489490
if err != nil {
490491
fmt.Fprintf(c.Err, "error printing keps as YAML: %s", err)
@@ -495,7 +496,7 @@ func (c *Client) PrintYAML(proposals []*keps.Proposal) {
495496
}
496497

497498
// PrintJSON outputs keps array as YAML to c.Out
498-
func (c *Client) PrintJSON(proposals []*keps.Proposal) {
499+
func (c *Client) PrintJSON(proposals []*api.Proposal) {
499500
data, err := json.Marshal(proposals)
500501
if err != nil {
501502
fmt.Fprintf(c.Err, "error printing keps as JSON: %s", err)

pkg/kepctl/kepctl_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import (
2424
"github.com/stretchr/testify/assert"
2525
"github.com/stretchr/testify/require"
2626
"gopkg.in/yaml.v2"
27-
"k8s.io/enhancements/pkg/kepval/keps"
27+
28+
"k8s.io/enhancements/api"
2829
)
2930

3031
func TestValidate(t *testing.T) {
@@ -49,7 +50,7 @@ func TestValidate(t *testing.T) {
4950
t.Run(tc.name, func(t *testing.T) {
5051
b, err := ioutil.ReadFile(tc.file)
5152
require.NoError(t, err)
52-
var p keps.Proposal
53+
var p api.Proposal
5354
err = yaml.Unmarshal(b, &p)
5455
require.NoError(t, err)
5556
err = validateKEP(&p)

pkg/kepctl/query.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
"github.com/pkg/errors"
2424

25-
"k8s.io/enhancements/pkg/kepval/keps"
25+
"k8s.io/enhancements/api"
2626
"k8s.io/enhancements/pkg/kepval/util"
2727
)
2828

@@ -101,7 +101,7 @@ func (c *Client) Query(opts QueryOpts) error {
101101

102102
c.SetGitHubToken(opts.CommonArgs)
103103

104-
var allKEPs []*keps.Proposal
104+
var allKEPs []*api.Proposal
105105
// load the KEPs for each listed SIG
106106
for _, sig := range opts.SIG {
107107
// KEPs in the local filesystem
@@ -126,7 +126,7 @@ func (c *Client) Query(opts QueryOpts) error {
126126
allowedAuthor := sliceToMap(opts.Author)
127127
allowedApprover := sliceToMap(opts.Approver)
128128

129-
var keep []*keps.Proposal
129+
var keps []*api.Proposal
130130
for _, k := range allKEPs {
131131
if len(opts.Status) > 0 && !allowedStatus[k.Status] {
132132
continue
@@ -143,16 +143,16 @@ func (c *Client) Query(opts QueryOpts) error {
143143
if len(opts.Approver) > 0 && !atLeastOne(k.Approvers, allowedApprover) {
144144
continue
145145
}
146-
keep = append(keep, k)
146+
keps = append(keps, k)
147147
}
148148

149149
switch opts.Output {
150150
case "table":
151-
c.PrintTable(DefaultPrintConfigs("LastUpdated", "Stage", "Status", "SIG", "Authors", "Title", "Link"), keep)
151+
c.PrintTable(DefaultPrintConfigs("LastUpdated", "Stage", "Status", "SIG", "Authors", "Title", "Link"), keps)
152152
case "yaml":
153-
c.PrintYAML(keep)
153+
c.PrintYAML(keps)
154154
case "json":
155-
c.PrintJSON(keep)
155+
c.PrintJSON(keps)
156156
default:
157157
// this check happens as a validation step in cobra as well
158158
// added it for additional verbosity

0 commit comments

Comments
 (0)