Skip to content

Commit

Permalink
enable golint lll check
Browse files Browse the repository at this point in the history
  • Loading branch information
camilamacedo86 committed Jan 17, 2020
1 parent 52db7c3 commit c52ba01
Show file tree
Hide file tree
Showing 50 changed files with 191 additions and 87 deletions.
3 changes: 2 additions & 1 deletion cmd/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ func newEditProjectCmd() *cobra.Command {
}

if projectInfo.Version != project.Version2 {
log.Fatalf("kubebuilder multigroup is for project version: 2, the version of this project is: %s \n", projectInfo.Version)
log.Fatalf("kubebuilder multigroup is for project version: 2,"+
" the version of this project is: %s \n", projectInfo.Version)
}

// Set MultiGroup Option
Expand Down
11 changes: 7 additions & 4 deletions cmd/init_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ type projectOptions struct {

func (o *projectOptions) bindCmdlineFlags(cmd *cobra.Command) {

cmd.Flags().BoolVar(&o.skipGoVersionCheck, "skip-go-version-check", false, "if specified, skip checking the Go version")
cmd.Flags().BoolVar(&o.skipGoVersionCheck, "skip-go-version-check",
false, "if specified, skip checking the Go version")

// dependency args
cmd.Flags().BoolVar(&o.fetchDeps, "fetch-deps", true, "ensure dependencies are downloaded")
Expand All @@ -107,12 +108,14 @@ func (o *projectOptions) bindCmdlineFlags(cmd *cobra.Command) {

// boilerplate args
cmd.Flags().StringVar(&o.boilerplate.Path, "path", "", "path for boilerplate")
cmd.Flags().StringVar(&o.boilerplate.License, "license", "apache2", "license to use to boilerplate. May be one of apache2,none")
cmd.Flags().StringVar(&o.boilerplate.License, "license", "apache2",
"license to use to boilerplate. May be one of apache2,none")
cmd.Flags().StringVar(&o.boilerplate.Owner, "owner", "", "Owner to add to the copyright")

// project args
cmd.Flags().StringVar(&o.project.Repo, "repo", "", "name to use for go module, e.g. github.com/user/repo. "+
"defaults to the go package of the current working directory.")
cmd.Flags().StringVar(&o.project.Repo, "repo", "",
"name to use for go module, e.g. github.com/user/repo. "+
"defaults to the go package of the current working directory.")
cmd.Flags().StringVar(&o.project.Domain, "domain", "my.domain", "domain for groups")
cmd.Flags().StringVar(&o.project.Version, "project-version", project.Version2, "project version")
}
Expand Down
7 changes: 5 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ func findCurrentRepo() (string, error) {
err = fmt.Errorf("%s", string(exitErr.Stderr))
}
// give up, let the user figure it out
return "", fmt.Errorf("could not determine repository path from module data, package data, or by initializing a module: %v", err)
return "", fmt.Errorf("could not determine repository path from module data, "+
"package data, or by initializing a module: %v", err)
}
defer os.Remove("go.mod") // clean up after ourselves
return findGoModulePath(true)
Expand Down Expand Up @@ -200,5 +201,7 @@ func getProjectVersion() (bool, string) {
}

func printV1DeprecationWarning() {
fmt.Printf(NoticeColor, "[Deprecation Notice] The v1 projects are deprecated and will not be supported beyond Feb 1, 2020.\nSee how to upgrade your project to v2: https://book.kubebuilder.io/migration/guide.html\n")
fmt.Printf(NoticeColor, "[Deprecation Notice] The v1 projects are deprecated and will not be supported "+
"beyond Feb 1, 2020.\nSee how to upgrade your project to v2:"+
" https://book.kubebuilder.io/migration/guide.html\n")
}
14 changes: 7 additions & 7 deletions cmd/webhook_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ This command is only available for v1 scaffolding project.
}

fmt.Println("Writing scaffold for you to edit...")

config := webhook.Config{Server: o.server, Type: o.webhookType, Operations: o.operations}
err = (&scaffold.Scaffold{}).Execute(
&model.Universe{},
input.Options{},
&manager.Webhook{},
&webhook.AdmissionHandler{Resource: o.res, Config: webhook.Config{Server: o.server, Type: o.webhookType, Operations: o.operations}},
&webhook.AdmissionWebhookBuilder{Resource: o.res, Config: webhook.Config{Server: o.server, Type: o.webhookType, Operations: o.operations}},
&webhook.AdmissionWebhooks{Resource: o.res, Config: webhook.Config{Server: o.server, Type: o.webhookType, Operations: o.operations}},
&webhook.AddAdmissionWebhookBuilderHandler{Resource: o.res, Config: webhook.Config{Server: o.server, Type: o.webhookType, Operations: o.operations}},
&webhook.Server{Config: webhook.Config{Server: o.server, Type: o.webhookType, Operations: o.operations}},
&webhook.AddServer{Config: webhook.Config{Server: o.server, Type: o.webhookType, Operations: o.operations}},
&webhook.AdmissionHandler{Resource: o.res, Config: config},
&webhook.AdmissionWebhookBuilder{Resource: o.res, Config: config},
&webhook.AdmissionWebhooks{Resource: o.res, Config: config},
&webhook.AddAdmissionWebhookBuilderHandler{Resource: o.res, Config: config},
&webhook.Server{Config: config},
&webhook.AddServer{Config: config},
)
if err != nil {
log.Fatal(err)
Expand Down
9 changes: 6 additions & 3 deletions cmd/webhook_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ func newWebhookV2Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "webhook",
Short: "Scaffold a webhook for an API resource.",
Long: `Scaffold a webhook for an API resource. You can choose to scaffold defaulting, validating and (or) conversion webhooks.`,
Long: `Scaffold a webhook for an API resource. You can choose to scaffold defaulting, ` +
`validating and (or) conversion webhooks.`,
Example: ` # Create defaulting and validating webhooks for CRD of group crew, version v1 and kind FirstMate.
kubebuilder create webhook --group crew --version v1 --kind FirstMate --defaulting --programmatic-validation
Expand All @@ -56,12 +57,14 @@ func newWebhookV2Cmd() *cobra.Command {
}

if projectInfo.Version != project.Version2 {
fmt.Printf("kubebuilder webhook is for project version: 2, the version of this project is: %s \n", projectInfo.Version)
fmt.Printf("kubebuilder webhook is for project version: 2,"+
" the version of this project is: %s \n", projectInfo.Version)
os.Exit(1)
}

if !o.defaulting && !o.validation && !o.conversion {
fmt.Printf("kubebuilder webhook requires at least one of --defaulting, --programmatic-validation and --conversion to be true")
fmt.Printf("kubebuilder webhook requires at least one of" +
" --defaulting, --programmatic-validation and --conversion to be true")
os.Exit(1)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ bases:
- ../crd
- ../rbac
- ../manager
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in crd/kustomization.yaml
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
- ../webhook
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
- ../certmanager
Expand All @@ -29,7 +30,8 @@ patchesStrategicMerge:
# endpoint w/o any authn/z, please comment the following line.
- manager_auth_proxy_patch.yaml

# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in crd/kustomization.yaml
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
- manager_webhook_patch.yaml

# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ bases:
- ../crd
- ../rbac
- ../manager
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in crd/kustomization.yaml
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
- ../webhook
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
- ../certmanager
Expand All @@ -29,7 +30,8 @@ patchesStrategicMerge:
# endpoint w/o any authn/z, please comment the following line.
- manager_auth_proxy_patch.yaml

# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in crd/kustomization.yaml
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
- manager_webhook_patch.yaml

# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'.
Expand Down
10 changes: 8 additions & 2 deletions pkg/scaffold/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ func (api *API) buildUniverse() *model.Universe {
Plural: flect.Pluralize(strings.ToLower(api.Resource.Kind)),
}

resourceModel.GoPackage, resourceModel.GroupDomain = util.GetResourceInfo(api.Resource, api.project.Repo, api.project.Domain, api.project.MultiGroup)
resourceModel.GoPackage, resourceModel.GroupDomain = util.GetResourceInfo(
api.Resource,
api.project.Repo,
api.project.Domain,
api.project.MultiGroup,
)

return &model.Universe{
Resource: resourceModel,
Expand Down Expand Up @@ -300,7 +305,8 @@ func (api *API) validateResourceGroup(r *resource.Resource) error {
return fmt.Errorf("group '%s', version '%s' and kind '%s' already exists", r.Group, r.Version, r.Kind)
}
if !api.isGroupAllowed(r) {
return fmt.Errorf("group '%s' is not same as existing group. Multiple groups are not enabled in this project. To enable, use the multigroup command", r.Group)
return fmt.Errorf("group '%s' is not same as existing group."+
" Multiple groups are not enabled in this project. To enable, use the multigroup command.", r.Group)
}
return nil
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/scaffold/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ type V1Project struct {
func (p *V1Project) Validate() error {
_, err := exec.LookPath("dep")
if err != nil {
return fmt.Errorf("dep is not installed (%v). Follow steps at: https://golang.github.io/dep/docs/installation.html", err)
return fmt.Errorf("dep is not installed (%v). "+
"Follow steps at: https://golang.github.io/dep/docs/installation.html", err)
}
return nil
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/scaffold/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ func (r *Resource) isGroupEmpty() bool {
const (
dns1123LabelFmt string = "[a-z0-9]([-a-z0-9]*[a-z0-9])?"
dns1123SubdomainFmt string = dns1123LabelFmt + "(\\." + dns1123LabelFmt + ")*"
dns1123SubdomainErrorMsg string = "a DNS-1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character"
dns1123SubdomainErrorMsg string = "a DNS-1123 subdomain must consist of lower case alphanumeric characters," +
" '-' or '.', and must start and end with an alphanumeric character"

// dns1123SubdomainMaxLength is a subdomain's max length in DNS (RFC 1123)
dns1123SubdomainMaxLength int = 253
Expand Down
6 changes: 4 additions & 2 deletions pkg/scaffold/resource/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ var _ = Describe("Resource", func() {
It("should fail if the Group is not all lowercase", func() {
instance := &Resource{Group: "Crew", Version: "v1", Kind: "FirstMate"}
Expect(instance.Validate()).NotTo(Succeed())
Expect(instance.Validate().Error()).To(ContainSubstring("group name is invalid: ([a DNS-1123 subdomain must consist of lower case alphanumeric characters"))
Expect(instance.Validate().Error()).To(ContainSubstring("group name is invalid: " +
"([a DNS-1123 subdomain must consist of lower case alphanumeric characters"))
})

It("should fail if the Group contains non-alpha characters", func() {
instance := &Resource{Group: "crew1*?", Version: "v1", Kind: "FirstMate"}
Expect(instance.Validate()).NotTo(Succeed())
Expect(instance.Validate().Error()).To(ContainSubstring("group name is invalid: ([a DNS-1123 subdomain must consist of lower case alphanumeric characters"))
Expect(instance.Validate().Error()).To(ContainSubstring("group name is invalid:" +
" ([a DNS-1123 subdomain must consist of lower case alphanumeric characters"))
})

It("should fail if the Version is not specified", func() {
Expand Down
4 changes: 2 additions & 2 deletions pkg/scaffold/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (s *Scaffold) validate(file input.File) error {

// LoadProjectFile reads the project file and deserializes it into a Project
func LoadProjectFile(path string) (input.ProjectFile, error) {
in, err := ioutil.ReadFile(path) // nolint: gosec
in, err := ioutil.ReadFile(path) // nolint:gosec
if err != nil {
return input.ProjectFile{}, err
}
Expand Down Expand Up @@ -142,7 +142,7 @@ func saveProjectFile(path string, project *input.ProjectFile) error {

// GetBoilerplate reads the boilerplate file
func getBoilerplate(path string) (string, error) {
b, err := ioutil.ReadFile(path) // nolint: gosec
b, err := ioutil.ReadFile(path) // nolint:gosec
return string(b), err
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/scaffold/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ import (
"sigs.k8s.io/kubebuilder/pkg/scaffold/resource"
)

func GetResourceInfo(r *resource.Resource, repo, domain string, isMultiGroup bool) (resourcePackage, groupDomain string) {
func GetResourceInfo(r *resource.Resource,
repo string,
domain string,
isMultiGroup bool,
) (resourcePackage, groupDomain string) {
// Use the k8s.io/api package for core resources
coreGroups := map[string]string{
"apps": "",
Expand Down
11 changes: 8 additions & 3 deletions pkg/scaffold/v1/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,13 @@ func (f *Controller) GetInput() (input.Input, error) {
return f.Input, nil
}

func getResourceInfo(coreGroups map[string]string, r *resource.Resource, in input.Input) (resourcePackage, groupDomain string) {
func getResourceInfo(coreGroups map[string]string,
r *resource.Resource,
in input.Input,
) (resourcePackage, groupDomain string) {
resourcePath := filepath.Join("pkg", "apis", r.Group, r.Version,
fmt.Sprintf("%s_types.go", strings.ToLower(r.Kind)))

if _, err := os.Stat(resourcePath); os.IsNotExist(err) {
if domain, found := coreGroups[r.Group]; found {
resourcePackage := path.Join("k8s.io", "api")
Expand All @@ -100,6 +104,7 @@ func getResourceInfo(coreGroups map[string]string, r *resource.Resource, in inpu
return path.Join(in.Repo, "pkg", "apis"), r.Group + "." + in.Domain
}

// nolint:lll
const controllerTemplate = `{{ .Boilerplate }}
package {{ lower .Resource.Kind }}
Expand Down Expand Up @@ -144,8 +149,8 @@ var log = logf.Log.WithName("{{ lower .Resource.Kind }}-controller")
* business logic. Delete these comments after modifying this file.*
*/
// Add creates a new {{ .Resource.Kind }} Controller and adds it to the Manager with default RBAC. The Manager will set fields on the Controller
// and Start it when the Manager is Started.
// Add creates a new {{ .Resource.Kind }} Controller and adds it to the Manager with default RBAC.
// The Manager will set fields on the Controller and Start it when the Manager is Started.
func Add(mgr manager.Manager) error {
return add(mgr, newReconciler(mgr))
}
Expand Down
1 change: 1 addition & 0 deletions pkg/scaffold/v1/controller/controllertest.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (f *Test) GetInput() (input.Input, error) {
return f.Input, nil
}

// nolint:lll
const controllerTestTemplate = `{{ .Boilerplate }}
package {{ lower .Resource.Kind }}
Expand Down
1 change: 1 addition & 0 deletions pkg/scaffold/v1/crd/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func (f *Doc) Validate() error {
return f.Resource.Validate()
}

// nolint:lll
const docGoTemplate = `{{ .Boilerplate }}
// Package {{.Resource.Version}} contains API Schema definitions for the {{ .Resource.GroupImportSafe }} {{.Resource.Version}} API group
Expand Down
1 change: 1 addition & 0 deletions pkg/scaffold/v1/crd/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func (f *Register) Validate() error {
return f.Resource.Validate()
}

// nolint:lll
const registerTemplate = `{{ .Boilerplate }}
// NOTE: Boilerplate only. Ignore this file.
Expand Down
1 change: 1 addition & 0 deletions pkg/scaffold/v1/manager/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func (f *Webhook) GetInput() (input.Input, error) {
return f.Input, nil
}

// nolint:lll
const webhookTemplate = `{{ .Boilerplate }}
package webhook
Expand Down
4 changes: 2 additions & 2 deletions pkg/scaffold/v1/metricsauth/kustomize_auth_proxy_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func (f *KustomizeAuthProxyPatch) GetInput() (input.Input, error) {
return f.Input, nil
}

const kustomizeAuthProxyPatchTemplate = `# This patch inject a sidecar container which is a HTTP proxy for the controller manager,
# it performs RBAC authorization against the Kubernetes API using SubjectAccessReviews.
const kustomizeAuthProxyPatchTemplate = `# This patch inject a sidecar container which is a HTTP proxy for the
# controller manager, it performs RBAC authorization against the Kubernetes API using SubjectAccessReviews.
apiVersion: apps/v1
kind: StatefulSet
metadata:
Expand Down
1 change: 1 addition & 0 deletions pkg/scaffold/v1/webhook/admissionhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func (f *AdmissionHandler) GetInput() (input.Input, error) {
return f.Input, nil
}

// nolint:lll
const addAdmissionHandlerTemplate = `{{ .Boilerplate }}
package {{ .Type }}
Expand Down
Loading

0 comments on commit c52ba01

Please sign in to comment.