Skip to content

Commit

Permalink
Merge pull request #369 from jkhelil/linter
Browse files Browse the repository at this point in the history
lint with golangci-lint
  • Loading branch information
tomaszsek authored May 6, 2020
2 parents eb8b2e3 + 128c97b commit 1eeca8e
Show file tree
Hide file tree
Showing 46 changed files with 394 additions and 181 deletions.
29 changes: 29 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
run:
deadline: 10m
linters-settings:
errcheck:
check-blank: false
ignore: fmt:.*,io/ioutil:^Read.*,Write

linters:
enable-all: true
disable:
- funlen
- gocognit
- godox
- gomnd
- gochecknoglobals
- gochecknoinits
- lll
- prealloc
- wsl
- gocyclo
- scopelint
- dupl
- gosec
- maligned
- testpackage
- goerr113
- nakedret
- nestif
- godot
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ fmt: ## Verifies all files have been `gofmt`ed
@go fmt $(PACKAGES)

.PHONY: lint
HAS_GOLINT := $(shell which golint)
HAS_GOLINT := $(shell which golangci-lint)
lint: ## Verifies `golint` passes
@echo "+ $@"
ifndef HAS_GOLINT
go get -u golang.org/x/lint/golint
go get github.com/golangci/golangci-lint/cmd/[email protected]
endif
@golint $(PACKAGES)
@golangci-lint run

.PHONY: goimports
HAS_GOIMPORTS := $(shell which goimports)
Expand Down
4 changes: 2 additions & 2 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (
"github.com/jenkinsci/kubernetes-operator/pkg/apis"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/notifications"
e "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/notifications/event"
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources"
"github.com/jenkinsci/kubernetes-operator/pkg/event"
"github.com/jenkinsci/kubernetes-operator/pkg/log"
"github.com/jenkinsci/kubernetes-operator/version"
Expand Down Expand Up @@ -119,7 +119,7 @@ func main() {
fatal(errors.Wrap(err, "failed to create Kubernetes client set"), *debug)
}

if( resources.IsRouteAPIAvailable(clientSet) ) {
if resources.IsRouteAPIAvailable(clientSet) {
log.Log.Info("Route API found: Route creation will be performed")
}
c := make(chan e.Event)
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ require (
github.com/go-logr/zapr v0.1.1
github.com/go-openapi/spec v0.19.4
github.com/golang/mock v1.3.1
github.com/golangci/golangci-lint v1.26.0 // indirect
github.com/mailgun/mailgun-go/v3 v3.6.0
github.com/openshift/api v3.9.1-0.20190924102528-32369d4db2ad+incompatible
github.com/operator-framework/operator-sdk v0.17.0
github.com/pkg/errors v0.9.1
github.com/robfig/cron v1.2.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.4.0
github.com/stretchr/testify v1.5.1
go.uber.org/zap v1.14.1
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b
Expand Down
178 changes: 178 additions & 0 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/pkg/errors"
)

// Render executes a parsed template (go-template) with configuration from data
// Render executes a parsed template (go-template) with configuration from data.
func Render(template *template.Template, data interface{}) (string, error) {
var buffer bytes.Buffer
if err := template.Execute(&buffer, data); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions internal/try/until.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
time2 "github.com/jenkinsci/kubernetes-operator/internal/time"
)

// ErrTimeout is used when the set timeout has been reached
// ErrTimeout is used when the set timeout has been reached.
type ErrTimeout struct {
text string
cause error
Expand All @@ -18,7 +18,7 @@ func (e *ErrTimeout) Error() string {
return fmt.Sprintf("%s: %s", e.text, e.cause.Error())
}

// Cause returns the error that caused ErrTimeout
// Cause returns the error that caused ErrTimeout.
func (e *ErrTimeout) Cause() error {
return e.cause
}
Expand All @@ -28,7 +28,7 @@ func (e *ErrTimeout) Format(s fmt.State, verb rune) {
errors.Format(e.cause, s, verb)
}

// Until keeps trying until timeout or there is a result or an error
// Until keeps trying until timeout or there is a result or an error.
func Until(something func() (end bool, err error), tick, timeout time.Duration) error {
counter := 0
tickChan := time2.Every(tick)
Expand All @@ -42,7 +42,7 @@ func Until(something func() (end bool, err error), tick, timeout time.Duration)
if end {
return err
}
counter = counter + 1
counter++
case <-timeoutChan:
return &ErrTimeout{
text: fmt.Sprintf("timed out after: %s, tries: %d", timeout, counter),
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"k8s.io/apimachinery/pkg/runtime"
)

// AddToSchemes may be used to add all resources defined in the project to a Scheme
// AddToSchemes may be used to add all resources defined in the project to a Scheme.
var AddToSchemes runtime.SchemeBuilder

// AddToScheme adds all Resources to the Scheme
// AddToScheme adds all Resources to the Scheme.
func AddToScheme(s *runtime.Scheme) error {
return AddToSchemes.AddToScheme(s)
}
Expand Down
46 changes: 23 additions & 23 deletions pkg/apis/jenkins/v1alpha2/jenkins_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// JenkinsSpec defines the desired state of the Jenkins
// JenkinsSpec defines the desired state of the Jenkins.
// +k8s:openapi-gen=true
type JenkinsSpec struct {
// Master represents Jenkins master pod properties and Jenkins plugins.
Expand Down Expand Up @@ -92,7 +92,7 @@ type ServiceAccount struct {
Annotations map[string]string `json:"annotations,omitempty"`
}

// NotificationLevel defines the level of a Notification
// NotificationLevel defines the level of a Notification.
type NotificationLevel string

const (
Expand All @@ -103,7 +103,7 @@ const (
NotificationLevelInfo NotificationLevel = "info"
)

// Notification is a service configuration used to send notifications about Jenkins status
// Notification is a service configuration used to send notifications about Jenkins status.
type Notification struct {
LoggingLevel NotificationLevel `json:"level"`
Verbose bool `json:"verbose"`
Expand All @@ -114,13 +114,13 @@ type Notification struct {
SMTP *SMTP `json:"smtp,omitempty"`
}

// Slack is handler for Slack notification channel
// Slack is handler for Slack notification channel.
type Slack struct {
// The web hook URL to Slack App
WebHookURLSecretKeySelector SecretKeySelector `json:"webHookURLSecretKeySelector"`
}

// SMTP is handler for sending emails via this protocol
// SMTP is handler for sending emails via this protocol.
type SMTP struct {
UsernameSecretKeySelector SecretKeySelector `json:"usernameSecretKeySelector"`
PasswordSecretKeySelector SecretKeySelector `json:"passwordSecretKeySelector"`
Expand All @@ -131,13 +131,13 @@ type SMTP struct {
To string `json:"to"`
}

// MicrosoftTeams is handler for Microsoft MicrosoftTeams notification channel
// MicrosoftTeams is handler for Microsoft MicrosoftTeams notification channel.
type MicrosoftTeams struct {
// The web hook URL to MicrosoftTeams App
WebHookURLSecretKeySelector SecretKeySelector `json:"webHookURLSecretKeySelector"`
}

// Mailgun is handler for Mailgun email service notification channel
// Mailgun is handler for Mailgun email service notification channel.
type Mailgun struct {
Domain string `json:"domain"`
APIKeySecretKeySelector SecretKeySelector `json:"apiKeySecretKeySelector"`
Expand All @@ -153,7 +153,7 @@ type SecretKeySelector struct {
Key string `json:"key"`
}

// Container defines Kubernetes container attributes
// Container defines Kubernetes container attributes.
type Container struct {
// Name of the container specified as a DNS_LABEL.
// Each container in a pod must have a unique name (DNS_LABEL).
Expand Down Expand Up @@ -244,7 +244,7 @@ type Container struct {
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
}

// Plugin defines Jenkins plugin
// Plugin defines Jenkins plugin.
type Plugin struct {
// Name is the name of Jenkins plugin
Name string `json:"name"`
Expand All @@ -255,7 +255,7 @@ type Plugin struct {
}

// JenkinsMaster defines the Jenkins master pod attributes and plugins,
// every single change requires a Jenkins master pod restart
// every single change requires a Jenkins master pod restart.
type JenkinsMaster struct {
// Annotations is an unstructured key value map stored with a resource that may be
// set by external tools to store and retrieve arbitrary metadata. They are not
Expand Down Expand Up @@ -510,14 +510,14 @@ type Jenkins struct {

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// JenkinsList contains a list of Jenkins
// JenkinsList contains a list of Jenkins.
type JenkinsList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Jenkins `json:"items"`
}

// JenkinsCredentialType defines type of Jenkins credential used to seed job mechanism
// JenkinsCredentialType defines type of Jenkins credential used to seed job mechanism.
type JenkinsCredentialType string

const (
Expand All @@ -531,7 +531,7 @@ const (
ExternalCredentialType JenkinsCredentialType = "external"
)

// AllowedJenkinsCredentialMap contains all allowed Jenkins credentials types
// AllowedJenkinsCredentialMap contains all allowed Jenkins credentials types.
var AllowedJenkinsCredentialMap = map[string]string{
string(NoJenkinsCredentialCredentialType): "",
string(BasicSSHCredentialType): "",
Expand All @@ -540,7 +540,7 @@ var AllowedJenkinsCredentialMap = map[string]string{
}

// SeedJob defines configuration for seed job
// More info: https://github.com/jenkinsci/kubernetes-operator/blob/master/docs/getting-started.md#configure-seed-jobs-and-pipelines
// More info: https://github.com/jenkinsci/kubernetes-operator/blob/master/docs/getting-started.md#configure-seed-jobs-and-pipelines.
type SeedJob struct {
// ID is the unique seed job name
ID string `json:"id,omitempty"`
Expand Down Expand Up @@ -598,13 +598,13 @@ type SeedJob struct {
UnstableOnDeprecation bool `json:"unstableOnDeprecation"`
}

// Handler defines a specific action that should be taken
// Handler defines a specific action that should be taken.
type Handler struct {
// Exec specifies the action to take.
Exec *corev1.ExecAction `json:"exec,omitempty"`
}

// Backup defines configuration of Jenkins backup
// Backup defines configuration of Jenkins backup.
type Backup struct {
// ContainerName is the container name responsible for backup operation
ContainerName string `json:"containerName"`
Expand All @@ -620,7 +620,7 @@ type Backup struct {
MakeBackupBeforePodDeletion bool `json:"makeBackupBeforePodDeletion"`
}

// Restore defines configuration of Jenkins backup restore operation
// Restore defines configuration of Jenkins backup restore operation.
type Restore struct {
// ContainerName is the container name responsible for restore backup operation
ContainerName string `json:"containerName"`
Expand All @@ -633,7 +633,7 @@ type Restore struct {
RecoveryOnce uint64 `json:"recoveryOnce,omitempty"`
}

// AppliedGroovyScript is the applied groovy script in Jenkins by the operator
// AppliedGroovyScript is the applied groovy script in Jenkins by the operator.
type AppliedGroovyScript struct {
// ConfigurationType is the name of the configuration type(base-groovy, user-groovy, user-casc)
ConfigurationType string `json:"configurationType"`
Expand All @@ -645,28 +645,28 @@ type AppliedGroovyScript struct {
Hash string `json:"hash"`
}

// SecretRef is reference to Kubernetes secret
// SecretRef is reference to Kubernetes secret.
type SecretRef struct {
Name string `json:"name"`
}

// ConfigMapRef is reference to Kubernetes ConfigMap
// ConfigMapRef is reference to Kubernetes ConfigMap.
type ConfigMapRef struct {
Name string `json:"name"`
}

// Customization defines configuration of Jenkins customization
// Customization defines configuration of Jenkins customization.
type Customization struct {
Secret SecretRef `json:"secret"`
Configurations []ConfigMapRef `json:"configurations"`
}

// GroovyScripts defines configuration of Jenkins customization via groovy scripts
// GroovyScripts defines configuration of Jenkins customization via groovy scripts.
type GroovyScripts struct {
Customization `json:",inline"`
}

// ConfigurationAsCode defines configuration of Jenkins customization via Configuration as Code Jenkins plugin
// ConfigurationAsCode defines configuration of Jenkins customization via Configuration as Code Jenkins plugin.
type ConfigurationAsCode struct {
Customization `json:",inline"`
}
Loading

0 comments on commit 1eeca8e

Please sign in to comment.