Skip to content

Commit

Permalink
Modify golangci.yaml file. Resolve found lint issues.
Browse files Browse the repository at this point in the history
Signed-off-by: Xun Jiang <[email protected]>
  • Loading branch information
Xun Jiang committed Mar 21, 2023
1 parent 086dbd3 commit 648177a
Show file tree
Hide file tree
Showing 31 changed files with 104 additions and 177 deletions.
17 changes: 2 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ else
GIT_TREE_STATE ?= clean
endif

# The default linters used by lint and local-lint
LINTERS ?= "gosec,goconst,gofmt,goimports,unparam"

###
### These variables should not need tweaking.
###
Expand Down Expand Up @@ -221,22 +218,12 @@ endif

lint:
ifneq ($(SKIP_TESTS), 1)
@$(MAKE) shell CMD="-c 'hack/lint.sh $(LINTERS)'"
@$(MAKE) shell CMD="-c 'hack/lint.sh'"
endif

local-lint:
ifneq ($(SKIP_TESTS), 1)
@hack/lint.sh $(LINTERS)
endif

lint-all:
ifneq ($(SKIP_TESTS), 1)
@$(MAKE) shell CMD="-c 'hack/lint.sh $(LINTERS) true'"
endif

local-lint-all:
ifneq ($(SKIP_TESTS), 1)
@hack/lint.sh $(LINTERS) true
@hack/lint.sh
endif

update:
Expand Down
1 change: 1 addition & 0 deletions changelogs/unreleased/6008-blackpiglet
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Modify golangci.yaml file. Resolve found lint issues.
2 changes: 1 addition & 1 deletion config/crd/v1/bases/velero.io_restores.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ spec:
nullable: true
type: array
existingResourcePolicy:
description: ExistingResourcePolicy specifies the restore behaviour
description: ExistingResourcePolicy specifies the restore behavior
for the kubernetes resource to be restored
nullable: true
type: string
Expand Down
2 changes: 1 addition & 1 deletion config/crd/v1/crds/crds.go

Large diffs are not rendered by default.

90 changes: 13 additions & 77 deletions golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ run:
concurrency: 4

# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 5m
timeout: 20m

# exit code when at least one issue was found, default is 1
issues-exit-code: 1

# include test files or not, default is true
tests: true

# list of build tags, all linters use it. Default is empty list.
#build-tags:
# - mytag
Expand Down Expand Up @@ -294,77 +292,26 @@ linters-settings:
# Allow leading comments to be separated with empty liens
allow-separated-leading-comment: false

# The custom section can be used to define linter plugins to be loaded at runtime. See README doc
# for more info.
# custom:
# Each custom linter should have a unique name.
# example:
# The path to the plugin *.so. Can be absolute or local. Required for each custom linter
# path: /path/to/example.so
# The description of the linter. Optional, just for documentation purposes.
# description: This is an example usage of a plugin linter.
# Intended to point to the repo location of the linter. Optional, just for documentation purposes.
# original-url: github.com/golangci/example-linter

linters:
# enable:
# - megacheck
# - govet
# disable:
# - maligned
# - prealloc
disable-all: true
presets:
# - bugs
# - unused
enable:
- bodyclose
- goconst
- gofmt
- goheader
- goimports
- gosec
- misspell
- typecheck
- unparam
- unused
fast: false


issues:
# # List of regexps of issue texts to exclude, empty list by default.
# # But independently from this option we use default exclude patterns,
# # it can be disabled by `exclude-use-default: false`. To list all
# # excluded by default patterns execute `golangci-lint run --help`
# exclude:
# - abcdef
#
# # Excluding configuration per-path, per-linter, per-text and per-source
# exclude-rules:
# # Exclude some linters from running on tests files.
# - path: _test\.go
# linters:
# - gocyclo
# - errcheck
# - dupl
# - gosec
#
# # Exclude known linters from partially hard-vendored code,
# # which is impossible to exclude via "nolint" comments.
# - path: internal/hmac/
# text: "weak cryptographic primitive"
# linters:
# - gosec
#
# # Exclude some staticcheck messages
# - linters:
# - staticcheck
# text: "SA9003:"
#
# # Exclude lll issues for long lines with go:generate
# - linters:
# - lll
# source: "^//go:generate "

# Independently from option `exclude` we use default exclude patterns,
# it can be disabled by this option. To list all
# excluded by default patterns execute `golangci-lint run --help`.
# Default value for this option is true.
exclude-use-default: true

# The default value is false. If set to true exclude and exclude-rules
# regular expressions become case sensitive.
exclude-case-sensitive: false

# The list of ids of default excludes to include or disable. By default it's empty.
include:
- EXC0002 # disable excluding of issues about comments from golint
Expand All @@ -375,19 +322,8 @@ issues:
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0

# Show only new issues: if there are unstaged changes or untracked files,
# only those changes are analyzed, else only changes in HEAD~ are analyzed.
# It's a super-useful option for integration of golangci-lint into existing
# large codebase. It's not practical to fix all existing issues at the moment
# of integration: much better don't allow issues in new code.
# Default is false.
new: false

# Show only new issues created after git revision `REV`
new-from-rev: REV

# Show only new issues created in git patch with set file path.
new-from-patch: path/to/patch/file
# new-from-rev: origin/main

severity:
# Default value is empty string.
Expand Down
11 changes: 1 addition & 10 deletions hack/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

LINTERS=${1:-"gosec,goconst,gofmt,goimports,unparam"}
ALL=${2:-false}

HACK_DIR=$(dirname "${BASH_SOURCE[0]}")

# Printing out cache status
golangci-lint cache status

if [[ $ALL == true ]] ; then
action=""
else
action="-n"
fi

# Enable GL_DEBUG line below for debug messages for golangci-lint
# export GL_DEBUG=loader,gocritic,env
CMD="golangci-lint run -E ${LINTERS} $action -c $HACK_DIR/../golangci.yaml"
CMD="golangci-lint run -c $HACK_DIR/../golangci.yaml"
echo "Running $CMD"

eval $CMD
1 change: 1 addition & 0 deletions hack/release-tools/chk_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

// This regex should match both our GA format (example: v1.4.3) and pre-release formats (v1.2.4-beta.2, v1.5.0-rc.1)
// The following sub-capture groups are defined:
//
// major
// minor
// patch
Expand Down
2 changes: 1 addition & 1 deletion internal/restartabletest/restartable_delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/velero/v1/restore_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ type RestoreSpec struct {
// +optional
Hooks RestoreHooks `json:"hooks,omitempty"`

// ExistingResourcePolicy specifies the restore behaviour for the kubernetes resource to be restored
// ExistingResourcePolicy specifies the restore behavior for the kubernetes resource to be restored
// +optional
// +nullable
ExistingResourcePolicy PolicyType `json:"existingResourcePolicy,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/builder/json_schema_props_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/backuplocation/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func NewDeleteCommand(f client.Factory, use string) *cobra.Command {
# Delete backup storage locations named "backup-location-1" and "backup-location-2".
velero backup-location delete backup-location-1 backup-location-2
# Delete all backup storage locations labelled with "foo=bar".
# Delete all backup storage locations labeled with "foo=bar".
velero backup-location delete --selector foo=bar
# Delete all backup storage locations.
Expand Down
7 changes: 6 additions & 1 deletion pkg/cmd/cli/nodeagent/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,12 @@ func (s *nodeAgentServer) run() {
metricsMux := http.NewServeMux()
metricsMux.Handle("/metrics", promhttp.Handler())
s.logger.Infof("Starting metric server for node agent at address [%s]", s.metricsAddress)
if err := http.ListenAndServe(s.metricsAddress, metricsMux); err != nil {
server := &http.Server{
Addr: s.metricsAddress,
Handler: metricsMux,
ReadTimeout: 3 * time.Second,
}
if err := server.ListenAndServe(); err != nil {
s.logger.Fatalf("Failed to start metric server for node agent at [%s]: %v", s.metricsAddress, err)
}
}()
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/restore/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func NewDeleteCommand(f client.Factory, use string) *cobra.Command {
# Delete restores named "restore-1" and "restore-2".
velero restore delete restore-1 restore-2
# Delete all restores labelled with "foo=bar".
# Delete all restores labeled with "foo=bar".
velero restore delete --selector foo=bar
# Delete all restores.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/schedule/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func NewDeleteCommand(f client.Factory, use string) *cobra.Command {
# Delete schedules named "schedule-1" and "schedule-2".
velero schedule delete schedule-1 schedule-2
# Delete all schedules labelled with "foo=bar".
# Delete all schedules labeled with "foo=bar".
velero schedule delete --selector foo=bar
# Delete all schedules.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/schedule/pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func NewPauseCommand(f client.Factory, use string) *cobra.Command {
# Pause schedules named "schedule-1" and "schedule-2".
velero schedule pause schedule-1 schedule-2
# Pause all schedules labelled with "foo=bar".
# Pause all schedules labeled with "foo=bar".
velero schedule pause --selector foo=bar
# Pause all schedules.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/schedule/unpause.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewUnpauseCommand(f client.Factory, use string) *cobra.Command {
# Unpause schedules named "schedule-1" and "schedule-2".
velero schedule unpause schedule-1 schedule-2
# Unpause all schedules labelled with "foo=bar".
# Unpause all schedules labeled with "foo=bar".
velero schedule unpause --selector foo=bar
# Unpause all schedules.
Expand Down
22 changes: 13 additions & 9 deletions pkg/cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ const (

defaultProfilerAddress = "localhost:6060"

defaultControllerWorkers = 1
// the default TTL for a backup
defaultBackupTTL = 30 * 24 * time.Hour

Expand Down Expand Up @@ -133,11 +132,6 @@ type serverConfig struct {
uploaderType string
}

type controllerRunInfo struct {
controller controller.Interface
numWorkers int
}

func NewCommand(f client.Factory) *cobra.Command {
var (
volumeSnapshotLocations = flag.NewMap().WithKeyValueDelimiter(':')
Expand Down Expand Up @@ -302,7 +296,7 @@ func newServer(f client.Factory, config serverConfig, logger *logrus.Logger) (*s
}

// cancelFunc is not deferred here because if it was, then ctx would immediately
// be cancelled once this function exited, making it useless to any informers using later.
// be canceled once this function exited, making it useless to any informers using later.
// That, in turn, causes the velero server to halt when the first informer tries to use it.
// Therefore, we must explicitly call it on the error paths in this function.
ctx, cancelFunc := context.WithCancel(context.Background())
Expand Down Expand Up @@ -620,7 +614,12 @@ func (s *server) runControllers(defaultVolumeSnapshotLocations map[string]string
metricsMux := http.NewServeMux()
metricsMux.Handle("/metrics", promhttp.Handler())
s.logger.Infof("Starting metric server at address [%s]", s.metricsAddress)
if err := http.ListenAndServe(s.metricsAddress, metricsMux); err != nil {
server := &http.Server{
Addr: s.metricsAddress,
Handler: metricsMux,
ReadTimeout: 3 * time.Second,
}
if err := server.ListenAndServe(); err != nil {
s.logger.Fatalf("Failed to start metric server at [%s]: %v", s.metricsAddress, err)
}
}()
Expand Down Expand Up @@ -967,7 +966,12 @@ func (s *server) runProfiler() {
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)

if err := http.ListenAndServe(s.config.profilerAddress, mux); err != nil {
server := &http.Server{
Addr: s.config.profilerAddress,
Handler: mux,
ReadTimeout: 3 * time.Second,
}
if err := server.ListenAndServe(); err != nil {
s.logger.WithError(errors.WithStack(err)).Error("error running profiler http server")
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/backup_deletion_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,14 @@ func (r *backupDeletionReconciler) patchBackup(ctx context.Context, backup *vele
// Record original json
oldData, err := json.Marshal(backup)
if err != nil {
return nil, errors.Wrap(err, "error marshalling original Backup")
return nil, errors.Wrap(err, "error marshaling original Backup")
}

newBackup := backup.DeepCopy()
mutate(newBackup)
newData, err := json.Marshal(newBackup)
if err != nil {
return nil, errors.Wrap(err, "error marshalling updated Backup")
return nil, errors.Wrap(err, "error marshaling updated Backup")
}
patchBytes, err := jsonpatch.CreateMergePatch(oldData, newData)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/restic/exec_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func GetSnapshotID(snapshotIdCmd *Command) (string, error) {

var snapshots []snapshotID
if err := json.Unmarshal([]byte(stdout), &snapshots); err != nil {
return "", errors.Wrap(err, "error unmarshalling restic snapshots result")
return "", errors.Wrap(err, "error unmarshaling restic snapshots result")
}

if len(snapshots) != 1 {
Expand Down Expand Up @@ -260,7 +260,7 @@ func getSnapshotSize(repoIdentifier, passwordFile, caCertFile, snapshotID string
}

if err := json.Unmarshal([]byte(stdout), &snapshotStats); err != nil {
return 0, errors.Wrapf(err, "error unmarshalling restic stats result, stdout=%s", stdout)
return 0, errors.Wrapf(err, "error unmarshaling restic stats result, stdout=%s", stdout)
}

return snapshotStats.TotalSize, nil
Expand Down
5 changes: 3 additions & 2 deletions pkg/restore/change_pvc_node_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ func (p *ChangePVCNodeSelectorAction) AppliesTo() (velero.ResourceSelector, erro
}

// Execute updates the pvc's selected-node annotation:
// a) if node mapping found in the config map for the plugin
// b) if node mentioned in annotation doesn't exist
//
// a) if node mapping found in the config map for the plugin
// b) if node mentioned in annotation doesn't exist
func (p *ChangePVCNodeSelectorAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) {
p.logger.Info("Executing ChangePVCNodeSelectorAction")
defer p.logger.Info("Done executing ChangePVCNodeSelectorAction")
Expand Down
Loading

0 comments on commit 648177a

Please sign in to comment.