diff --git a/pkg/scaffold/project/authproxyrole.go b/pkg/scaffold/project/authproxyrole.go index 2cd0593899b..c7cd36f2634 100644 --- a/pkg/scaffold/project/authproxyrole.go +++ b/pkg/scaffold/project/authproxyrole.go @@ -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 diff --git a/pkg/scaffold/project/authproxyrolebinding.go b/pkg/scaffold/project/authproxyrolebinding.go index d62433df2b7..7b84c1f5b90 100644 --- a/pkg/scaffold/project/authproxyrolebinding.go +++ b/pkg/scaffold/project/authproxyrolebinding.go @@ -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 diff --git a/pkg/scaffold/project/boilerplate.go b/pkg/scaffold/project/boilerplate.go index e4205ebd1cb..38bca3e6d5b 100644 --- a/pkg/scaffold/project/boilerplate.go +++ b/pkg/scaffold/project/boilerplate.go @@ -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 = `/* diff --git a/pkg/scaffold/project/gitignore.go b/pkg/scaffold/project/gitignore.go index ac9d8555e30..fe3390a52bb 100644 --- a/pkg/scaffold/project/gitignore.go +++ b/pkg/scaffold/project/gitignore.go @@ -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 = ` diff --git a/pkg/scaffold/project/gopkg.go b/pkg/scaffold/project/gopkg.go index 6ec1a649a2a..7f68cee0d27 100644 --- a/pkg/scaffold/project/gopkg.go +++ b/pkg/scaffold/project/gopkg.go @@ -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 } diff --git a/pkg/scaffold/project/kustomize.go b/pkg/scaffold/project/kustomize.go index d7afd2cc72f..aee64b20665 100644 --- a/pkg/scaffold/project/kustomize.go +++ b/pkg/scaffold/project/kustomize.go @@ -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. diff --git a/pkg/scaffold/project/kustomize_manager_base.go b/pkg/scaffold/project/kustomize_manager_base.go index aef819bed9f..fea6ba95cd9 100644 --- a/pkg/scaffold/project/kustomize_manager_base.go +++ b/pkg/scaffold/project/kustomize_manager_base.go @@ -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: diff --git a/pkg/scaffold/project/kustomize_rbac_base.go b/pkg/scaffold/project/kustomize_rbac_base.go index 0e532ad475d..1dcd9ae3fd0 100644 --- a/pkg/scaffold/project/kustomize_rbac_base.go +++ b/pkg/scaffold/project/kustomize_rbac_base.go @@ -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: diff --git a/pkg/scaffold/project/makefile.go b/pkg/scaffold/project/makefile.go index 3996a5fdb13..8943abf88f6 100644 --- a/pkg/scaffold/project/makefile.go +++ b/pkg/scaffold/project/makefile.go @@ -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 = ` diff --git a/pkg/scaffold/project/project.go b/pkg/scaffold/project/project.go index 4a706bdcc55..fc57f82f78f 100644 --- a/pkg/scaffold/project/project.go +++ b/pkg/scaffold/project/project.go @@ -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 } diff --git a/pkg/scaffold/v1/authproxyservice.go b/pkg/scaffold/v1/authproxyservice.go index 63debdf3fca..efcc2979d08 100644 --- a/pkg/scaffold/v1/authproxyservice.go +++ b/pkg/scaffold/v1/authproxyservice.go @@ -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 diff --git a/pkg/scaffold/v1/controller/add.go b/pkg/scaffold/v1/controller/add.go index 38b8d50574f..577a1d8ec2f 100644 --- a/pkg/scaffold/v1/controller/add.go +++ b/pkg/scaffold/v1/controller/add.go @@ -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 }} diff --git a/pkg/scaffold/v1/controller/controller.go b/pkg/scaffold/v1/controller/controller.go index bb4ce630d17..9776e0414fb 100644 --- a/pkg/scaffold/v1/controller/controller.go +++ b/pkg/scaffold/v1/controller/controller.go @@ -47,7 +47,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": "", @@ -65,20 +65,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) { diff --git a/pkg/scaffold/v1/controller/controllersuitetest.go b/pkg/scaffold/v1/controller/controllersuitetest.go index c7881bbd4aa..d52a03590b6 100644 --- a/pkg/scaffold/v1/controller/controllersuitetest.go +++ b/pkg/scaffold/v1/controller/controllersuitetest.go @@ -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 }} diff --git a/pkg/scaffold/v1/controller/controllertest.go b/pkg/scaffold/v1/controller/controllertest.go index 2742a1a40c5..495311d8e67 100644 --- a/pkg/scaffold/v1/controller/controllertest.go +++ b/pkg/scaffold/v1/controller/controllertest.go @@ -36,10 +36,10 @@ type Test struct { } // GetInput implements input.File -func (a *Test) GetInput() (input.Input, error) { - if a.Path == "" { - a.Path = filepath.Join("pkg", "controller", - strings.ToLower(a.Resource.Kind), strings.ToLower(a.Resource.Kind)+"_controller_test.go") +func (f *Test) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("pkg", "controller", + strings.ToLower(f.Resource.Kind), strings.ToLower(f.Resource.Kind)+"_controller_test.go") } // Use the k8s.io/api package for core resources @@ -59,11 +59,11 @@ func (a *Test) GetInput() (input.Input, error) { "storage": "k8s.io", } - a.ResourcePackage, _ = getResourceInfo(coreGroups, a.Resource, a.Input) + f.ResourcePackage, _ = getResourceInfo(coreGroups, f.Resource, f.Input) - a.TemplateBody = controllerTestTemplate - a.Input.IfExistsAction = input.Error - return a.Input, nil + f.TemplateBody = controllerTestTemplate + f.Input.IfExistsAction = input.Error + return f.Input, nil } const controllerTestTemplate = `{{ .Boilerplate }} diff --git a/pkg/scaffold/v1/crd/addtoscheme.go b/pkg/scaffold/v1/crd/addtoscheme.go index bdcdd02d636..aa19e282b5e 100644 --- a/pkg/scaffold/v1/crd/addtoscheme.go +++ b/pkg/scaffold/v1/crd/addtoscheme.go @@ -35,18 +35,18 @@ type AddToScheme struct { } // GetInput implements input.File -func (a *AddToScheme) GetInput() (input.Input, error) { - if a.Path == "" { - a.Path = filepath.Join("pkg", "apis", fmt.Sprintf( - "addtoscheme_%s_%s.go", a.Resource.Group, a.Resource.Version)) +func (f *AddToScheme) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("pkg", "apis", fmt.Sprintf( + "addtoscheme_%s_%s.go", f.Resource.Group, f.Resource.Version)) } - a.TemplateBody = addResourceTemplate - return a.Input, nil + f.TemplateBody = addResourceTemplate + return f.Input, nil } // Validate validates the values -func (a *AddToScheme) Validate() error { - return a.Resource.Validate() +func (f *AddToScheme) Validate() error { + return f.Resource.Validate() } // NB(directxman12): we need that package alias on the API import otherwise imports.Process diff --git a/pkg/scaffold/v1/crd/crd_sample.go b/pkg/scaffold/v1/crd/crd_sample.go index 850a22b12e2..65621bd2882 100644 --- a/pkg/scaffold/v1/crd/crd_sample.go +++ b/pkg/scaffold/v1/crd/crd_sample.go @@ -36,20 +36,20 @@ type CRDSample struct { } // GetInput implements input.File -func (c *CRDSample) GetInput() (input.Input, error) { - if c.Path == "" { - c.Path = filepath.Join("config", "samples", fmt.Sprintf( - "%s_%s_%s.yaml", c.Resource.Group, c.Resource.Version, strings.ToLower(c.Resource.Kind))) +func (f *CRDSample) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("config", "samples", fmt.Sprintf( + "%s_%s_%s.yaml", f.Resource.Group, f.Resource.Version, strings.ToLower(f.Resource.Kind))) } - c.IfExistsAction = input.Error - c.TemplateBody = crdSampleTemplate - return c.Input, nil + f.IfExistsAction = input.Error + f.TemplateBody = crdSampleTemplate + return f.Input, nil } // Validate validates the values -func (c *CRDSample) Validate() error { - return c.Resource.Validate() +func (f *CRDSample) Validate() error { + return f.Resource.Validate() } const crdSampleTemplate = `apiVersion: {{ .Resource.Group }}.{{ .Domain }}/{{ .Resource.Version }} diff --git a/pkg/scaffold/v1/crd/doc.go b/pkg/scaffold/v1/crd/doc.go index 5394aae652a..de57754ec8b 100644 --- a/pkg/scaffold/v1/crd/doc.go +++ b/pkg/scaffold/v1/crd/doc.go @@ -34,17 +34,17 @@ type Doc struct { } // GetInput implements input.File -func (a *Doc) GetInput() (input.Input, error) { - if a.Path == "" { - a.Path = filepath.Join("pkg", "apis", a.Resource.Group, a.Resource.Version, "doc.go") +func (f *Doc) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("pkg", "apis", f.Resource.Group, f.Resource.Version, "doc.go") } - a.TemplateBody = docGoTemplate - return a.Input, nil + f.TemplateBody = docGoTemplate + return f.Input, nil } // Validate validates the values -func (a *Doc) Validate() error { - return a.Resource.Validate() +func (f *Doc) Validate() error { + return f.Resource.Validate() } const docGoTemplate = `{{ .Boilerplate }} diff --git a/pkg/scaffold/v1/crd/group.go b/pkg/scaffold/v1/crd/group.go index ebc4513e0dd..5324dd5a2de 100644 --- a/pkg/scaffold/v1/crd/group.go +++ b/pkg/scaffold/v1/crd/group.go @@ -34,17 +34,17 @@ type Group struct { } // GetInput implements input.File -func (g *Group) GetInput() (input.Input, error) { - if g.Path == "" { - g.Path = filepath.Join("pkg", "apis", g.Resource.Group, "group.go") +func (f *Group) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("pkg", "apis", f.Resource.Group, "group.go") } - g.TemplateBody = groupTemplate - return g.Input, nil + f.TemplateBody = groupTemplate + return f.Input, nil } // Validate validates the values -func (g *Group) Validate() error { - return g.Resource.Validate() +func (f *Group) Validate() error { + return f.Resource.Validate() } const groupTemplate = `{{ .Boilerplate }} diff --git a/pkg/scaffold/v1/crd/register.go b/pkg/scaffold/v1/crd/register.go index 97e6332a458..9880bab0f45 100644 --- a/pkg/scaffold/v1/crd/register.go +++ b/pkg/scaffold/v1/crd/register.go @@ -34,17 +34,17 @@ type Register struct { } // GetInput implements input.File -func (r *Register) GetInput() (input.Input, error) { - if r.Path == "" { - r.Path = filepath.Join("pkg", "apis", r.Resource.Group, r.Resource.Version, "register.go") +func (f *Register) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("pkg", "apis", f.Resource.Group, f.Resource.Version, "register.go") } - r.TemplateBody = registerTemplate - return r.Input, nil + f.TemplateBody = registerTemplate + return f.Input, nil } // Validate validates the values -func (r *Register) Validate() error { - return r.Resource.Validate() +func (f *Register) Validate() error { + return f.Resource.Validate() } const registerTemplate = `{{ .Boilerplate }} diff --git a/pkg/scaffold/v1/crd/types.go b/pkg/scaffold/v1/crd/types.go index 2b3fe6f4269..40a6995ec8c 100644 --- a/pkg/scaffold/v1/crd/types.go +++ b/pkg/scaffold/v1/crd/types.go @@ -36,19 +36,19 @@ type Types struct { } // GetInput implements input.File -func (t *Types) GetInput() (input.Input, error) { - if t.Path == "" { - t.Path = filepath.Join("pkg", "apis", t.Resource.GroupImportSafe, t.Resource.Version, - fmt.Sprintf("%s_types.go", strings.ToLower(t.Resource.Kind))) +func (f *Types) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("pkg", "apis", f.Resource.GroupImportSafe, f.Resource.Version, + fmt.Sprintf("%s_types.go", strings.ToLower(f.Resource.Kind))) } - t.TemplateBody = typesTemplate - t.IfExistsAction = input.Error - return t.Input, nil + f.TemplateBody = typesTemplate + f.IfExistsAction = input.Error + return f.Input, nil } // Validate validates the values -func (t *Types) Validate() error { - return t.Resource.Validate() +func (f *Types) Validate() error { + return f.Resource.Validate() } const typesTemplate = `{{ .Boilerplate }} diff --git a/pkg/scaffold/v1/crd/typestest.go b/pkg/scaffold/v1/crd/typestest.go index 35a56f4c4b6..a899fa75686 100644 --- a/pkg/scaffold/v1/crd/typestest.go +++ b/pkg/scaffold/v1/crd/typestest.go @@ -36,19 +36,19 @@ type TypesTest struct { } // GetInput implements input.File -func (t *TypesTest) GetInput() (input.Input, error) { - if t.Path == "" { - t.Path = filepath.Join("pkg", "apis", t.Resource.Group, t.Resource.Version, - fmt.Sprintf("%s_types_test.go", strings.ToLower(t.Resource.Kind))) +func (f *TypesTest) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("pkg", "apis", f.Resource.Group, f.Resource.Version, + fmt.Sprintf("%s_types_test.go", strings.ToLower(f.Resource.Kind))) } - t.TemplateBody = typesTestTemplate - t.IfExistsAction = input.Error - return t.Input, nil + f.TemplateBody = typesTestTemplate + f.IfExistsAction = input.Error + return f.Input, nil } // Validate validates the values -func (t *TypesTest) Validate() error { - return t.Resource.Validate() +func (f *TypesTest) Validate() error { + return f.Resource.Validate() } const typesTestTemplate = `{{ .Boilerplate }} diff --git a/pkg/scaffold/v1/crd/version_suitetest.go b/pkg/scaffold/v1/crd/version_suitetest.go index 4639e4dc836..247ea0c579e 100644 --- a/pkg/scaffold/v1/crd/version_suitetest.go +++ b/pkg/scaffold/v1/crd/version_suitetest.go @@ -35,18 +35,18 @@ type VersionSuiteTest struct { } // GetInput implements input.File -func (v *VersionSuiteTest) GetInput() (input.Input, error) { - if v.Path == "" { - v.Path = filepath.Join("pkg", "apis", v.Resource.GroupImportSafe, v.Resource.Version, - fmt.Sprintf("%s_suite_test.go", v.Resource.Version)) +func (f *VersionSuiteTest) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("pkg", "apis", f.Resource.GroupImportSafe, f.Resource.Version, + fmt.Sprintf("%s_suite_test.go", f.Resource.Version)) } - v.TemplateBody = versionSuiteTestTemplate - return v.Input, nil + f.TemplateBody = versionSuiteTestTemplate + return f.Input, nil } // Validate validates the values -func (v *VersionSuiteTest) Validate() error { - return v.Resource.Validate() +func (f *VersionSuiteTest) Validate() error { + return f.Resource.Validate() } const versionSuiteTestTemplate = `{{ .Boilerplate }} diff --git a/pkg/scaffold/v1/kustomize_image_patch.go b/pkg/scaffold/v1/kustomize_image_patch.go index 8853ce26806..21f4c1f8580 100644 --- a/pkg/scaffold/v1/kustomize_image_patch.go +++ b/pkg/scaffold/v1/kustomize_image_patch.go @@ -34,16 +34,16 @@ type KustomizeImagePatch struct { } // GetInput implements input.File -func (c *KustomizeImagePatch) GetInput() (input.Input, error) { - if c.Path == "" { - c.Path = filepath.Join("config", "default", "manager_image_patch.yaml") +func (f *KustomizeImagePatch) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("config", "default", "manager_image_patch.yaml") } - if c.ImageURL == "" { - c.ImageURL = "IMAGE_URL" + if f.ImageURL == "" { + f.ImageURL = "IMAGE_URL" } - c.TemplateBody = kustomizeImagePatchTemplate - c.Input.IfExistsAction = input.Error - return c.Input, nil + f.TemplateBody = kustomizeImagePatchTemplate + f.Input.IfExistsAction = input.Error + return f.Input, nil } const kustomizeImagePatchTemplate = `apiVersion: apps/v1 diff --git a/pkg/scaffold/v1/manager/apis.go b/pkg/scaffold/v1/manager/apis.go index 3fa6adad449..899889283a0 100644 --- a/pkg/scaffold/v1/manager/apis.go +++ b/pkg/scaffold/v1/manager/apis.go @@ -41,21 +41,21 @@ var deepCopy = strings.Join([]string{ "-i ./..."}, " ") // GetInput implements input.File -func (a *APIs) GetInput() (input.Input, error) { - if a.Path == "" { - a.Path = filepath.Join("pkg", "apis", "apis.go") +func (f *APIs) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("pkg", "apis", "apis.go") } - b, err := filepath.Rel(filepath.Join(a.Input.ProjectPath, "pkg", "apis"), a.BoilerplatePath) + relPath, err := filepath.Rel(filepath.Join(f.Input.ProjectPath, "pkg", "apis"), f.BoilerplatePath) if err != nil { return input.Input{}, err } - if len(a.Comments) == 0 { - a.Comments = append(a.Comments, - "// Generate deepcopy for apis", fmt.Sprintf("%s -h %s", deepCopy, filepath.ToSlash(b))) + if len(f.Comments) == 0 { + f.Comments = append(f.Comments, + "// Generate deepcopy for apis", fmt.Sprintf("%s -h %s", deepCopy, filepath.ToSlash(relPath))) } - a.TemplateBody = apisTemplate - return a.Input, nil + f.TemplateBody = apisTemplate + return f.Input, nil } const apisTemplate = `{{ .Boilerplate }} diff --git a/pkg/scaffold/v1/manager/cmd.go b/pkg/scaffold/v1/manager/cmd.go index dbd339215b4..ff55ae27d1b 100644 --- a/pkg/scaffold/v1/manager/cmd.go +++ b/pkg/scaffold/v1/manager/cmd.go @@ -30,12 +30,12 @@ type Cmd struct { } // GetInput implements input.File -func (a *Cmd) GetInput() (input.Input, error) { - if a.Path == "" { - a.Path = filepath.Join("cmd", "manager", "main.go") +func (f *Cmd) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("cmd", "manager", "main.go") } - a.TemplateBody = cmdTemplate - return a.Input, nil + f.TemplateBody = cmdTemplate + return f.Input, nil } const cmdTemplate = `{{ .Boilerplate }} diff --git a/pkg/scaffold/v1/manager/config.go b/pkg/scaffold/v1/manager/config.go index aea2c8d96ef..d98f092e212 100644 --- a/pkg/scaffold/v1/manager/config.go +++ b/pkg/scaffold/v1/manager/config.go @@ -32,12 +32,12 @@ type Config struct { } // GetInput implements input.File -func (c *Config) GetInput() (input.Input, error) { - if c.Path == "" { - c.Path = filepath.Join("config", "manager", "manager.yaml") +func (f *Config) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("config", "manager", "manager.yaml") } - c.TemplateBody = configTemplate - return c.Input, nil + f.TemplateBody = configTemplate + return f.Input, nil } const configTemplate = `apiVersion: v1 diff --git a/pkg/scaffold/v1/manager/controller.go b/pkg/scaffold/v1/manager/controller.go index cecb0ab969d..a16e3a7fa55 100644 --- a/pkg/scaffold/v1/manager/controller.go +++ b/pkg/scaffold/v1/manager/controller.go @@ -30,12 +30,12 @@ type Controller struct { } // GetInput implements input.File -func (c *Controller) GetInput() (input.Input, error) { - if c.Path == "" { - c.Path = filepath.Join("pkg", "controller", "controller.go") +func (f *Controller) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("pkg", "controller", "controller.go") } - c.TemplateBody = controllerTemplate - return c.Input, nil + f.TemplateBody = controllerTemplate + return f.Input, nil } const controllerTemplate = `{{ .Boilerplate }} diff --git a/pkg/scaffold/v1/manager/dockerfile.go b/pkg/scaffold/v1/manager/dockerfile.go index c90c60e0d10..d111dd4fc2e 100644 --- a/pkg/scaffold/v1/manager/dockerfile.go +++ b/pkg/scaffold/v1/manager/dockerfile.go @@ -28,12 +28,12 @@ type Dockerfile struct { } // GetInput implements input.File -func (c *Dockerfile) GetInput() (input.Input, error) { - if c.Path == "" { - c.Path = "Dockerfile" +func (f *Dockerfile) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = "Dockerfile" } - c.TemplateBody = dockerfileTemplate - return c.Input, nil + f.TemplateBody = dockerfileTemplate + return f.Input, nil } const dockerfileTemplate = `# Build the manager binary diff --git a/pkg/scaffold/v1/manager/webhook.go b/pkg/scaffold/v1/manager/webhook.go index 8dff92cbfae..b0c9b06dff7 100644 --- a/pkg/scaffold/v1/manager/webhook.go +++ b/pkg/scaffold/v1/manager/webhook.go @@ -30,12 +30,12 @@ type Webhook struct { } // GetInput implements input.File -func (c *Webhook) GetInput() (input.Input, error) { - if c.Path == "" { - c.Path = filepath.Join("pkg", "webhook", "webhook.go") +func (f *Webhook) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("pkg", "webhook", "webhook.go") } - c.TemplateBody = webhookTemplate - return c.Input, nil + f.TemplateBody = webhookTemplate + return f.Input, nil } const webhookTemplate = `{{ .Boilerplate }} diff --git a/pkg/scaffold/v1/metricsauth/kustomize_auth_proxy_patch.go b/pkg/scaffold/v1/metricsauth/kustomize_auth_proxy_patch.go index 1a7b59d415b..c21ccb7f710 100644 --- a/pkg/scaffold/v1/metricsauth/kustomize_auth_proxy_patch.go +++ b/pkg/scaffold/v1/metricsauth/kustomize_auth_proxy_patch.go @@ -31,13 +31,13 @@ type KustomizeAuthProxyPatch struct { } // GetInput implements input.File -func (c *KustomizeAuthProxyPatch) GetInput() (input.Input, error) { - if c.Path == "" { - c.Path = filepath.Join("config", "default", "manager_auth_proxy_patch.yaml") +func (f *KustomizeAuthProxyPatch) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("config", "default", "manager_auth_proxy_patch.yaml") } - c.TemplateBody = kustomizeAuthProxyPatchTemplate - c.Input.IfExistsAction = input.Error - return c.Input, nil + f.TemplateBody = kustomizeAuthProxyPatchTemplate + f.Input.IfExistsAction = input.Error + return f.Input, nil } const kustomizeAuthProxyPatchTemplate = `# This patch inject a sidecar container which is a HTTP proxy for the controller manager, diff --git a/pkg/scaffold/v1/metricsauth/kustomize_metrics_patch.go b/pkg/scaffold/v1/metricsauth/kustomize_metrics_patch.go index f217c576291..3df55c30d81 100644 --- a/pkg/scaffold/v1/metricsauth/kustomize_metrics_patch.go +++ b/pkg/scaffold/v1/metricsauth/kustomize_metrics_patch.go @@ -31,13 +31,13 @@ type KustomizePrometheusMetricsPatch struct { } // GetInput implements input.File -func (c *KustomizePrometheusMetricsPatch) GetInput() (input.Input, error) { - if c.Path == "" { - c.Path = filepath.Join("config", "default", "manager_prometheus_metrics_patch.yaml") +func (f *KustomizePrometheusMetricsPatch) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("config", "default", "manager_prometheus_metrics_patch.yaml") } - c.TemplateBody = kustomizePrometheusMetricsPatchTemplate - c.Input.IfExistsAction = input.Error - return c.Input, nil + f.TemplateBody = kustomizePrometheusMetricsPatchTemplate + f.Input.IfExistsAction = input.Error + return f.Input, nil } const kustomizePrometheusMetricsPatchTemplate = `# This patch enables Prometheus scraping for the manager pod. diff --git a/pkg/scaffold/v1/webhook/add_admissionbuilder_handler.go b/pkg/scaffold/v1/webhook/add_admissionbuilder_handler.go index 9bb9dbf3e44..a7d1bacd8cd 100644 --- a/pkg/scaffold/v1/webhook/add_admissionbuilder_handler.go +++ b/pkg/scaffold/v1/webhook/add_admissionbuilder_handler.go @@ -38,15 +38,15 @@ type AddAdmissionWebhookBuilderHandler struct { } // GetInput implements input.File -func (a *AddAdmissionWebhookBuilderHandler) GetInput() (input.Input, error) { - a.Server = strings.ToLower(a.Server) - if a.Path == "" { - a.Path = filepath.Join("pkg", "webhook", - fmt.Sprintf("%s_server", a.Server), - fmt.Sprintf("add_%s_%s.go", a.Type, strings.ToLower(a.Resource.Kind))) +func (f *AddAdmissionWebhookBuilderHandler) GetInput() (input.Input, error) { + f.Server = strings.ToLower(f.Server) + if f.Path == "" { + f.Path = filepath.Join("pkg", "webhook", + fmt.Sprintf("%s_server", f.Server), + fmt.Sprintf("add_%s_%s.go", f.Type, strings.ToLower(f.Resource.Kind))) } - a.TemplateBody = addAdmissionWebhookBuilderHandlerTemplate - return a.Input, nil + f.TemplateBody = addAdmissionWebhookBuilderHandlerTemplate + return f.Input, nil } const addAdmissionWebhookBuilderHandlerTemplate = `{{ .Boilerplate }} diff --git a/pkg/scaffold/v1/webhook/add_server.go b/pkg/scaffold/v1/webhook/add_server.go index ddb4a7e9e0b..f8c69789db3 100644 --- a/pkg/scaffold/v1/webhook/add_server.go +++ b/pkg/scaffold/v1/webhook/add_server.go @@ -33,12 +33,12 @@ type AddServer struct { } // GetInput implements input.File -func (a *AddServer) GetInput() (input.Input, error) { - if a.Path == "" { - a.Path = filepath.Join("pkg", "webhook", fmt.Sprintf("add_%s_server.go", a.Server)) +func (f *AddServer) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("pkg", "webhook", fmt.Sprintf("add_%s_server.go", f.Server)) } - a.TemplateBody = addServerTemplate - return a.Input, nil + f.TemplateBody = addServerTemplate + return f.Input, nil } const addServerTemplate = `{{ .Boilerplate }} diff --git a/pkg/scaffold/v1/webhook/admissionbuilder.go b/pkg/scaffold/v1/webhook/admissionbuilder.go index be91f14ffdc..1696c615b0c 100644 --- a/pkg/scaffold/v1/webhook/admissionbuilder.go +++ b/pkg/scaffold/v1/webhook/admissionbuilder.go @@ -47,29 +47,29 @@ type AdmissionWebhookBuilder struct { } // GetInput implements input.File -func (a *AdmissionWebhookBuilder) GetInput() (input.Input, error) { - a.ResourcePackage = getResourceInfo(coreGroups, a.Resource, a.Input) +func (f *AdmissionWebhookBuilder) GetInput() (input.Input, error) { + f.ResourcePackage = getResourceInfo(coreGroups, f.Resource, f.Input) - if a.Type == "mutating" { - a.Mutating = true + if f.Type == "mutating" { + f.Mutating = true } - a.Type = strings.ToLower(a.Type) - a.BuilderName = builderName(a.Config, strings.ToLower(a.Resource.Kind)) - ops := make([]string, len(a.Operations)) - for i, op := range a.Operations { + f.Type = strings.ToLower(f.Type) + f.BuilderName = builderName(f.Config, strings.ToLower(f.Resource.Kind)) + ops := make([]string, len(f.Operations)) + for i, op := range f.Operations { ops[i] = "admissionregistrationv1beta1." + strings.Title(op) } - a.OperationsParameterString = strings.Join(ops, ", ") - - if a.Path == "" { - a.Path = filepath.Join("pkg", "webhook", - fmt.Sprintf("%s_server", a.Server), - strings.ToLower(a.Resource.Kind), - a.Type, - fmt.Sprintf("%s_webhook.go", strings.Join(a.Operations, "_"))) + f.OperationsParameterString = strings.Join(ops, ", ") + + if f.Path == "" { + f.Path = filepath.Join("pkg", "webhook", + fmt.Sprintf("%s_server", f.Server), + strings.ToLower(f.Resource.Kind), + f.Type, + fmt.Sprintf("%s_webhook.go", strings.Join(f.Operations, "_"))) } - a.TemplateBody = admissionWebhookBuilderTemplate - return a.Input, nil + f.TemplateBody = admissionWebhookBuilderTemplate + return f.Input, nil } const admissionWebhookBuilderTemplate = `{{ .Boilerplate }} diff --git a/pkg/scaffold/v1/webhook/admissionhandler.go b/pkg/scaffold/v1/webhook/admissionhandler.go index 783f437f7de..9ecd1c20d8b 100644 --- a/pkg/scaffold/v1/webhook/admissionhandler.go +++ b/pkg/scaffold/v1/webhook/admissionhandler.go @@ -47,28 +47,28 @@ type AdmissionHandler struct { } // GetInput implements input.File -func (a *AdmissionHandler) GetInput() (input.Input, error) { - a.ResourcePackage = getResourceInfo(coreGroups, a.Resource, a.Input) - a.Type = strings.ToLower(a.Type) - if a.Type == "mutating" { - a.Mutate = true +func (f *AdmissionHandler) GetInput() (input.Input, error) { + f.ResourcePackage = getResourceInfo(coreGroups, f.Resource, f.Input) + f.Type = strings.ToLower(f.Type) + if f.Type == "mutating" { + f.Mutate = true } - a.BuilderName = builderName(a.Config, strings.ToLower(a.Resource.Kind)) - ops := make([]string, len(a.Operations)) - for i, op := range a.Operations { + f.BuilderName = builderName(f.Config, strings.ToLower(f.Resource.Kind)) + ops := make([]string, len(f.Operations)) + for i, op := range f.Operations { ops[i] = strings.Title(op) } - a.OperationsString = strings.Join(ops, "") - - if a.Path == "" { - a.Path = filepath.Join("pkg", "webhook", - fmt.Sprintf("%s_server", a.Server), - strings.ToLower(a.Resource.Kind), - a.Type, - fmt.Sprintf("%s_%s_handler.go", strings.ToLower(a.Resource.Kind), strings.Join(a.Operations, "_"))) + f.OperationsString = strings.Join(ops, "") + + if f.Path == "" { + f.Path = filepath.Join("pkg", "webhook", + fmt.Sprintf("%s_server", f.Server), + strings.ToLower(f.Resource.Kind), + f.Type, + fmt.Sprintf("%s_%s_handler.go", strings.ToLower(f.Resource.Kind), strings.Join(f.Operations, "_"))) } - a.TemplateBody = addAdmissionHandlerTemplate - return a.Input, nil + f.TemplateBody = addAdmissionHandlerTemplate + return f.Input, nil } const addAdmissionHandlerTemplate = `{{ .Boilerplate }} diff --git a/pkg/scaffold/v1/webhook/admissionwebhooks.go b/pkg/scaffold/v1/webhook/admissionwebhooks.go index 98d3da38fa7..b5cd99b26d1 100644 --- a/pkg/scaffold/v1/webhook/admissionwebhooks.go +++ b/pkg/scaffold/v1/webhook/admissionwebhooks.go @@ -38,17 +38,17 @@ type AdmissionWebhooks struct { } // GetInput implements input.File -func (a *AdmissionWebhooks) GetInput() (input.Input, error) { - a.Server = strings.ToLower(a.Server) - a.Type = strings.ToLower(a.Type) - if a.Path == "" { - a.Path = filepath.Join("pkg", "webhook", - fmt.Sprintf("%s_server", a.Server), - strings.ToLower(a.Resource.Kind), - a.Type, "webhooks.go") +func (f *AdmissionWebhooks) GetInput() (input.Input, error) { + f.Server = strings.ToLower(f.Server) + f.Type = strings.ToLower(f.Type) + if f.Path == "" { + f.Path = filepath.Join("pkg", "webhook", + fmt.Sprintf("%s_server", f.Server), + strings.ToLower(f.Resource.Kind), + f.Type, "webhooks.go") } - a.TemplateBody = webhooksTemplate - return a.Input, nil + f.TemplateBody = webhooksTemplate + return f.Input, nil } const webhooksTemplate = `{{ .Boilerplate }} diff --git a/pkg/scaffold/v1/webhook/server.go b/pkg/scaffold/v1/webhook/server.go index 31b4f322cae..b6ebba602c2 100644 --- a/pkg/scaffold/v1/webhook/server.go +++ b/pkg/scaffold/v1/webhook/server.go @@ -33,12 +33,12 @@ type Server struct { } // GetInput implements input.File -func (a *Server) GetInput() (input.Input, error) { - if a.Path == "" { - a.Path = filepath.Join("pkg", "webhook", fmt.Sprintf("%s_server", a.Server), "server.go") +func (f *Server) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("pkg", "webhook", fmt.Sprintf("%s_server", f.Server), "server.go") } - a.TemplateBody = serverTemplate - return a.Input, nil + f.TemplateBody = serverTemplate + return f.Input, nil } const serverTemplate = `{{ .Boilerplate }} diff --git a/pkg/scaffold/v2/authproxyservice.go b/pkg/scaffold/v2/authproxyservice.go index 481f4224d18..1129024538b 100644 --- a/pkg/scaffold/v2/authproxyservice.go +++ b/pkg/scaffold/v2/authproxyservice.go @@ -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 diff --git a/pkg/scaffold/v2/certmanager/certificate.go b/pkg/scaffold/v2/certmanager/certificate.go index 2f29e0fbfd7..61f8612e155 100644 --- a/pkg/scaffold/v2/certmanager/certificate.go +++ b/pkg/scaffold/v2/certmanager/certificate.go @@ -28,12 +28,12 @@ type CertManager struct { } // GetInput implements input.File -func (p *CertManager) GetInput() (input.Input, error) { - if p.Path == "" { - p.Path = filepath.Join("config", "certmanager", "certificate.yaml") +func (f *CertManager) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("config", "certmanager", "certificate.yaml") } - p.TemplateBody = certManagerTemplate - return p.Input, nil + f.TemplateBody = certManagerTemplate + return f.Input, nil } const certManagerTemplate = `# The following manifests contain a self-signed issuer CR and a certificate CR. diff --git a/pkg/scaffold/v2/certmanager/kustomize.go b/pkg/scaffold/v2/certmanager/kustomize.go index 99cbe12edcc..02f23376731 100644 --- a/pkg/scaffold/v2/certmanager/kustomize.go +++ b/pkg/scaffold/v2/certmanager/kustomize.go @@ -28,12 +28,12 @@ type Kustomization struct { } // GetInput implements input.File -func (p *Kustomization) GetInput() (input.Input, error) { - if p.Path == "" { - p.Path = filepath.Join("config", "certmanager", "kustomization.yaml") +func (f *Kustomization) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("config", "certmanager", "kustomization.yaml") } - p.TemplateBody = kustomizationTemplate - return p.Input, nil + f.TemplateBody = kustomizationTemplate + return f.Input, nil } const kustomizationTemplate = `resources: diff --git a/pkg/scaffold/v2/certmanager/kustomizeconfig.go b/pkg/scaffold/v2/certmanager/kustomizeconfig.go index c2f5ab43721..853481f1da5 100644 --- a/pkg/scaffold/v2/certmanager/kustomizeconfig.go +++ b/pkg/scaffold/v2/certmanager/kustomizeconfig.go @@ -28,12 +28,12 @@ type KustomizeConfig struct { } // GetInput implements input.File -func (p *KustomizeConfig) GetInput() (input.Input, error) { - if p.Path == "" { - p.Path = filepath.Join("config", "certmanager", "kustomizeconfig.yaml") +func (f *KustomizeConfig) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("config", "certmanager", "kustomizeconfig.yaml") } - p.TemplateBody = kustomizeConfigTemplate - return p.Input, nil + f.TemplateBody = kustomizeConfigTemplate + return f.Input, nil } const kustomizeConfigTemplate = `# This configuration is for teaching kustomize how to update name ref and var substitution diff --git a/pkg/scaffold/v2/controller.go b/pkg/scaffold/v2/controller.go index aba74adaa51..5d7ca415922 100644 --- a/pkg/scaffold/v2/controller.go +++ b/pkg/scaffold/v2/controller.go @@ -45,23 +45,23 @@ type Controller struct { } // GetInput implements input.File -func (a *Controller) GetInput() (input.Input, error) { +func (f *Controller) GetInput() (input.Input, error) { - a.ResourcePackage, a.GroupDomain = util.GetResourceInfo(a.Resource, a.Repo, a.Domain) + f.ResourcePackage, f.GroupDomain = util.GetResourceInfo(f.Resource, f.Repo, f.Domain) - 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("controllers", - strings.ToLower(a.Resource.Kind)+"_controller.go") + if f.Path == "" { + f.Path = filepath.Join("controllers", + strings.ToLower(f.Resource.Kind)+"_controller.go") } - a.TemplateBody = controllerTemplate + f.TemplateBody = controllerTemplate - a.Input.IfExistsAction = input.Error - return a.Input, nil + f.Input.IfExistsAction = input.Error + return f.Input, nil } const controllerTemplate = `{{ .Boilerplate }} diff --git a/pkg/scaffold/v2/controller_suitetest.go b/pkg/scaffold/v2/controller_suitetest.go index 699c6365fbe..622df2f9715 100644 --- a/pkg/scaffold/v2/controller_suitetest.go +++ b/pkg/scaffold/v2/controller_suitetest.go @@ -37,17 +37,17 @@ type ControllerSuiteTest struct { } // GetInput implements input.File -func (v *ControllerSuiteTest) GetInput() (input.Input, error) { - if v.Path == "" { - v.Path = filepath.Join("controllers", "suite_test.go") +func (f *ControllerSuiteTest) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("controllers", "suite_test.go") } - v.TemplateBody = controllerSuiteTestTemplate - return v.Input, nil + f.TemplateBody = controllerSuiteTestTemplate + return f.Input, nil } // Validate validates the values -func (v *ControllerSuiteTest) Validate() error { - return v.Resource.Validate() +func (f *ControllerSuiteTest) Validate() error { + return f.Resource.Validate() } const controllerSuiteTestTemplate = `{{ .Boilerplate }} @@ -114,21 +114,21 @@ var _ = AfterSuite(func() { // Update updates given file (suite_test.go) with code fragments required for // adding import paths and code setup for new types. -func (a *ControllerSuiteTest) Update() error { +func (f *ControllerSuiteTest) Update() error { - resourcePackage, _ := util.GetResourceInfo(a.Resource, a.Repo, a.Domain) + resourcePackage, _ := util.GetResourceInfo(f.Resource, f.Repo, f.Domain) ctrlImportCodeFragment := fmt.Sprintf(`"%s/controllers" -`, a.Repo) +`, f.Repo) apiImportCodeFragment := fmt.Sprintf(`%s%s "%s/%s" -`, a.Resource.GroupImportSafe, a.Resource.Version, resourcePackage, a.Resource.Version) +`, f.Resource.GroupImportSafe, f.Resource.Version, resourcePackage, f.Resource.Version) addschemeCodeFragment := fmt.Sprintf(`err = %s%s.AddToScheme(scheme.Scheme) Expect(err).NotTo(HaveOccurred()) -`, a.Resource.GroupImportSafe, a.Resource.Version) +`, f.Resource.GroupImportSafe, f.Resource.Version) - err := internal.InsertStringsInFile(a.Path, + err := internal.InsertStringsInFile(f.Path, map[string][]string{ apiPkgImportScaffoldMarker: []string{ctrlImportCodeFragment, apiImportCodeFragment}, apiSchemeScaffoldMarker: []string{addschemeCodeFragment}, diff --git a/pkg/scaffold/v2/crd/enablecainjection_patch.go b/pkg/scaffold/v2/crd/enablecainjection_patch.go index dc6f108c03d..ef092a058ad 100644 --- a/pkg/scaffold/v2/crd/enablecainjection_patch.go +++ b/pkg/scaffold/v2/crd/enablecainjection_patch.go @@ -36,19 +36,19 @@ type EnableCAInjectionPatch struct { } // GetInput implements input.File -func (p *EnableCAInjectionPatch) GetInput() (input.Input, error) { - if p.Path == "" { - plural := flect.Pluralize(strings.ToLower(p.Resource.Kind)) - p.Path = filepath.Join("config", "crd", "patches", +func (f *EnableCAInjectionPatch) GetInput() (input.Input, error) { + if f.Path == "" { + plural := flect.Pluralize(strings.ToLower(f.Resource.Kind)) + f.Path = filepath.Join("config", "crd", "patches", fmt.Sprintf("cainjection_in_%s.yaml", plural)) } - p.TemplateBody = EnableCAInjectionPatchTemplate - return p.Input, nil + f.TemplateBody = EnableCAInjectionPatchTemplate + return f.Input, nil } // Validate validates the values -func (g *EnableCAInjectionPatch) Validate() error { - return g.Resource.Validate() +func (f *EnableCAInjectionPatch) Validate() error { + return f.Resource.Validate() } const EnableCAInjectionPatchTemplate = `# The following patch adds a directive for certmanager to inject CA into the CRD diff --git a/pkg/scaffold/v2/crd/enablewebhook_patch.go b/pkg/scaffold/v2/crd/enablewebhook_patch.go index ecea1742682..520a9d2f337 100644 --- a/pkg/scaffold/v2/crd/enablewebhook_patch.go +++ b/pkg/scaffold/v2/crd/enablewebhook_patch.go @@ -36,19 +36,19 @@ type EnableWebhookPatch struct { } // GetInput implements input.File -func (p *EnableWebhookPatch) GetInput() (input.Input, error) { - if p.Path == "" { - plural := flect.Pluralize(strings.ToLower(p.Resource.Kind)) - p.Path = filepath.Join("config", "crd", "patches", +func (f *EnableWebhookPatch) GetInput() (input.Input, error) { + if f.Path == "" { + plural := flect.Pluralize(strings.ToLower(f.Resource.Kind)) + f.Path = filepath.Join("config", "crd", "patches", fmt.Sprintf("webhook_in_%s.yaml", plural)) } - p.TemplateBody = enableWebhookPatchTemplate - return p.Input, nil + f.TemplateBody = enableWebhookPatchTemplate + return f.Input, nil } // Validate validates the values -func (g *EnableWebhookPatch) Validate() error { - return g.Resource.Validate() +func (f *EnableWebhookPatch) Validate() error { + return f.Resource.Validate() } const enableWebhookPatchTemplate = `# The following patch enables conversion webhook for CRD diff --git a/pkg/scaffold/v2/crd/kustomization.go b/pkg/scaffold/v2/crd/kustomization.go index db625d32df5..48dbe832a69 100644 --- a/pkg/scaffold/v2/crd/kustomization.go +++ b/pkg/scaffold/v2/crd/kustomization.go @@ -45,29 +45,29 @@ type Kustomization struct { } // GetInput implements input.File -func (c *Kustomization) GetInput() (input.Input, error) { - if c.Path == "" { - c.Path = filepath.Join("config", "crd", "kustomization.yaml") +func (f *Kustomization) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("config", "crd", "kustomization.yaml") } - c.TemplateBody = kustomizationTemplate - c.Input.IfExistsAction = input.Error - return c.Input, nil + f.TemplateBody = kustomizationTemplate + f.Input.IfExistsAction = input.Error + return f.Input, nil } -func (c *Kustomization) Update() error { - if c.Path == "" { - c.Path = filepath.Join("config", "crd", "kustomization.yaml") +func (f *Kustomization) Update() error { + if f.Path == "" { + f.Path = filepath.Join("config", "crd", "kustomization.yaml") } // TODO(directxman12): not technically valid if something changes from the default // (we'd need to parse the markers) - plural := flect.Pluralize(strings.ToLower(c.Resource.Kind)) + plural := flect.Pluralize(strings.ToLower(f.Resource.Kind)) - kustomizeResourceCodeFragment := fmt.Sprintf("- bases/%s.%s_%s.yaml\n", c.Resource.Group, c.Domain, plural) + kustomizeResourceCodeFragment := fmt.Sprintf("- bases/%s.%s_%s.yaml\n", f.Resource.Group, f.Domain, plural) kustomizeWebhookPatchCodeFragment := fmt.Sprintf("#- patches/webhook_in_%s.yaml\n", plural) kustomizeCAInjectionPatchCodeFragment := fmt.Sprintf("#- patches/cainjection_in_%s.yaml\n", plural) - return internal.InsertStringsInFile(c.Path, + return internal.InsertStringsInFile(f.Path, map[string][]string{ kustomizeResourceScaffoldMarker: {kustomizeResourceCodeFragment}, kustomizeWebhookPatchScaffoldMarker: {kustomizeWebhookPatchCodeFragment}, diff --git a/pkg/scaffold/v2/crd/kustomizeconfig.go b/pkg/scaffold/v2/crd/kustomizeconfig.go index 8aea3899e3c..0b9384de782 100644 --- a/pkg/scaffold/v2/crd/kustomizeconfig.go +++ b/pkg/scaffold/v2/crd/kustomizeconfig.go @@ -30,13 +30,13 @@ type KustomizeConfig struct { } // GetInput implements input.File -func (c *KustomizeConfig) GetInput() (input.Input, error) { - if c.Path == "" { - c.Path = filepath.Join("config", "crd", "kustomizeconfig.yaml") +func (f *KustomizeConfig) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("config", "crd", "kustomizeconfig.yaml") } - c.TemplateBody = kustomizeConfigTemplate - c.Input.IfExistsAction = input.Error - return c.Input, nil + f.TemplateBody = kustomizeConfigTemplate + f.Input.IfExistsAction = input.Error + return f.Input, nil } const kustomizeConfigTemplate = `# This file is for teaching kustomize how to substitute name and namespace reference in CRD diff --git a/pkg/scaffold/v2/crd_editor_rbac.go b/pkg/scaffold/v2/crd_editor_rbac.go index e07b82a42f3..e834c2a0e9a 100644 --- a/pkg/scaffold/v2/crd_editor_rbac.go +++ b/pkg/scaffold/v2/crd_editor_rbac.go @@ -36,18 +36,18 @@ type CRDEditorRole struct { } // GetInput implements input.File -func (g *CRDEditorRole) GetInput() (input.Input, error) { - if g.Path == "" { - g.Path = filepath.Join("config", "rbac", fmt.Sprintf("%s_editor_role.yaml", strings.ToLower(g.Resource.Kind))) +func (f *CRDEditorRole) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("config", "rbac", fmt.Sprintf("%s_editor_role.yaml", strings.ToLower(f.Resource.Kind))) } - g.TemplateBody = crdRoleEditorTemplate - return g.Input, nil + f.TemplateBody = crdRoleEditorTemplate + return f.Input, nil } // Validate validates the values -func (g *CRDEditorRole) Validate() error { - return g.Resource.Validate() +func (f *CRDEditorRole) Validate() error { + return f.Resource.Validate() } const crdRoleEditorTemplate = `# permissions for end users to edit {{ .Resource.Resource }}. diff --git a/pkg/scaffold/v2/crd_sample.go b/pkg/scaffold/v2/crd_sample.go index baa2569a83a..fa266f16c1d 100644 --- a/pkg/scaffold/v2/crd_sample.go +++ b/pkg/scaffold/v2/crd_sample.go @@ -36,20 +36,20 @@ type CRDSample struct { } // GetInput implements input.File -func (c *CRDSample) GetInput() (input.Input, error) { - if c.Path == "" { - c.Path = filepath.Join("config", "samples", fmt.Sprintf( - "%s_%s_%s.yaml", c.Resource.Group, c.Resource.Version, strings.ToLower(c.Resource.Kind))) +func (f *CRDSample) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("config", "samples", fmt.Sprintf( + "%s_%s_%s.yaml", f.Resource.Group, f.Resource.Version, strings.ToLower(f.Resource.Kind))) } - c.IfExistsAction = input.Error - c.TemplateBody = crdSampleTemplate - return c.Input, nil + f.IfExistsAction = input.Error + f.TemplateBody = crdSampleTemplate + return f.Input, nil } // Validate validates the values -func (c *CRDSample) Validate() error { - return c.Resource.Validate() +func (f *CRDSample) Validate() error { + return f.Resource.Validate() } const crdSampleTemplate = `apiVersion: {{ .Resource.Group }}.{{ .Domain }}/{{ .Resource.Version }} diff --git a/pkg/scaffold/v2/crd_viewer_rbac.go b/pkg/scaffold/v2/crd_viewer_rbac.go index 38c4ea3452a..bac2b6e195a 100644 --- a/pkg/scaffold/v2/crd_viewer_rbac.go +++ b/pkg/scaffold/v2/crd_viewer_rbac.go @@ -36,18 +36,18 @@ type CRDViewerRole struct { } // GetInput implements input.File -func (g *CRDViewerRole) GetInput() (input.Input, error) { - if g.Path == "" { - g.Path = filepath.Join("config", "rbac", fmt.Sprintf("%s_viewer_role.yaml", strings.ToLower(g.Resource.Kind))) +func (f *CRDViewerRole) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("config", "rbac", fmt.Sprintf("%s_viewer_role.yaml", strings.ToLower(f.Resource.Kind))) } - g.TemplateBody = crdRoleViewerTemplate - return g.Input, nil + f.TemplateBody = crdRoleViewerTemplate + return f.Input, nil } // Validate validates the values -func (g *CRDViewerRole) Validate() error { - return g.Resource.Validate() +func (f *CRDViewerRole) Validate() error { + return f.Resource.Validate() } const crdRoleViewerTemplate = `# permissions for end users to view {{ .Resource.Resource }}. diff --git a/pkg/scaffold/v2/dockerfile.go b/pkg/scaffold/v2/dockerfile.go index 8447eb09bb5..b3b8f6ed1b9 100644 --- a/pkg/scaffold/v2/dockerfile.go +++ b/pkg/scaffold/v2/dockerfile.go @@ -28,12 +28,12 @@ type Dockerfile struct { } // GetInput implements input.File -func (c *Dockerfile) GetInput() (input.Input, error) { - if c.Path == "" { - c.Path = "Dockerfile" +func (f *Dockerfile) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = "Dockerfile" } - c.TemplateBody = dockerfileTemplate - return c.Input, nil + f.TemplateBody = dockerfileTemplate + return f.Input, nil } const dockerfileTemplate = `# Build the manager binary diff --git a/pkg/scaffold/v2/gomod.go b/pkg/scaffold/v2/gomod.go index 4721d487ff4..f10bc85af39 100644 --- a/pkg/scaffold/v2/gomod.go +++ b/pkg/scaffold/v2/gomod.go @@ -29,13 +29,13 @@ type GoMod struct { } // GetInput implements input.File -func (g *GoMod) GetInput() (input.Input, error) { - if g.Path == "" { - g.Path = "go.mod" +func (f *GoMod) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = "go.mod" } - g.Input.IfExistsAction = input.Overwrite - g.TemplateBody = goModTemplate - return g.Input, nil + f.Input.IfExistsAction = input.Overwrite + f.TemplateBody = goModTemplate + return f.Input, nil } const goModTemplate = ` diff --git a/pkg/scaffold/v2/group.go b/pkg/scaffold/v2/group.go index d40d577d17b..554c2297a96 100644 --- a/pkg/scaffold/v2/group.go +++ b/pkg/scaffold/v2/group.go @@ -34,17 +34,17 @@ type Group struct { } // GetInput implements input.File -func (g *Group) GetInput() (input.Input, error) { - if g.Path == "" { - g.Path = filepath.Join("api", g.Resource.Version, "groupversion_info.go") +func (f *Group) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("api", f.Resource.Version, "groupversion_info.go") } - g.TemplateBody = groupTemplate - return g.Input, nil + f.TemplateBody = groupTemplate + return f.Input, nil } // Validate validates the values -func (g *Group) Validate() error { - return g.Resource.Validate() +func (f *Group) Validate() error { + return f.Resource.Validate() } const groupTemplate = `{{ .Boilerplate }} diff --git a/pkg/scaffold/v2/kustomize.go b/pkg/scaffold/v2/kustomize.go index e347c462fe7..79e2ca2729b 100644 --- a/pkg/scaffold/v2/kustomize.go +++ b/pkg/scaffold/v2/kustomize.go @@ -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. diff --git a/pkg/scaffold/v2/leaderelectionrole.go b/pkg/scaffold/v2/leaderelectionrole.go index fb05ae329f2..1f7e897125c 100644 --- a/pkg/scaffold/v2/leaderelectionrole.go +++ b/pkg/scaffold/v2/leaderelectionrole.go @@ -30,12 +30,12 @@ type LeaderElectionRole struct { } // GetInput implements input.File -func (r *LeaderElectionRole) GetInput() (input.Input, error) { - if r.Path == "" { - r.Path = filepath.Join("config", "rbac", "leader_election_role.yaml") +func (f *LeaderElectionRole) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("config", "rbac", "leader_election_role.yaml") } - r.TemplateBody = leaderElectionRoleTemplate - return r.Input, nil + f.TemplateBody = leaderElectionRoleTemplate + return f.Input, nil } const leaderElectionRoleTemplate = `# permissions to do leader election. diff --git a/pkg/scaffold/v2/leaderelectionrolebinding.go b/pkg/scaffold/v2/leaderelectionrolebinding.go index bc745977681..1b065b3a07f 100644 --- a/pkg/scaffold/v2/leaderelectionrolebinding.go +++ b/pkg/scaffold/v2/leaderelectionrolebinding.go @@ -30,12 +30,12 @@ type LeaderElectionRoleBinding struct { } // GetInput implements input.File -func (r *LeaderElectionRoleBinding) GetInput() (input.Input, error) { - if r.Path == "" { - r.Path = filepath.Join("config", "rbac", "leader_election_role_binding.yaml") +func (f *LeaderElectionRoleBinding) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("config", "rbac", "leader_election_role_binding.yaml") } - r.TemplateBody = leaderElectionRoleBindingTemplate - return r.Input, nil + f.TemplateBody = leaderElectionRoleBindingTemplate + return f.Input, nil } const leaderElectionRoleBindingTemplate = `apiVersion: rbac.authorization.k8s.io/v1 diff --git a/pkg/scaffold/v2/main.go b/pkg/scaffold/v2/main.go index 433d5d53993..d0f642e8105 100644 --- a/pkg/scaffold/v2/main.go +++ b/pkg/scaffold/v2/main.go @@ -40,17 +40,17 @@ type Main struct { } // GetInput implements input.File -func (m *Main) GetInput() (input.Input, error) { - if m.Path == "" { - m.Path = filepath.Join("main.go") +func (f *Main) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("main.go") } - m.TemplateBody = mainTemplate - return m.Input, nil + f.TemplateBody = mainTemplate + return f.Input, nil } // Update updates main.go with code fragments required to wire a new // resource/controller. -func (m *Main) Update(opts *MainUpdateOptions) error { +func (f *Main) Update(opts *MainUpdateOptions) error { path := "main.go" resPkg, _ := util.GetResourceInfo(opts.Resource, opts.Project.Repo, opts.Project.Domain) diff --git a/pkg/scaffold/v2/makefile.go b/pkg/scaffold/v2/makefile.go index a3342718629..96c2d910cc6 100644 --- a/pkg/scaffold/v2/makefile.go +++ b/pkg/scaffold/v2/makefile.go @@ -32,16 +32,16 @@ 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" } - 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 = ` diff --git a/pkg/scaffold/v2/manager/config.go b/pkg/scaffold/v2/manager/config.go index efd5beddec0..f7668a1d19f 100644 --- a/pkg/scaffold/v2/manager/config.go +++ b/pkg/scaffold/v2/manager/config.go @@ -32,12 +32,12 @@ type Config struct { } // GetInput implements input.File -func (c *Config) GetInput() (input.Input, error) { - if c.Path == "" { - c.Path = filepath.Join("config", "manager", "manager.yaml") +func (f *Config) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("config", "manager", "manager.yaml") } - c.TemplateBody = configTemplate - return c.Input, nil + f.TemplateBody = configTemplate + return f.Input, nil } const configTemplate = `apiVersion: v1 diff --git a/pkg/scaffold/v2/manager/kustomization.go b/pkg/scaffold/v2/manager/kustomization.go index 26bfbe64dc1..05a1930df5f 100644 --- a/pkg/scaffold/v2/manager/kustomization.go +++ b/pkg/scaffold/v2/manager/kustomization.go @@ -30,13 +30,13 @@ type Kustomization struct { } // GetInput implements input.File -func (c *Kustomization) GetInput() (input.Input, error) { - if c.Path == "" { - c.Path = filepath.Join("config", "manager", "kustomization.yaml") +func (f *Kustomization) 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: diff --git a/pkg/scaffold/v2/metricsauth/kustomize_auth_proxy_patch.go b/pkg/scaffold/v2/metricsauth/kustomize_auth_proxy_patch.go index d7aaa06482e..8c8bb8ad541 100644 --- a/pkg/scaffold/v2/metricsauth/kustomize_auth_proxy_patch.go +++ b/pkg/scaffold/v2/metricsauth/kustomize_auth_proxy_patch.go @@ -31,13 +31,13 @@ type KustomizeAuthProxyPatch struct { } // GetInput implements input.File -func (c *KustomizeAuthProxyPatch) GetInput() (input.Input, error) { - if c.Path == "" { - c.Path = filepath.Join("config", "default", "manager_auth_proxy_patch.yaml") +func (f *KustomizeAuthProxyPatch) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("config", "default", "manager_auth_proxy_patch.yaml") } - c.TemplateBody = kustomizeAuthProxyPatchTemplate - c.Input.IfExistsAction = input.Error - return c.Input, nil + f.TemplateBody = kustomizeAuthProxyPatchTemplate + f.Input.IfExistsAction = input.Error + return f.Input, nil } const kustomizeAuthProxyPatchTemplate = `# This patch inject a sidecar container which is a HTTP proxy for the controller manager, diff --git a/pkg/scaffold/v2/mgrrolebinding.go b/pkg/scaffold/v2/mgrrolebinding.go index a9a7f36758f..288bfe279fe 100644 --- a/pkg/scaffold/v2/mgrrolebinding.go +++ b/pkg/scaffold/v2/mgrrolebinding.go @@ -30,12 +30,12 @@ type ManagerRoleBinding struct { } // GetInput implements input.File -func (r *ManagerRoleBinding) GetInput() (input.Input, error) { - if r.Path == "" { - r.Path = filepath.Join("config", "rbac", "role_binding.yaml") +func (f *ManagerRoleBinding) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("config", "rbac", "role_binding.yaml") } - r.TemplateBody = managerBindingTemplate - return r.Input, nil + f.TemplateBody = managerBindingTemplate + return f.Input, nil } const managerBindingTemplate = `apiVersion: rbac.authorization.k8s.io/v1 diff --git a/pkg/scaffold/v2/prometheus/kustomize.go b/pkg/scaffold/v2/prometheus/kustomize.go index 49ff8bb2037..81ac79850e5 100644 --- a/pkg/scaffold/v2/prometheus/kustomize.go +++ b/pkg/scaffold/v2/prometheus/kustomize.go @@ -28,12 +28,12 @@ type Kustomization struct { } // GetInput implements input.File -func (p *Kustomization) GetInput() (input.Input, error) { - if p.Path == "" { - p.Path = filepath.Join("config", "prometheus", "kustomization.yaml") +func (f *Kustomization) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("config", "prometheus", "kustomization.yaml") } - p.TemplateBody = kustomizationTemplate - return p.Input, nil + f.TemplateBody = kustomizationTemplate + return f.Input, nil } const kustomizationTemplate = `resources: diff --git a/pkg/scaffold/v2/prometheus/monitor.go b/pkg/scaffold/v2/prometheus/monitor.go index 954313a64bd..e9ed3805f1c 100644 --- a/pkg/scaffold/v2/prometheus/monitor.go +++ b/pkg/scaffold/v2/prometheus/monitor.go @@ -28,12 +28,12 @@ type PrometheusServiceMonitor struct { } // GetInput implements input.File -func (p *PrometheusServiceMonitor) GetInput() (input.Input, error) { - if p.Path == "" { - p.Path = filepath.Join("config", "prometheus", "monitor.yaml") +func (f *PrometheusServiceMonitor) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("config", "prometheus", "monitor.yaml") } - p.TemplateBody = monitorTemplate - return p.Input, nil + f.TemplateBody = monitorTemplate + return f.Input, nil } const monitorTemplate = ` diff --git a/pkg/scaffold/v2/rbac.go b/pkg/scaffold/v2/rbac.go index cb6826ad2be..5c2b96b7d37 100644 --- a/pkg/scaffold/v2/rbac.go +++ b/pkg/scaffold/v2/rbac.go @@ -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: diff --git a/pkg/scaffold/v2/types.go b/pkg/scaffold/v2/types.go index 352b30cfebe..65a8c17d16a 100644 --- a/pkg/scaffold/v2/types.go +++ b/pkg/scaffold/v2/types.go @@ -36,19 +36,19 @@ type Types struct { } // GetInput implements input.File -func (t *Types) GetInput() (input.Input, error) { - if t.Path == "" { - t.Path = filepath.Join("pkg", "apis", t.Resource.Group, t.Resource.Version, - fmt.Sprintf("%s_types.go", strings.ToLower(t.Resource.Kind))) +func (f *Types) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("pkg", "apis", f.Resource.Group, f.Resource.Version, + fmt.Sprintf("%s_types.go", strings.ToLower(f.Resource.Kind))) } - t.TemplateBody = typesTemplate - t.IfExistsAction = input.Error - return t.Input, nil + f.TemplateBody = typesTemplate + f.IfExistsAction = input.Error + return f.Input, nil } // Validate validates the values -func (t *Types) Validate() error { - return t.Resource.Validate() +func (f *Types) Validate() error { + return f.Resource.Validate() } const typesTemplate = `{{ .Boilerplate }} diff --git a/pkg/scaffold/v2/webhook/enablecainection_patch.go b/pkg/scaffold/v2/webhook/enablecainection_patch.go index f9115e2df6b..d0b2b7afd8d 100644 --- a/pkg/scaffold/v2/webhook/enablecainection_patch.go +++ b/pkg/scaffold/v2/webhook/enablecainection_patch.go @@ -30,13 +30,13 @@ type InjectCAPatch struct { } // GetInput implements input.File -func (c *InjectCAPatch) GetInput() (input.Input, error) { - if c.Path == "" { - c.Path = filepath.Join("config", "default", "webhookcainjection_patch.yaml") +func (f *InjectCAPatch) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("config", "default", "webhookcainjection_patch.yaml") } - c.TemplateBody = injectCAPatchTemplate - c.Input.IfExistsAction = input.Error - return c.Input, nil + f.TemplateBody = injectCAPatchTemplate + f.Input.IfExistsAction = input.Error + return f.Input, nil } const injectCAPatchTemplate = `# This patch add annotation to admission webhook config and diff --git a/pkg/scaffold/v2/webhook/kustomization.go b/pkg/scaffold/v2/webhook/kustomization.go index 4562b4ff52a..e1f5fc52c82 100644 --- a/pkg/scaffold/v2/webhook/kustomization.go +++ b/pkg/scaffold/v2/webhook/kustomization.go @@ -30,13 +30,13 @@ type Kustomization struct { } // GetInput implements input.File -func (c *Kustomization) GetInput() (input.Input, error) { - if c.Path == "" { - c.Path = filepath.Join("config", "webhook", "kustomization.yaml") +func (f *Kustomization) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("config", "webhook", "kustomization.yaml") } - c.TemplateBody = KustomizeWebhookTemplate - c.Input.IfExistsAction = input.Error - return c.Input, nil + f.TemplateBody = KustomizeWebhookTemplate + f.Input.IfExistsAction = input.Error + return f.Input, nil } const KustomizeWebhookTemplate = `resources: diff --git a/pkg/scaffold/v2/webhook/kustomizeconfig.go b/pkg/scaffold/v2/webhook/kustomizeconfig.go index b65baed7d5d..e942d115f6c 100644 --- a/pkg/scaffold/v2/webhook/kustomizeconfig.go +++ b/pkg/scaffold/v2/webhook/kustomizeconfig.go @@ -30,13 +30,13 @@ type KustomizeConfigWebhook struct { } // GetInput implements input.File -func (c *KustomizeConfigWebhook) GetInput() (input.Input, error) { - if c.Path == "" { - c.Path = filepath.Join("config", "webhook", "kustomizeconfig.yaml") +func (f *KustomizeConfigWebhook) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("config", "webhook", "kustomizeconfig.yaml") } - c.TemplateBody = KustomizeConfigWebhookTemplate - c.Input.IfExistsAction = input.Error - return c.Input, nil + f.TemplateBody = KustomizeConfigWebhookTemplate + f.Input.IfExistsAction = input.Error + return f.Input, nil } const KustomizeConfigWebhookTemplate = `# the following config is for teaching kustomize where to look at when substituting vars. diff --git a/pkg/scaffold/v2/webhook/service.go b/pkg/scaffold/v2/webhook/service.go index 7fcb804fec0..5975a779422 100644 --- a/pkg/scaffold/v2/webhook/service.go +++ b/pkg/scaffold/v2/webhook/service.go @@ -30,13 +30,13 @@ type Service struct { } // GetInput implements input.File -func (c *Service) GetInput() (input.Input, error) { - if c.Path == "" { - c.Path = filepath.Join("config", "webhook", "service.yaml") +func (f *Service) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("config", "webhook", "service.yaml") } - c.TemplateBody = ServiceTemplate - c.Input.IfExistsAction = input.Error - return c.Input, nil + f.TemplateBody = ServiceTemplate + f.Input.IfExistsAction = input.Error + return f.Input, nil } const ServiceTemplate = ` diff --git a/pkg/scaffold/v2/webhook/webhook.go b/pkg/scaffold/v2/webhook/webhook.go index 9f900dee850..3b0e9e36785 100644 --- a/pkg/scaffold/v2/webhook/webhook.go +++ b/pkg/scaffold/v2/webhook/webhook.go @@ -51,36 +51,36 @@ type Webhook struct { } // GetInput implements input.File -func (a *Webhook) GetInput() (input.Input, error) { +func (f *Webhook) GetInput() (input.Input, error) { - _, a.GroupDomain = util.GetResourceInfo(a.Resource, a.Repo, a.Domain) + _, f.GroupDomain = util.GetResourceInfo(f.Resource, f.Repo, f.Domain) - a.GroupDomainWithDash = strings.Replace(a.GroupDomain, ".", "-", -1) + f.GroupDomainWithDash = strings.Replace(f.GroupDomain, ".", "-", -1) - 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("api", a.Resource.Version, - fmt.Sprintf("%s_webhook.go", strings.ToLower(a.Resource.Kind))) + if f.Path == "" { + f.Path = filepath.Join("api", f.Resource.Version, + fmt.Sprintf("%s_webhook.go", strings.ToLower(f.Resource.Kind))) } webhookTemplate := WebhookTemplate - if a.Defaulting { + if f.Defaulting { webhookTemplate = webhookTemplate + DefaultingWebhookTemplate } - if a.Validating { + if f.Validating { webhookTemplate = webhookTemplate + ValidatingWebhookTemplate } - a.TemplateBody = webhookTemplate - a.Input.IfExistsAction = input.Error - return a.Input, nil + f.TemplateBody = webhookTemplate + f.Input.IfExistsAction = input.Error + return f.Input, nil } // Validate validates the values -func (g *Webhook) Validate() error { - return g.Resource.Validate() +func (f *Webhook) Validate() error { + return f.Resource.Validate() } const ( diff --git a/pkg/scaffold/v2/webhook_manager_patch.go b/pkg/scaffold/v2/webhook_manager_patch.go index 3abcebe965a..636de346c8e 100644 --- a/pkg/scaffold/v2/webhook_manager_patch.go +++ b/pkg/scaffold/v2/webhook_manager_patch.go @@ -28,12 +28,12 @@ type ManagerWebhookPatch struct { } // GetInput implements input.File -func (p *ManagerWebhookPatch) GetInput() (input.Input, error) { - if p.Path == "" { - p.Path = filepath.Join("config", "default", "manager_webhook_patch.yaml") +func (f *ManagerWebhookPatch) GetInput() (input.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("config", "default", "manager_webhook_patch.yaml") } - p.TemplateBody = ManagerWebhookPatchTemplate - return p.Input, nil + f.TemplateBody = ManagerWebhookPatchTemplate + return f.Input, nil } const ManagerWebhookPatchTemplate = `apiVersion: apps/v1