Skip to content

Commit

Permalink
Homogenize all File receivers to f
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Orive <[email protected]>
  • Loading branch information
Adirio committed Nov 26, 2019
1 parent 03f70fb commit 20f2f7d
Show file tree
Hide file tree
Showing 71 changed files with 530 additions and 530 deletions.
10 changes: 5 additions & 5 deletions pkg/scaffold/project/authproxyrole.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ type AuthProxyRole struct {
}

// GetInput implements input.File
func (r *AuthProxyRole) GetInput() (input.Input, error) {
if r.Path == "" {
r.Path = filepath.Join("config", "rbac", "auth_proxy_role.yaml")
func (f *AuthProxyRole) GetInput() (input.Input, error) {
if f.Path == "" {
f.Path = filepath.Join("config", "rbac", "auth_proxy_role.yaml")
}
r.TemplateBody = proxyRoleTemplate
return r.Input, nil
f.TemplateBody = proxyRoleTemplate
return f.Input, nil
}

const proxyRoleTemplate = `apiVersion: rbac.authorization.k8s.io/v1
Expand Down
10 changes: 5 additions & 5 deletions pkg/scaffold/project/authproxyrolebinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ type AuthProxyRoleBinding struct {
}

// GetInput implements input.File
func (r *AuthProxyRoleBinding) GetInput() (input.Input, error) {
if r.Path == "" {
r.Path = filepath.Join("config", "rbac", "auth_proxy_role_binding.yaml")
func (f *AuthProxyRoleBinding) GetInput() (input.Input, error) {
if f.Path == "" {
f.Path = filepath.Join("config", "rbac", "auth_proxy_role_binding.yaml")
}
r.TemplateBody = proxyRoleBindinggTemplate
return r.Input, nil
f.TemplateBody = proxyRoleBindinggTemplate
return f.Input, nil
}

const proxyRoleBindinggTemplate = `apiVersion: rbac.authorization.k8s.io/v1
Expand Down
24 changes: 12 additions & 12 deletions pkg/scaffold/project/boilerplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,28 @@ type Boilerplate struct {
}

// GetInput implements input.File
func (c *Boilerplate) GetInput() (input.Input, error) {
if c.Path == "" {
c.Path = filepath.Join("hack", "boilerplate.go.txt")
func (f *Boilerplate) GetInput() (input.Input, error) {
if f.Path == "" {
f.Path = filepath.Join("hack", "boilerplate.go.txt")
}

// Boilerplate given
if len(c.Boilerplate) > 0 {
c.TemplateBody = c.Boilerplate
return c.Input, nil
if len(f.Boilerplate) > 0 {
f.TemplateBody = f.Boilerplate
return f.Input, nil
}

// Pick a template boilerplate option
if c.Year == "" {
c.Year = fmt.Sprintf("%v", time.Now().Year())
if f.Year == "" {
f.Year = fmt.Sprintf("%v", time.Now().Year())
}
switch c.License {
switch f.License {
case "", "apache2":
c.TemplateBody = apache
f.TemplateBody = apache
case "none":
c.TemplateBody = none
f.TemplateBody = none
}
return c.Input, nil
return f.Input, nil
}

const apache = `/*
Expand Down
10 changes: 5 additions & 5 deletions pkg/scaffold/project/gitignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ type GitIgnore struct {
}

// GetInput implements input.File
func (c *GitIgnore) GetInput() (input.Input, error) {
if c.Path == "" {
c.Path = ".gitignore"
func (f *GitIgnore) GetInput() (input.Input, error) {
if f.Path == "" {
f.Path = ".gitignore"
}
c.TemplateBody = gitignoreTemplate
return c.Input, nil
f.TemplateBody = gitignoreTemplate
return f.Input, nil
}

const gitignoreTemplate = `
Expand Down
30 changes: 15 additions & 15 deletions pkg/scaffold/project/gopkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,40 +60,40 @@ type Stanza struct {
}

// GetInput implements input.File
func (g *GopkgToml) GetInput() (input.Input, error) {
if g.Path == "" {
g.Path = "Gopkg.toml"
func (f *GopkgToml) GetInput() (input.Input, error) {
if f.Path == "" {
f.Path = "Gopkg.toml"
}
if g.ManagedHeader == "" {
g.ManagedHeader = DefaultGopkgHeader
if f.ManagedHeader == "" {
f.ManagedHeader = DefaultGopkgHeader
}

// Set the user content to be used if the Gopkg.toml doesn't exist
if g.DefaultUserContent == "" {
g.DefaultUserContent = DefaultGopkgUserContent
if f.DefaultUserContent == "" {
f.DefaultUserContent = DefaultGopkgUserContent
}

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

g.Input.IfExistsAction = input.Overwrite
g.TemplateBody = depTemplate
return g.Input, nil
f.Input.IfExistsAction = input.Overwrite
f.TemplateBody = depTemplate
return f.Input, nil
}

func (g *GopkgToml) getUserContent(b []byte) (string, error) {
func (f *GopkgToml) getUserContent(b []byte) (string, error) {
// Keep the users lines
scanner := bufio.NewScanner(bytes.NewReader(b))
userLines := []string{}
found := false
for scanner.Scan() {
l := scanner.Text()
if l == g.ManagedHeader {
if l == f.ManagedHeader {
found = true
break
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/scaffold/project/kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ type Kustomize struct {
}

// GetInput implements input.File
func (c *Kustomize) GetInput() (input.Input, error) {
if c.Path == "" {
c.Path = filepath.Join("config", "default", "kustomization.yaml")
func (f *Kustomize) GetInput() (input.Input, error) {
if f.Path == "" {
f.Path = filepath.Join("config", "default", "kustomization.yaml")
}
if c.Prefix == "" {
if f.Prefix == "" {
// use directory name as prefix
dir, err := os.Getwd()
if err != nil {
return input.Input{}, err
}
c.Prefix = strings.ToLower(filepath.Base(dir))
f.Prefix = strings.ToLower(filepath.Base(dir))
}
c.TemplateBody = kustomizeTemplate
c.Input.IfExistsAction = input.Error
return c.Input, nil
f.TemplateBody = kustomizeTemplate
f.Input.IfExistsAction = input.Error
return f.Input, nil
}

const kustomizeTemplate = `# Adds namespace to all resources.
Expand Down
12 changes: 6 additions & 6 deletions pkg/scaffold/project/kustomize_manager_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ type KustomizeManager struct {
}

// GetInput implements input.File
func (c *KustomizeManager) GetInput() (input.Input, error) {
if c.Path == "" {
c.Path = filepath.Join("config", "manager", "kustomization.yaml")
func (f *KustomizeManager) GetInput() (input.Input, error) {
if f.Path == "" {
f.Path = filepath.Join("config", "manager", "kustomization.yaml")
}
c.TemplateBody = kustomizeManagerTemplate
c.Input.IfExistsAction = input.Error
return c.Input, nil
f.TemplateBody = kustomizeManagerTemplate
f.Input.IfExistsAction = input.Error
return f.Input, nil
}

const kustomizeManagerTemplate = `resources:
Expand Down
12 changes: 6 additions & 6 deletions pkg/scaffold/project/kustomize_rbac_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ type KustomizeRBAC struct {
}

// GetInput implements input.File
func (c *KustomizeRBAC) GetInput() (input.Input, error) {
if c.Path == "" {
c.Path = filepath.Join("config", "rbac", "kustomization.yaml")
func (f *KustomizeRBAC) GetInput() (input.Input, error) {
if f.Path == "" {
f.Path = filepath.Join("config", "rbac", "kustomization.yaml")
}
c.TemplateBody = kustomizeRBACTemplate
c.Input.IfExistsAction = input.Error
return c.Input, nil
f.TemplateBody = kustomizeRBACTemplate
f.Input.IfExistsAction = input.Error
return f.Input, nil
}

const kustomizeRBACTemplate = `resources:
Expand Down
20 changes: 10 additions & 10 deletions pkg/scaffold/project/makefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ type Makefile struct {
}

// GetInput implements input.File
func (c *Makefile) GetInput() (input.Input, error) {
if c.Path == "" {
c.Path = "Makefile"
func (f *Makefile) GetInput() (input.Input, error) {
if f.Path == "" {
f.Path = "Makefile"
}
if c.Image == "" {
c.Image = "controller:latest"
if f.Image == "" {
f.Image = "controller:latest"
}
if c.ControllerToolsPath == "" {
c.ControllerToolsPath = "vendor/sigs.k8s.io/controller-tools"
if f.ControllerToolsPath == "" {
f.ControllerToolsPath = "vendor/sigs.k8s.io/controller-tools"
}
c.TemplateBody = makefileTemplate
c.Input.IfExistsAction = input.Error
return c.Input, nil
f.TemplateBody = makefileTemplate
f.Input.IfExistsAction = input.Error
return f.Input, nil
}

const makefileTemplate = `
Expand Down
22 changes: 11 additions & 11 deletions pkg/scaffold/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,28 @@ type Project struct {
}

// GetInput implements input.File
func (c *Project) GetInput() (input.Input, error) {
if c.Path == "" {
c.Path = "PROJECT"
func (f *Project) GetInput() (input.Input, error) {
if f.Path == "" {
f.Path = "PROJECT"
}
if c.Version == "" {
c.Version = Version1
if f.Version == "" {
f.Version = Version1
}
if c.Repo == "" {
if f.Repo == "" {
return input.Input{}, fmt.Errorf("must specify repository")
}

out, err := yaml.Marshal(c.ProjectFile)
out, err := yaml.Marshal(f.ProjectFile)
if err != nil {
return input.Input{}, err
}

return input.Input{
Path: c.Path,
Path: f.Path,
TemplateBody: string(out),
Repo: c.Repo,
Version: c.Version,
Domain: c.Domain,
Repo: f.Repo,
Version: f.Version,
Domain: f.Domain,
IfExistsAction: input.Error,
}, nil
}
10 changes: 5 additions & 5 deletions pkg/scaffold/v1/authproxyservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ type AuthProxyService struct {
}

// GetInput implements input.File
func (r *AuthProxyService) GetInput() (input.Input, error) {
if r.Path == "" {
r.Path = filepath.Join("config", "rbac", "auth_proxy_service.yaml")
func (f *AuthProxyService) GetInput() (input.Input, error) {
if f.Path == "" {
f.Path = filepath.Join("config", "rbac", "auth_proxy_service.yaml")
}
r.TemplateBody = AuthProxyServiceTemplate
return r.Input, nil
f.TemplateBody = AuthProxyServiceTemplate
return f.Input, nil
}

const AuthProxyServiceTemplate = `apiVersion: v1
Expand Down
12 changes: 6 additions & 6 deletions pkg/scaffold/v1/controller/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ type AddController struct {
}

// GetInput implements input.File
func (a *AddController) GetInput() (input.Input, error) {
if a.Path == "" {
a.Path = filepath.Join("pkg", "controller", fmt.Sprintf(
"add_%s.go", strings.ToLower(a.Resource.Kind)))
func (f *AddController) GetInput() (input.Input, error) {
if f.Path == "" {
f.Path = filepath.Join("pkg", "controller", fmt.Sprintf(
"add_%s.go", strings.ToLower(f.Resource.Kind)))
}
a.TemplateBody = addControllerTemplate
return a.Input, nil
f.TemplateBody = addControllerTemplate
return f.Input, nil
}

const addControllerTemplate = `{{ .Boilerplate }}
Expand Down
22 changes: 11 additions & 11 deletions pkg/scaffold/v1/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type Controller struct {
}

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

a.ResourcePackage, a.GroupDomain = getResourceInfo(coreGroups, a.Resource, a.Input)
f.ResourcePackage, f.GroupDomain = getResourceInfo(coreGroups, f.Resource, f.Input)

if a.Plural == "" {
a.Plural = flect.Pluralize(strings.ToLower(a.Resource.Kind))
if f.Plural == "" {
f.Plural = flect.Pluralize(strings.ToLower(f.Resource.Kind))
}

if a.Path == "" {
a.Path = filepath.Join("pkg", "controller",
strings.ToLower(a.Resource.Kind),
strings.ToLower(a.Resource.Kind)+"_controller.go")
if f.Path == "" {
f.Path = filepath.Join("pkg", "controller",
strings.ToLower(f.Resource.Kind),
strings.ToLower(f.Resource.Kind)+"_controller.go")
}
a.TemplateBody = controllerTemplate
a.Input.IfExistsAction = input.Error
return a.Input, nil
f.TemplateBody = controllerTemplate
f.Input.IfExistsAction = input.Error
return f.Input, nil
}

func getResourceInfo(coreGroups map[string]string, r *resource.Resource, in input.Input) (resourcePackage, groupDomain string) {
Expand Down
12 changes: 6 additions & 6 deletions pkg/scaffold/v1/controller/controllersuitetest.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ type SuiteTest struct {
}

// GetInput implements input.File
func (a *SuiteTest) GetInput() (input.Input, error) {
if a.Path == "" {
a.Path = filepath.Join("pkg", "controller",
strings.ToLower(a.Resource.Kind), strings.ToLower(a.Resource.Kind)+"_controller_suite_test.go")
func (f *SuiteTest) GetInput() (input.Input, error) {
if f.Path == "" {
f.Path = filepath.Join("pkg", "controller",
strings.ToLower(f.Resource.Kind), strings.ToLower(f.Resource.Kind)+"_controller_suite_test.go")
}
a.TemplateBody = controllerSuiteTestTemplate
return a.Input, nil
f.TemplateBody = controllerSuiteTestTemplate
return f.Input, nil
}

const controllerSuiteTestTemplate = `{{ .Boilerplate }}
Expand Down
Loading

0 comments on commit 20f2f7d

Please sign in to comment.