Skip to content

Commit

Permalink
Merge pull request #1291 from camilamacedo86/lint
Browse files Browse the repository at this point in the history
enable lint golint and fix notifications
  • Loading branch information
k8s-ci-robot committed Jan 17, 2020
2 parents 0f3644a + ade6f5f commit 1bbfd06
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 50 deletions.
2 changes: 1 addition & 1 deletion cmd/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func newEditProjectCmd() *cobra.Command {

err = saveProjectFile("PROJECT", &projectInfo)
if err != nil {
log.Fatalf("error updating project file with resource information : %v \n", err)
log.Fatalf("error updating project file with resource information : %v", err)
}
},
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/scaffold/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (api *API) scaffoldV2() error {
// If the --force was used to re-crete a resource that was created before then,
// the PROJECT file will not be updated.
if err := saveProjectFile("PROJECT", api.project); err != nil {
return fmt.Errorf("error updating project file with resource information : %v \n", err)
return fmt.Errorf("error updating project file with resource information: %v", err)
}
}

Expand Down Expand Up @@ -249,7 +249,7 @@ func (api *API) scaffoldV2() error {
}

ctrlScaffolder := &controllerv2.Controller{Resource: r}
testsuiteScaffolder := &controllerv2.ControllerSuiteTest{Resource: r}
testsuiteScaffolder := &controllerv2.SuiteTest{Resource: r}
err := scaffold.Execute(
api.buildUniverse(),
input.Options{},
Expand Down Expand Up @@ -297,10 +297,10 @@ func (api *API) isGroupAllowed(r *resource.Resource) bool {
// validateResourceGroup will return an error if the group cannot be created
func (api *API) validateResourceGroup(r *resource.Resource) error {
if api.resourceExists() && !api.Force {
return fmt.Errorf("group '%s', version '%s' and kind '%s' already exists.", r.Group, r.Version, r.Kind)
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
2 changes: 1 addition & 1 deletion pkg/scaffold/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func (p *V2Project) Scaffold() error {
&webhook.Service{},
&webhook.InjectCAPatch{},
&prometheus.Kustomization{},
&prometheus.PrometheusServiceMonitor{},
&prometheus.ServiceMonitor{},
&certmanager.CertManager{},
&certmanager.Kustomization{},
&certmanager.KustomizeConfig{})
Expand Down
8 changes: 4 additions & 4 deletions pkg/scaffold/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (s *Scaffold) setFields(t input.File) {
}
}

func (_ *Scaffold) validate(file input.File) error {
func (s *Scaffold) validate(file input.File) error {
if reqValFile, ok := file.(input.RequiresValidation); ok {
return reqValFile.Validate()
}
Expand Down Expand Up @@ -239,11 +239,11 @@ func (s *Scaffold) buildFileModel(e input.File) (*model.File, error) {
Path: i.Path,
}

if b, err := s.doTemplate(i, e); err != nil {
b, err := s.doTemplate(i, e)
if err != nil {
return nil, err
} else {
m.Contents = string(b)
}
m.Contents = string(b)

return m, nil
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/scaffold/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ func GetResourceInfo(r *resource.Resource, repo, domain string, isMultiGroup boo

if isMultiGroup {
return path.Join(repo, "apis", r.Group), r.Group + "." + domain
} else {
return path.Join(repo, "api"), r.Group + "." + domain
}
return path.Join(repo, "api"), r.Group + "." + domain
}
1 change: 1 addition & 0 deletions pkg/scaffold/v1/crd/crd_sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
var _ input.File = &CRDSample{}

// CRDSample scaffolds a manifest for CRD sample.
// nolint:golint
type CRDSample struct {
input.Input

Expand Down
16 changes: 8 additions & 8 deletions pkg/scaffold/v2/controller/controller_suitetest.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ import (
"sigs.k8s.io/kubebuilder/pkg/scaffold/v2/internal"
)

var _ input.File = &ControllerSuiteTest{}
var _ input.File = &SuiteTest{}

// ControllerSuiteTest scaffolds the suite_test.go file to setup the controller test
type ControllerSuiteTest struct {
// SuiteTest scaffolds the suite_test.go file to setup the controller test
type SuiteTest struct {
input.Input

// Resource is the Resource to make the Controller for
Resource *resource.Resource
}

// GetInput implements input.File
func (f *ControllerSuiteTest) GetInput() (input.Input, error) {
func (f *SuiteTest) GetInput() (input.Input, error) {

if f.Path == "" {
if f.MultiGroup {
Expand All @@ -53,7 +53,7 @@ func (f *ControllerSuiteTest) GetInput() (input.Input, error) {
}

// Validate validates the values
func (f *ControllerSuiteTest) Validate() error {
func (f *SuiteTest) Validate() error {
return f.Resource.Validate()
}

Expand Down Expand Up @@ -121,7 +121,7 @@ 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 (f *ControllerSuiteTest) Update() error {
func (f *SuiteTest) Update() error {

resourcePackage, _ := util.GetResourceInfo(f.Resource, f.Repo, f.Domain, f.MultiGroup)

Expand All @@ -137,8 +137,8 @@ Expect(err).NotTo(HaveOccurred())

err := internal.InsertStringsInFile(f.Path,
map[string][]string{
scaffoldv2.ApiPkgImportScaffoldMarker: {ctrlImportCodeFragment, apiImportCodeFragment},
scaffoldv2.ApiSchemeScaffoldMarker: {addschemeCodeFragment},
scaffoldv2.APIPkgImportScaffoldMarker: {ctrlImportCodeFragment, apiImportCodeFragment},
scaffoldv2.APISchemeScaffoldMarker: {addschemeCodeFragment},
})
if err != nil {
return err
Expand Down
18 changes: 9 additions & 9 deletions pkg/scaffold/v2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (
)

const (
ApiPkgImportScaffoldMarker = "// +kubebuilder:scaffold:imports"
ApiSchemeScaffoldMarker = "// +kubebuilder:scaffold:scheme"
APIPkgImportScaffoldMarker = "// +kubebuilder:scaffold:imports"
APISchemeScaffoldMarker = "// +kubebuilder:scaffold:scheme"
ReconcilerSetupScaffoldMarker = "// +kubebuilder:scaffold:builder"
)

Expand Down Expand Up @@ -104,8 +104,8 @@ func (f *Main) Update(opts *MainUpdateOptions) error {
if opts.WireResource {
err := internal.InsertStringsInFile(path,
map[string][]string{
ApiPkgImportScaffoldMarker: {apiImportCodeFragment},
ApiSchemeScaffoldMarker: {addschemeCodeFragment},
APIPkgImportScaffoldMarker: {apiImportCodeFragment},
APISchemeScaffoldMarker: {addschemeCodeFragment},
})
if err != nil {
return err
Expand All @@ -115,17 +115,17 @@ func (f *Main) Update(opts *MainUpdateOptions) error {
if opts.WireController {
return internal.InsertStringsInFile(path,
map[string][]string{
ApiPkgImportScaffoldMarker: {apiImportCodeFragment, ctrlImportCodeFragment},
ApiSchemeScaffoldMarker: {addschemeCodeFragment},
APIPkgImportScaffoldMarker: {apiImportCodeFragment, ctrlImportCodeFragment},
APISchemeScaffoldMarker: {addschemeCodeFragment},
ReconcilerSetupScaffoldMarker: {reconcilerSetupCodeFragment},
})
}

if opts.WireWebhook {
return internal.InsertStringsInFile(path,
map[string][]string{
ApiPkgImportScaffoldMarker: {apiImportCodeFragment, ctrlImportCodeFragment},
ApiSchemeScaffoldMarker: {addschemeCodeFragment},
APIPkgImportScaffoldMarker: {apiImportCodeFragment, ctrlImportCodeFragment},
APISchemeScaffoldMarker: {addschemeCodeFragment},
ReconcilerSetupScaffoldMarker: {webhookSetupCodeFragment},
})
}
Expand Down Expand Up @@ -205,4 +205,4 @@ func main() {
os.Exit(1)
}
}
`, ApiPkgImportScaffoldMarker, ApiSchemeScaffoldMarker, ReconcilerSetupScaffoldMarker)
`, APIPkgImportScaffoldMarker, APISchemeScaffoldMarker, ReconcilerSetupScaffoldMarker)
12 changes: 6 additions & 6 deletions pkg/scaffold/v2/prometheus/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ import (
"sigs.k8s.io/kubebuilder/pkg/scaffold/input"
)

var _ input.File = &PrometheusServiceMonitor{}
var _ input.File = &ServiceMonitor{}

// PrometheusMetricsService scaffolds an issuer CR and a certificate CR
type PrometheusServiceMonitor struct {
// ServiceMonitor scaffolds an issuer CR and a certificate CR
type ServiceMonitor struct {
input.Input
}

// GetInput implements input.File
func (f *PrometheusServiceMonitor) GetInput() (input.Input, error) {
func (f *ServiceMonitor) GetInput() (input.Input, error) {
if f.Path == "" {
f.Path = filepath.Join("config", "prometheus", "monitor.yaml")
}
f.TemplateBody = monitorTemplate
f.TemplateBody = serviceMonitorTemplate
return f.Input, nil
}

const monitorTemplate = `
const serviceMonitorTemplate = `
# Prometheus Monitor Service (Metrics)
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
Expand Down
6 changes: 2 additions & 4 deletions scripts/verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ golangci-lint run --disable-all \
--enable=gosec \
--enable=staticcheck \
--enable=unused \
--enable=gosimple
--enable=gosimple \
--enable=golint \

##todo(camilamacedo86): The following checks requires fixes in the code
# --enable=golint
# --enable=lll
9 changes: 3 additions & 6 deletions test/e2e/utils/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,26 @@ func (k *Kubectl) Apply(inNamespace bool, cmdOptions ...string) (string, error)
ops := append([]string{"apply"}, cmdOptions...)
if inNamespace {
return k.CommandInNamespace(ops...)
} else {
return k.Command(ops...)
}
return k.Command(ops...)
}

// Get is a func to run kubectl get commands
func (k *Kubectl) Get(inNamespace bool, cmdOptions ...string) (string, error) {
ops := append([]string{"get"}, cmdOptions...)
if inNamespace {
return k.CommandInNamespace(ops...)
} else {
return k.Command(ops...)
}
return k.Command(ops...)
}

// Delete is a func to run kubectl delete commands
func (k *Kubectl) Delete(inNamespace bool, cmdOptions ...string) (string, error) {
ops := append([]string{"delete"}, cmdOptions...)
if inNamespace {
return k.CommandInNamespace(ops...)
} else {
return k.Command(ops...)
}
return k.Command(ops...)
}

// Logs is a func to run kubectl logs commands
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/utils/test_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"path/filepath"
"strings"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo" //nolint:golint
)

const certmanagerVersion = "v0.11.0"
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/v1/e2e_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"strings"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/ginkgo" //nolint:golint
. "github.com/onsi/gomega" //nolint:golint

"sigs.k8s.io/kubebuilder/test/e2e/utils"
)
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/v2/e2e_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"strings"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/ginkgo" //nolint:golint
. "github.com/onsi/gomega" //nolint:golint

"sigs.k8s.io/kubebuilder/test/e2e/utils"
)
Expand Down

0 comments on commit 1bbfd06

Please sign in to comment.