Skip to content

Commit adf0318

Browse files
committed
Homogenize all File receivers to f
Signed-off-by: Adrian Orive <[email protected]>
1 parent 03f70fb commit adf0318

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+544
-544
lines changed

pkg/scaffold/project/authproxyrole.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ type AuthProxyRole struct {
3030
}
3131

3232
// GetInput implements input.File
33-
func (r *AuthProxyRole) GetInput() (input.Input, error) {
34-
if r.Path == "" {
35-
r.Path = filepath.Join("config", "rbac", "auth_proxy_role.yaml")
33+
func (f *AuthProxyRole) GetInput() (input.Input, error) {
34+
if f.Path == "" {
35+
f.Path = filepath.Join("config", "rbac", "auth_proxy_role.yaml")
3636
}
37-
r.TemplateBody = proxyRoleTemplate
38-
return r.Input, nil
37+
f.TemplateBody = proxyRoleTemplate
38+
return f.Input, nil
3939
}
4040

4141
const proxyRoleTemplate = `apiVersion: rbac.authorization.k8s.io/v1

pkg/scaffold/project/authproxyrolebinding.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ type AuthProxyRoleBinding struct {
3030
}
3131

3232
// GetInput implements input.File
33-
func (r *AuthProxyRoleBinding) GetInput() (input.Input, error) {
34-
if r.Path == "" {
35-
r.Path = filepath.Join("config", "rbac", "auth_proxy_role_binding.yaml")
33+
func (f *AuthProxyRoleBinding) GetInput() (input.Input, error) {
34+
if f.Path == "" {
35+
f.Path = filepath.Join("config", "rbac", "auth_proxy_role_binding.yaml")
3636
}
37-
r.TemplateBody = proxyRoleBindinggTemplate
38-
return r.Input, nil
37+
f.TemplateBody = proxyRoleBindinggTemplate
38+
return f.Input, nil
3939
}
4040

4141
const proxyRoleBindinggTemplate = `apiVersion: rbac.authorization.k8s.io/v1

pkg/scaffold/project/boilerplate.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,28 @@ type Boilerplate struct {
4141
}
4242

4343
// GetInput implements input.File
44-
func (c *Boilerplate) GetInput() (input.Input, error) {
45-
if c.Path == "" {
46-
c.Path = filepath.Join("hack", "boilerplate.go.txt")
44+
func (f *Boilerplate) GetInput() (input.Input, error) {
45+
if f.Path == "" {
46+
f.Path = filepath.Join("hack", "boilerplate.go.txt")
4747
}
4848

4949
// Boilerplate given
50-
if len(c.Boilerplate) > 0 {
51-
c.TemplateBody = c.Boilerplate
52-
return c.Input, nil
50+
if len(f.Boilerplate) > 0 {
51+
f.TemplateBody = f.Boilerplate
52+
return f.Input, nil
5353
}
5454

5555
// Pick a template boilerplate option
56-
if c.Year == "" {
57-
c.Year = fmt.Sprintf("%v", time.Now().Year())
56+
if f.Year == "" {
57+
f.Year = fmt.Sprintf("%v", time.Now().Year())
5858
}
59-
switch c.License {
59+
switch f.License {
6060
case "", "apache2":
61-
c.TemplateBody = apache
61+
f.TemplateBody = apache
6262
case "none":
63-
c.TemplateBody = none
63+
f.TemplateBody = none
6464
}
65-
return c.Input, nil
65+
return f.Input, nil
6666
}
6767

6868
const apache = `/*

pkg/scaffold/project/gitignore.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ type GitIgnore struct {
2828
}
2929

3030
// GetInput implements input.File
31-
func (c *GitIgnore) GetInput() (input.Input, error) {
32-
if c.Path == "" {
33-
c.Path = ".gitignore"
31+
func (f *GitIgnore) GetInput() (input.Input, error) {
32+
if f.Path == "" {
33+
f.Path = ".gitignore"
3434
}
35-
c.TemplateBody = gitignoreTemplate
36-
return c.Input, nil
35+
f.TemplateBody = gitignoreTemplate
36+
return f.Input, nil
3737
}
3838

3939
const gitignoreTemplate = `

pkg/scaffold/project/gopkg.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -60,40 +60,40 @@ type Stanza struct {
6060
}
6161

6262
// GetInput implements input.File
63-
func (g *GopkgToml) GetInput() (input.Input, error) {
64-
if g.Path == "" {
65-
g.Path = "Gopkg.toml"
63+
func (f *GopkgToml) GetInput() (input.Input, error) {
64+
if f.Path == "" {
65+
f.Path = "Gopkg.toml"
6666
}
67-
if g.ManagedHeader == "" {
68-
g.ManagedHeader = DefaultGopkgHeader
67+
if f.ManagedHeader == "" {
68+
f.ManagedHeader = DefaultGopkgHeader
6969
}
7070

7171
// Set the user content to be used if the Gopkg.toml doesn't exist
72-
if g.DefaultUserContent == "" {
73-
g.DefaultUserContent = DefaultGopkgUserContent
72+
if f.DefaultUserContent == "" {
73+
f.DefaultUserContent = DefaultGopkgUserContent
7474
}
7575

7676
// Set the user owned content from the last Gopkg.toml file - e.g. everything before the header
77-
lastBytes, err := ioutil.ReadFile(g.Path)
77+
lastBytes, err := ioutil.ReadFile(f.Path)
7878
if err != nil {
79-
g.UserContent = g.DefaultUserContent
80-
} else if g.UserContent, err = g.getUserContent(lastBytes); err != nil {
79+
f.UserContent = f.DefaultUserContent
80+
} else if f.UserContent, err = f.getUserContent(lastBytes); err != nil {
8181
return input.Input{}, err
8282
}
8383

84-
g.Input.IfExistsAction = input.Overwrite
85-
g.TemplateBody = depTemplate
86-
return g.Input, nil
84+
f.Input.IfExistsAction = input.Overwrite
85+
f.TemplateBody = depTemplate
86+
return f.Input, nil
8787
}
8888

89-
func (g *GopkgToml) getUserContent(b []byte) (string, error) {
89+
func (f *GopkgToml) getUserContent(b []byte) (string, error) {
9090
// Keep the users lines
9191
scanner := bufio.NewScanner(bytes.NewReader(b))
9292
userLines := []string{}
9393
found := false
9494
for scanner.Scan() {
9595
l := scanner.Text()
96-
if l == g.ManagedHeader {
96+
if l == f.ManagedHeader {
9797
found = true
9898
break
9999
}

pkg/scaffold/project/kustomize.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@ type Kustomize struct {
3535
}
3636

3737
// GetInput implements input.File
38-
func (c *Kustomize) GetInput() (input.Input, error) {
39-
if c.Path == "" {
40-
c.Path = filepath.Join("config", "default", "kustomization.yaml")
38+
func (f *Kustomize) GetInput() (input.Input, error) {
39+
if f.Path == "" {
40+
f.Path = filepath.Join("config", "default", "kustomization.yaml")
4141
}
42-
if c.Prefix == "" {
42+
if f.Prefix == "" {
4343
// use directory name as prefix
4444
dir, err := os.Getwd()
4545
if err != nil {
4646
return input.Input{}, err
4747
}
48-
c.Prefix = strings.ToLower(filepath.Base(dir))
48+
f.Prefix = strings.ToLower(filepath.Base(dir))
4949
}
50-
c.TemplateBody = kustomizeTemplate
51-
c.Input.IfExistsAction = input.Error
52-
return c.Input, nil
50+
f.TemplateBody = kustomizeTemplate
51+
f.Input.IfExistsAction = input.Error
52+
return f.Input, nil
5353
}
5454

5555
const kustomizeTemplate = `# Adds namespace to all resources.

pkg/scaffold/project/kustomize_manager_base.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ type KustomizeManager struct {
3030
}
3131

3232
// GetInput implements input.File
33-
func (c *KustomizeManager) GetInput() (input.Input, error) {
34-
if c.Path == "" {
35-
c.Path = filepath.Join("config", "manager", "kustomization.yaml")
33+
func (f *KustomizeManager) GetInput() (input.Input, error) {
34+
if f.Path == "" {
35+
f.Path = filepath.Join("config", "manager", "kustomization.yaml")
3636
}
37-
c.TemplateBody = kustomizeManagerTemplate
38-
c.Input.IfExistsAction = input.Error
39-
return c.Input, nil
37+
f.TemplateBody = kustomizeManagerTemplate
38+
f.Input.IfExistsAction = input.Error
39+
return f.Input, nil
4040
}
4141

4242
const kustomizeManagerTemplate = `resources:

pkg/scaffold/project/kustomize_rbac_base.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ type KustomizeRBAC struct {
3030
}
3131

3232
// GetInput implements input.File
33-
func (c *KustomizeRBAC) GetInput() (input.Input, error) {
34-
if c.Path == "" {
35-
c.Path = filepath.Join("config", "rbac", "kustomization.yaml")
33+
func (f *KustomizeRBAC) GetInput() (input.Input, error) {
34+
if f.Path == "" {
35+
f.Path = filepath.Join("config", "rbac", "kustomization.yaml")
3636
}
37-
c.TemplateBody = kustomizeRBACTemplate
38-
c.Input.IfExistsAction = input.Error
39-
return c.Input, nil
37+
f.TemplateBody = kustomizeRBACTemplate
38+
f.Input.IfExistsAction = input.Error
39+
return f.Input, nil
4040
}
4141

4242
const kustomizeRBACTemplate = `resources:

pkg/scaffold/project/makefile.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ type Makefile struct {
3333
}
3434

3535
// GetInput implements input.File
36-
func (c *Makefile) GetInput() (input.Input, error) {
37-
if c.Path == "" {
38-
c.Path = "Makefile"
36+
func (f *Makefile) GetInput() (input.Input, error) {
37+
if f.Path == "" {
38+
f.Path = "Makefile"
3939
}
40-
if c.Image == "" {
41-
c.Image = "controller:latest"
40+
if f.Image == "" {
41+
f.Image = "controller:latest"
4242
}
43-
if c.ControllerToolsPath == "" {
44-
c.ControllerToolsPath = "vendor/sigs.k8s.io/controller-tools"
43+
if f.ControllerToolsPath == "" {
44+
f.ControllerToolsPath = "vendor/sigs.k8s.io/controller-tools"
4545
}
46-
c.TemplateBody = makefileTemplate
47-
c.Input.IfExistsAction = input.Error
48-
return c.Input, nil
46+
f.TemplateBody = makefileTemplate
47+
f.Input.IfExistsAction = input.Error
48+
return f.Input, nil
4949
}
5050

5151
const makefileTemplate = `

pkg/scaffold/project/project.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,28 @@ type Project struct {
4040
}
4141

4242
// GetInput implements input.File
43-
func (c *Project) GetInput() (input.Input, error) {
44-
if c.Path == "" {
45-
c.Path = "PROJECT"
43+
func (f *Project) GetInput() (input.Input, error) {
44+
if f.Path == "" {
45+
f.Path = "PROJECT"
4646
}
47-
if c.Version == "" {
48-
c.Version = Version1
47+
if f.Version == "" {
48+
f.Version = Version1
4949
}
50-
if c.Repo == "" {
50+
if f.Repo == "" {
5151
return input.Input{}, fmt.Errorf("must specify repository")
5252
}
5353

54-
out, err := yaml.Marshal(c.ProjectFile)
54+
out, err := yaml.Marshal(f.ProjectFile)
5555
if err != nil {
5656
return input.Input{}, err
5757
}
5858

5959
return input.Input{
60-
Path: c.Path,
60+
Path: f.Path,
6161
TemplateBody: string(out),
62-
Repo: c.Repo,
63-
Version: c.Version,
64-
Domain: c.Domain,
62+
Repo: f.Repo,
63+
Version: f.Version,
64+
Domain: f.Domain,
6565
IfExistsAction: input.Error,
6666
}, nil
6767
}

pkg/scaffold/v1/authproxyservice.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ type AuthProxyService struct {
3030
}
3131

3232
// GetInput implements input.File
33-
func (r *AuthProxyService) GetInput() (input.Input, error) {
34-
if r.Path == "" {
35-
r.Path = filepath.Join("config", "rbac", "auth_proxy_service.yaml")
33+
func (f *AuthProxyService) GetInput() (input.Input, error) {
34+
if f.Path == "" {
35+
f.Path = filepath.Join("config", "rbac", "auth_proxy_service.yaml")
3636
}
37-
r.TemplateBody = AuthProxyServiceTemplate
38-
return r.Input, nil
37+
f.TemplateBody = AuthProxyServiceTemplate
38+
return f.Input, nil
3939
}
4040

4141
const AuthProxyServiceTemplate = `apiVersion: v1

pkg/scaffold/v1/controller/add.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ type AddController struct {
3636
}
3737

3838
// GetInput implements input.File
39-
func (a *AddController) GetInput() (input.Input, error) {
40-
if a.Path == "" {
41-
a.Path = filepath.Join("pkg", "controller", fmt.Sprintf(
42-
"add_%s.go", strings.ToLower(a.Resource.Kind)))
39+
func (f *AddController) GetInput() (input.Input, error) {
40+
if f.Path == "" {
41+
f.Path = filepath.Join("pkg", "controller", fmt.Sprintf(
42+
"add_%s.go", strings.ToLower(f.Resource.Kind)))
4343
}
44-
a.TemplateBody = addControllerTemplate
45-
return a.Input, nil
44+
f.TemplateBody = addControllerTemplate
45+
return f.Input, nil
4646
}
4747

4848
const addControllerTemplate = `{{ .Boilerplate }}

pkg/scaffold/v1/controller/controller.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type Controller struct {
4646
}
4747

4848
// GetInput implements input.File
49-
func (a *Controller) GetInput() (input.Input, error) {
49+
func (f *Controller) GetInput() (input.Input, error) {
5050
// Use the k8s.io/api package for core resources
5151
coreGroups := map[string]string{
5252
"apps": "",
@@ -64,20 +64,20 @@ func (a *Controller) GetInput() (input.Input, error) {
6464
"storage": "k8s.io",
6565
}
6666

67-
a.ResourcePackage, a.GroupDomain = getResourceInfo(coreGroups, a.Resource, a.Input)
67+
f.ResourcePackage, f.GroupDomain = getResourceInfo(coreGroups, f.Resource, f.Input)
6868

69-
if a.Plural == "" {
70-
a.Plural = flect.Pluralize(strings.ToLower(a.Resource.Kind))
69+
if f.Plural == "" {
70+
f.Plural = flect.Pluralize(strings.ToLower(f.Resource.Kind))
7171
}
7272

73-
if a.Path == "" {
74-
a.Path = filepath.Join("pkg", "controller",
75-
strings.ToLower(a.Resource.Kind),
76-
strings.ToLower(a.Resource.Kind)+"_controller.go")
73+
if f.Path == "" {
74+
f.Path = filepath.Join("pkg", "controller",
75+
strings.ToLower(f.Resource.Kind),
76+
strings.ToLower(f.Resource.Kind)+"_controller.go")
7777
}
78-
a.TemplateBody = controllerTemplate
79-
a.Input.IfExistsAction = input.Error
80-
return a.Input, nil
78+
f.TemplateBody = controllerTemplate
79+
f.Input.IfExistsAction = input.Error
80+
return f.Input, nil
8181
}
8282

8383
func getResourceInfo(coreGroups map[string]string, r *resource.Resource, in input.Input) (resourcePackage, groupDomain string) {

pkg/scaffold/v1/controller/controllersuitetest.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ type SuiteTest struct {
3333
}
3434

3535
// GetInput implements input.File
36-
func (a *SuiteTest) GetInput() (input.Input, error) {
37-
if a.Path == "" {
38-
a.Path = filepath.Join("pkg", "controller",
39-
strings.ToLower(a.Resource.Kind), strings.ToLower(a.Resource.Kind)+"_controller_suite_test.go")
36+
func (f *SuiteTest) GetInput() (input.Input, error) {
37+
if f.Path == "" {
38+
f.Path = filepath.Join("pkg", "controller",
39+
strings.ToLower(f.Resource.Kind), strings.ToLower(f.Resource.Kind)+"_controller_suite_test.go")
4040
}
41-
a.TemplateBody = controllerSuiteTestTemplate
42-
return a.Input, nil
41+
f.TemplateBody = controllerSuiteTestTemplate
42+
return f.Input, nil
4343
}
4444

4545
const controllerSuiteTestTemplate = `{{ .Boilerplate }}

0 commit comments

Comments
 (0)