diff --git a/.github/workflows/gochecks.yml b/.github/workflows/gochecks.yml index da9c7bd1..c1edf859 100644 --- a/.github/workflows/gochecks.yml +++ b/.github/workflows/gochecks.yml @@ -17,7 +17,7 @@ jobs: - name: Install dependencies run: | go version - go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.52.2 + go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0 - name: Run golangci-lint run: | diff --git a/.golangci.yaml b/.golangci.yaml index e2fe3949..3d730bbf 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,12 +1,4 @@ linters-settings: - depguard: - list-type: denylist - packages: - # logging is allowed only by logutils.Log, logrus - # is allowed to use only in logutils package - - github.com/sirupsen/logrus - packages-with-error-message: - - github.com/sirupsen/logrus: "logging is allowed only by logutils.Log" dupl: threshold: 100 funlen: @@ -31,7 +23,7 @@ linters-settings: min-complexity: 15 goimports: local-prefixes: github.com/golangci/golangci-lint - gomnd: + mnd: # don't include the "operation" and "assign" checks: - argument @@ -47,7 +39,9 @@ linters-settings: - strings.SplitN govet: - check-shadowing: true + enable-all: true + disable: + - fieldalignment # a lot of manual overhead for reduced readability and adding a linter "gotcha" settings: printf: funcs: @@ -71,12 +65,10 @@ linters-settings: linters: disable-all: true enable: - - bodyclose - - depguard + - copyloopvar - dogsled - dupl - errcheck - - exportloopref - funlen - gochecknoinits - goconst @@ -84,7 +76,6 @@ linters: - gocyclo - gofmt - goimports - - gomnd - goprintffuncname - gosec - gosimple @@ -92,6 +83,7 @@ linters: - ineffassign - lll - misspell + - mnd - nakedret - noctx - nolintlint @@ -105,6 +97,8 @@ linters: - whitespace # don't enable: + # - bodyclose + # - depguard # - asciicheck # - scopelint # - gochecknoglobals @@ -137,6 +131,8 @@ issues: - errcheck - dupl - gosec - + - lll + - goconst + - dogsled run: - timeout: 5m + timeout: 5m \ No newline at end of file diff --git a/builder/vultr/config.go b/builder/vultr/config.go index b131f3e4..adcf5312 100644 --- a/builder/vultr/config.go +++ b/builder/vultr/config.go @@ -14,6 +14,10 @@ import ( "github.com/hashicorp/packer-plugin-sdk/template/interpolate" ) +const ( + defaultStateTimeout = 10 * time.Minute +) + // Config provides the config struct type Config struct { common.PackerConfig `mapstructure:",squash"` @@ -121,7 +125,7 @@ func (c *Config) Prepare(raws ...interface{}) error { //nolint:gocyclo } if c.RawStateTimeout == "" { - c.stateTimeout = 10 * time.Minute + c.stateTimeout = defaultStateTimeout } else { if stateTimeout, err := time.ParseDuration(c.RawStateTimeout); err == nil { c.stateTimeout = stateTimeout diff --git a/builder/vultr/step_create_iso.go b/builder/vultr/step_create_iso.go index 839e88d7..36e74f47 100644 --- a/builder/vultr/step_create_iso.go +++ b/builder/vultr/step_create_iso.go @@ -20,7 +20,7 @@ func (s *stepCreateISO) Run(ctx context.Context, state multistep.StateBag) multi c := state.Get("config").(*Config) ui := state.Get("ui").(packer.Ui) - if len(c.ISOURL) > 0 { + if c.ISOURL != "" { ui.Say("Creating ISO in Vultr account...") isoReq := &govultr.ISOReq{ diff --git a/builder/vultr/wait.go b/builder/vultr/wait.go index d8d3ec8a..33172f89 100644 --- a/builder/vultr/wait.go +++ b/builder/vultr/wait.go @@ -9,6 +9,11 @@ import ( "github.com/vultr/govultr/v3" ) +const ( + sleepDurationSeconds = 3 + stateTimeoutMinutes = 10 +) + func waitForISOState(state, isoID string, client *govultr.Client, timeout time.Duration) error { //nolint:dupl done := make(chan struct{}) defer close(done) @@ -30,7 +35,7 @@ func waitForISOState(state, isoID string, client *govultr.Client, timeout time.D return } - time.Sleep(3 * time.Second) + time.Sleep(sleepDurationSeconds * time.Second) select { case <-done: @@ -69,7 +74,7 @@ func waitForServerState(state, power, serverID string, client *govultr.Client, t return } - time.Sleep(3 * time.Second) + time.Sleep(sleepDurationSeconds * time.Second) // Verify we shouldn't exit select { @@ -111,7 +116,7 @@ func waitForSnapshotState(state, snapshotID string, client *govultr.Client, time return } - time.Sleep(3 * time.Second) + time.Sleep(sleepDurationSeconds * time.Second) // Verify we shouldn't exit select {