From 7c9599fdd5b4cb9d26ff235d41479cfe56f4f3ba Mon Sep 17 00:00:00 2001
From: Kayla McKay <39921134+kaymckay@users.noreply.github.com>
Date: Tue, 8 Mar 2022 10:51:38 -0600
Subject: [PATCH 1/2] chore: update Golangci config & clean repo (#282)
* add new yml config
* lint wsl
* replace golint fals pos with revive false pos
* remove nolintlints
* lint funlen
* noctx
* govet -> goheader
* errorlint
* remove lll false pos, lint contextcheck
* lint dupl
* lint nilerr
* remove false positives
* clean
* remove changelog code
---
.chglog/CHANGELOG.tpl.md | 30 -----
.chglog/config.yml | 28 ----
.github/workflows/release.yml | 53 --------
.golangci.yml | 172 ++++++++++++++-----------
cmd/vela-worker/exec.go | 3 +-
cmd/vela-worker/operate.go | 3 +-
cmd/vela-worker/register.go | 9 +-
cmd/vela-worker/run.go | 2 -
cmd/vela-worker/server.go | 2 +
cmd/vela-worker/start.go | 6 +-
executor/context.go | 2 +-
executor/context_test.go | 6 +-
executor/linux/build.go | 8 +-
executor/linux/build_test.go | 2 +-
executor/linux/linux.go | 2 +-
executor/linux/secret.go | 5 +-
executor/linux/service.go | 4 -
executor/linux/stage.go | 1 +
executor/linux/step.go | 5 +-
executor/linux/step_test.go | 1 +
executor/local/build.go | 4 +-
executor/local/local.go | 2 +-
executor/local/step_test.go | 2 +-
internal/service/environment.go | 2 -
internal/service/snapshot.go | 2 -
internal/service/upload.go | 4 -
internal/step/environment.go | 2 -
internal/step/snapshot.go | 4 -
internal/step/upload.go | 4 -
internal/volume/volume.go | 2 -
mock/docker/config.go | 1 +
mock/docker/container.go | 24 ++--
mock/docker/docker.go | 1 -
mock/docker/image.go | 6 +-
mock/docker/network.go | 8 +-
mock/docker/secret.go | 1 +
mock/docker/volume.go | 12 +-
router/middleware/executor/executor.go | 1 +
router/middleware/header.go | 5 +-
router/middleware/logger.go | 1 +
router/middleware/perm/perm.go | 2 +
router/middleware/token/token_test.go | 5 +-
router/pipeline.go | 2 +-
runtime/context.go | 2 +-
runtime/context_test.go | 6 +-
runtime/docker/container.go | 4 -
runtime/docker/docker.go | 4 +-
runtime/kubernetes/build.go | 9 ++
runtime/kubernetes/build_test.go | 3 +-
runtime/kubernetes/container.go | 12 +-
runtime/kubernetes/image.go | 1 -
runtime/kubernetes/kubernetes.go | 5 +-
runtime/kubernetes/network.go | 1 -
version/version.go | 4 +-
54 files changed, 189 insertions(+), 303 deletions(-)
delete mode 100755 .chglog/CHANGELOG.tpl.md
delete mode 100755 .chglog/config.yml
delete mode 100644 .github/workflows/release.yml
diff --git a/.chglog/CHANGELOG.tpl.md b/.chglog/CHANGELOG.tpl.md
deleted file mode 100755
index 60a67d5bc..000000000
--- a/.chglog/CHANGELOG.tpl.md
+++ /dev/null
@@ -1,30 +0,0 @@
-{{ range .Versions }}
-
-## {{ if .Tag.Previous }}[{{ .Tag.Name }}]({{ $.Info.RepositoryURL }}/compare/{{ .Tag.Previous.Name }}...{{ .Tag.Name }}){{ else }}{{ .Tag.Name }}{{ end }} ({{ datetime "2006-01-02" .Tag.Date }})
-
-{{ range .CommitGroups -}}
-### {{ .Title }}
-
-{{ range .Commits -}}
-* {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
-{{ end }}
-{{ end -}}
-
-{{- if .RevertCommits -}}
-### Reverts
-
-{{ range .RevertCommits -}}
-* {{ .Revert.Header }}
-{{ end }}
-{{ end -}}
-
-{{- if .NoteGroups -}}
-{{ range .NoteGroups -}}
-### {{ .Title }}
-
-{{ range .Notes }}
-{{ .Body }}
-{{ end }}
-{{ end -}}
-{{ end -}}
-{{ end -}}
\ No newline at end of file
diff --git a/.chglog/config.yml b/.chglog/config.yml
deleted file mode 100755
index febd8d720..000000000
--- a/.chglog/config.yml
+++ /dev/null
@@ -1,28 +0,0 @@
-style: github
-template: CHANGELOG.tpl.md
-info:
- title: CHANGELOG
- repository_url: https://github.com/go-vela/worker
-options:
- commits:
- # filters:
- # Type:
- # - feat
- # - fix
- # - perf
- # - refactor
- commit_groups:
- # title_maps:
- # feat: Features
- # fix: Bug Fixes
- # perf: Performance Improvements
- # refactor: Code Refactoring
- header:
- pattern: "^(\\w*)(?:\\(([\\w\\$\\.\\-\\*\\s]*)\\))?\\:\\s(.*)$"
- pattern_maps:
- - Type
- - Scope
- - Subject
- notes:
- keywords:
- - BREAKING CHANGE
\ No newline at end of file
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
deleted file mode 100644
index 80904f913..000000000
--- a/.github/workflows/release.yml
+++ /dev/null
@@ -1,53 +0,0 @@
-# name of the action
-name: release
-
-# trigger on push events with `v*` in tag
-# ignore push events with `v*-rc*` in tag
-on:
- push:
- tags:
- - 'v*'
- - '!v*-rc*'
-
-# pipeline to execute
-jobs:
- release:
- runs-on: ubuntu-latest
- container:
- image: golang:1.17
- steps:
- - name: clone
- uses: actions/checkout@v3
-
- - name: tags
- run: |
- git fetch --tags
-
- - name: version
- id: version
- run: |
- echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/}
-
- - name: install
- run: |
- go get github.com/git-chglog/git-chglog/cmd/git-chglog
- go get github.com/github-release/github-release
-
- - name: changelog
- run: |
- # https://github.com/git-chglog/git-chglog#git-chglog
- $(go env GOPATH)/bin/git-chglog \
- -o $GITHUB_WORKSPACE/CHANGELOG.md \
- ${{ steps.version.outputs.VERSION }}
-
- - name: release
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: |
- # https://github.com/github-release/github-release#how-to-use
- $(go env GOPATH)/bin/github-release edit \
- --user go-vela \
- --repo worker \
- --tag ${{ steps.version.outputs.VERSION }} \
- --name ${{ steps.version.outputs.VERSION }} \
- --description "$(cat $GITHUB_WORKSPACE/CHANGELOG.md)"
diff --git a/.golangci.yml b/.golangci.yml
index 85c783b6e..97b6d15a3 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -28,27 +28,16 @@ linters-settings:
# https://github.com/ultraware/funlen
funlen:
- lines: 100
- statements: 50
+ # accounting for comments
+ lines: 160
+ statements: 70
- # https://github.com/golang/lint
- golint:
- min-confidence: 0
-
- # https://github.com/tommy-muehle/go-mnd
- gomnd:
- settings:
- mnd:
- # don't include the "operation" and "assign"
- checks: argument,case,condition,return
-
- # https://github.com/walle/lll
- lll:
- line-length: 100
-
- # https://github.com/mdempsky/maligned
- maligned:
- suggest-new: true
+ # https://github.com/denis-tingaikin/go-header
+ goheader:
+ template: |-
+ Copyright (c) {{ YEAR }} Target Brands, Inc. All rights reserved.
+
+ Use of this source code is governed by the LICENSE file in this repository.
# https://github.com/client9/misspell
misspell:
@@ -56,10 +45,10 @@ linters-settings:
# https://github.com/golangci/golangci-lint/blob/master/pkg/golinters/nolintlint
nolintlint:
- allow-leading-space: true # allow non-"machine-readable" format (ie. with leading space)
- allow-unused: false # allow nolint directives that don't address a linting issue
- require-explanation: true # require an explanation for nolint directives
- require-specific: true # require nolint directives to be specific about which linter is being skipped
+ allow-leading-space: true # allow non-"machine-readable" format (ie. with leading space)
+ allow-unused: false # allow nolint directives that don't address a linting issue
+ require-explanation: true # require an explanation for nolint directives
+ require-specific: true # require nolint directives to be specific about which linter is being skipped
# This section provides the configuration for which linters
# golangci will execute. Several of them were disabled by
@@ -70,58 +59,91 @@ linters:
# enable a specific set of linters to run
enable:
- - bodyclose
- - deadcode # enabled by default
- - dupl
- - errcheck # enabled by default
- - funlen
- - goconst
- - gocyclo
- - godot
- - gofmt
- - goimports
- - golint
- - gomnd
- - goprintffuncname
- - gosec
- - gosimple # enabled by default
- - govet # enabled by default
- - ineffassign # enabled by default
- - lll
- - maligned
- - misspell
- - nakedret
- - nolintlint
- - staticcheck # enabled by default
- - structcheck # enabled by default
- - stylecheck
- - typecheck # enabled by default
- - unconvert
- - unparam
- - unused # enabled by default
- - varcheck # enabled by default
- - whitespace
-
+ - bidichk # checks for dangerous unicode character sequences
+ - bodyclose # checks whether HTTP response body is closed successfully
+ - contextcheck # check the function whether use a non-inherited context
+ - deadcode # finds unused code
+ - dupl # code clone detection
+ - errcheck # checks for unchecked errors
+ - errorlint # find misuses of errors
+ - exportloopref # check for exported loop vars
+ - funlen # detects long functions
+ - goconst # finds repeated strings that could be replaced by a constant
+ - gocyclo # computes and checks the cyclomatic complexity of functions
+ - godot # checks if comments end in a period
+ - gofmt # checks whether code was gofmt-ed
+ - goheader # checks is file header matches to pattern
+ - goimports # fixes imports and formats code in same style as gofmt
+ - gomoddirectives # manage the use of 'replace', 'retract', and 'excludes' directives in go.mod
+ - goprintffuncname # checks that printf-like functions are named with f at the end
+ - gosec # inspects code for security problems
+ - gosimple # linter that specializes in simplifying a code
+ - govet # reports suspicious constructs, ex. Printf calls whose arguments don't align with the format string
+ - ineffassign # detects when assignments to existing variables aren't used
+ - makezero # finds slice declarations with non-zero initial length
+ - misspell # finds commonly misspelled English words in comments
+ - nakedret # finds naked returns in functions greater than a specified function length
+ - nilerr # finds the code that returns nil even if it checks that the error is not nil
+ - noctx # noctx finds sending http request without context.Context
+ - nolintlint # reports ill-formed or insufficient nolint directives
+ - revive # linter for go
+ - staticcheck # applies static analysis checks, go vet on steroids
+ - structcheck # finds unused struct fields
+ - stylecheck # replacement for golint
+ - tenv # analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
+ - typecheck # parses and type-checks go code, like the front-end of a go compiler
+ - unconvert # remove unnecessary type conversions
+ - unparam # reports unused function parameters
+ - unused # checks for unused constants, variables, functions and types
+ - varcheck # finds unused global variables and constants
+ - whitespace # detects leading and trailing whitespace
+ - wsl # forces code to use empty lines
+
# static list of linters we know golangci can run but we've
# chosen to leave disabled for now
- # - asciicheck
- # - depguard
- # - dogsled
- # - exhaustive
- # - gochecknoinits
- # - gochecknoglobals
- # - gocognit
- # - gocritic
- # - godox
- # - goerr113
- # - interfacer
- # - nestif
- # - noctx
- # - prealloc
- # - rowserrcheck
- # - scopelint
- # - testpackage
- # - wsl
+ # - asciicheck - non-critical
+ # - cyclop - unused complexity metric
+ # - depguard - unused
+ # - dogsled - blanks allowed
+ # - durationcheck - unused
+ # - errname - unused
+ # - exhaustive - unused
+ # - exhaustivestruct - style preference
+ # - forbidigo - unused
+ # - forcetypeassert - unused
+ # - gci - use goimports
+ # - gochecknoinits - unused
+ # - gochecknoglobals - global variables allowed
+ # - gocognit - unused complexity metric
+ # - gocritic - style preference
+ # - godox - to be used in the future
+ # - goerr113 - to be used in the future
+ # - golint - archived, replaced with revive
+ # - gofumpt - use gofmt
+ # - gomnd - get too many false-positives
+ # - gomodguard - unused
+ # - ifshort - use both styles
+ # - ireturn - allow interfaces to be returned
+ # - importas - want flexibility with naming
+ # - lll - not too concerned about line length
+ # - interfacer - archived
+ # - nestif - non-critical
+ # - nilnil - style preference
+ # - nlreturn - style preference
+ # - maligned - archived, replaced with govet 'fieldalignment'
+ # - paralleltest - false-positives
+ # - prealloc - don't use
+ # - predeclared - unused
+ # - promlinter - style preference
+ # - rowserrcheck - unused
+ # - scopelint - deprecated - replaced with exportloopref
+ # - sqlclosecheck - unused
+ # - tagliatelle - use a mix of variable naming
+ # - testpackage - don't use this style of testing
+ # - thelper - false-positives
+ # - varnamelen - unused
+ # - wastedassign - duplicate functionality
+ # - wrapcheck - style preference
# This section provides the configuration for how golangci
# will report the issues it finds.
@@ -135,5 +157,3 @@ issues:
- funlen
- goconst
- gocyclo
- - gomnd
- - lll
diff --git a/cmd/vela-worker/exec.go b/cmd/vela-worker/exec.go
index 50d70f9d5..4f9d0c14b 100644
--- a/cmd/vela-worker/exec.go
+++ b/cmd/vela-worker/exec.go
@@ -17,8 +17,7 @@ import (
// exec is a helper function to poll the queue
// and execute Vela pipelines for the Worker.
-//
-// nolint:funlen // ignore function length due to comments and log messages
+// nolint: nilerr // ignore returning nil - don't want to crash worker
func (w *Worker) exec(index int) error {
var err error
diff --git a/cmd/vela-worker/operate.go b/cmd/vela-worker/operate.go
index 53a522d69..4d7b91969 100644
--- a/cmd/vela-worker/operate.go
+++ b/cmd/vela-worker/operate.go
@@ -19,7 +19,6 @@ import (
// operate is a helper function to initiate all
// subprocesses for the operator to poll the
// queue and execute Vela pipelines.
-// nolint: funlen // ignore function length
func (w *Worker) operate(ctx context.Context) error {
var err error
@@ -63,7 +62,6 @@ func (w *Worker) operate(ctx context.Context) error {
// if unable to update the worker, log the error but allow the worker to continue running
if err != nil {
- // nolint: lll // ignore long line length due to error message
logrus.Errorf("unable to update worker %s on the server: %v", registryWorker.GetHostname(), err)
}
@@ -107,6 +105,7 @@ func (w *Worker) operate(ctx context.Context) error {
return nil
default:
// exec operator subprocess to poll and execute builds
+ // nolint: contextcheck // ignore passing context
err = w.exec(id)
if err != nil {
// log the error received from the executor
diff --git a/cmd/vela-worker/register.go b/cmd/vela-worker/register.go
index e147b83a5..8c40d9b24 100644
--- a/cmd/vela-worker/register.go
+++ b/cmd/vela-worker/register.go
@@ -16,9 +16,10 @@ import (
func (w *Worker) checkIn(config *library.Worker) error {
// check to see if the worker already exists in the database
logrus.Infof("retrieving worker %s from the server", config.GetHostname())
+
_, resp, err := w.VelaClient.Worker.Get(config.GetHostname())
if err != nil {
- respErr := fmt.Errorf("unable to retrieve worker %s from the server: %v", config.GetHostname(), err)
+ respErr := fmt.Errorf("unable to retrieve worker %s from the server: %w", config.GetHostname(), err)
if resp == nil {
return respErr
}
@@ -32,9 +33,10 @@ func (w *Worker) checkIn(config *library.Worker) error {
// if we were able to GET the worker, update it
logrus.Infof("checking worker %s into the server", config.GetHostname())
+
_, _, err = w.VelaClient.Worker.Update(config.GetHostname(), config)
if err != nil {
- return fmt.Errorf("unable to update worker %s on the server: %v", config.GetHostname(), err)
+ return fmt.Errorf("unable to update worker %s on the server: %w", config.GetHostname(), err)
}
return nil
@@ -43,10 +45,11 @@ func (w *Worker) checkIn(config *library.Worker) error {
// register is a helper function to register the worker with the server.
func (w *Worker) register(config *library.Worker) error {
logrus.Infof("worker %s not found, registering it with the server", config.GetHostname())
+
_, _, err := w.VelaClient.Worker.Add(config)
if err != nil {
// log the error instead of returning so the operation doesn't block worker deployment
- return fmt.Errorf("unable to register worker %s with the server: %v", config.GetHostname(), err)
+ return fmt.Errorf("unable to register worker %s with the server: %w", config.GetHostname(), err)
}
// successfully added the worker so return nil
diff --git a/cmd/vela-worker/run.go b/cmd/vela-worker/run.go
index e519531de..76ecb8a84 100644
--- a/cmd/vela-worker/run.go
+++ b/cmd/vela-worker/run.go
@@ -23,8 +23,6 @@ import (
// run executes the worker based
// off the configuration provided.
-//
-// nolint: funlen // ignore function length due to comments
func run(c *cli.Context) error {
// set log format for the worker
switch c.String("log.format") {
diff --git a/cmd/vela-worker/server.go b/cmd/vela-worker/server.go
index 876c8064d..ee79aa952 100644
--- a/cmd/vela-worker/server.go
+++ b/cmd/vela-worker/server.go
@@ -47,6 +47,7 @@ func (w *Worker) server() (http.Handler, bool) {
if err != nil {
logrus.Fatalf("expecting certificate file at %s, got %v", w.Config.Certificate.Cert, err)
}
+
_, err = os.Stat(w.Config.Certificate.Key)
if err != nil {
logrus.Fatalf("expecting certificate key at %s, got %v", w.Config.Certificate.Key, err)
@@ -54,6 +55,7 @@ func (w *Worker) server() (http.Handler, bool) {
} else {
logrus.Fatal("unable to run with TLS: No certificate provided")
}
+
return _server, true
}
diff --git a/cmd/vela-worker/start.go b/cmd/vela-worker/start.go
index 74f8cca5b..454224238 100644
--- a/cmd/vela-worker/start.go
+++ b/cmd/vela-worker/start.go
@@ -6,6 +6,7 @@ package main
import (
"context"
+ "errors"
"fmt"
"net/http"
"os"
@@ -67,15 +68,14 @@ func (w *Worker) Start() error {
var err error
logrus.Info("starting worker server")
if tls {
- // nolint: lll // ignore long line length due to error message
- if err := server.ListenAndServeTLS(w.Config.Certificate.Cert, w.Config.Certificate.Key); err != http.ErrServerClosed {
+ if err := server.ListenAndServeTLS(w.Config.Certificate.Cert, w.Config.Certificate.Key); !errors.Is(err, http.ErrServerClosed) {
// log a message indicating the start of the server
//
// https://pkg.go.dev/github.com/sirupsen/logrus?tab=doc#Info
logrus.Errorf("failing worker server: %v", err)
}
} else {
- if err := server.ListenAndServe(); err != http.ErrServerClosed {
+ if err := server.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) {
// log a message indicating the start of the server
//
// https://pkg.go.dev/github.com/sirupsen/logrus?tab=doc#Info
diff --git a/executor/context.go b/executor/context.go
index f06e77b61..0ee583abc 100644
--- a/executor/context.go
+++ b/executor/context.go
@@ -54,7 +54,7 @@ func FromGinContext(c *gin.Context) Engine {
func WithContext(c context.Context, e Engine) context.Context {
// set the executor Engine in the context.Context
//
- // nolint: golint,staticcheck // ignore using string with context value
+ // nolint: revive,staticcheck // ignore using string with context value
return context.WithValue(c, key, e)
}
diff --git a/executor/context_test.go b/executor/context_test.go
index 790e5ff3a..10607ba94 100644
--- a/executor/context_test.go
+++ b/executor/context_test.go
@@ -55,7 +55,7 @@ func TestExecutor_FromContext(t *testing.T) {
want Engine
}{
{
- // nolint: golint,staticcheck // ignore using string with context value
+ // nolint: staticcheck // ignore using string with context value
context: context.WithValue(context.Background(), key, _engine),
want: _engine,
},
@@ -64,7 +64,7 @@ func TestExecutor_FromContext(t *testing.T) {
want: nil,
},
{
- // nolint: golint,staticcheck // ignore using string with context value
+ // nolint: staticcheck // ignore using string with context value
context: context.WithValue(context.Background(), key, "foo"),
want: nil,
},
@@ -173,7 +173,7 @@ func TestExecutor_WithContext(t *testing.T) {
t.Errorf("unable to create linux engine: %v", err)
}
- // nolint: golint,staticcheck // ignore using string with context value
+ // nolint: staticcheck // ignore using string with context value
want := context.WithValue(context.Background(), key, _engine)
// run test
diff --git a/executor/linux/build.go b/executor/linux/build.go
index fa31f65d8..5806e06fe 100644
--- a/executor/linux/build.go
+++ b/executor/linux/build.go
@@ -38,7 +38,7 @@ func (c *client) CreateBuild(ctx context.Context) error {
// https://pkg.go.dev/github.com/go-vela/sdk-go/vela?tab=doc#BuildService.Update
c.build, _, c.err = c.Vela.Build.Update(c.repo.GetOrg(), c.repo.GetName(), c.build)
if c.err != nil {
- return fmt.Errorf("unable to upload build state: %v", c.err)
+ return fmt.Errorf("unable to upload build state: %w", c.err)
}
// setup the runtime build
@@ -73,8 +73,6 @@ func (c *client) CreateBuild(ctx context.Context) error {
}
// PlanBuild prepares the build for execution.
-//
-// nolint: funlen // ignore function length due to comments and logging messages
func (c *client) PlanBuild(ctx context.Context) error {
// defer taking a snapshot of the build
//
@@ -386,8 +384,6 @@ func (c *client) AssembleBuild(ctx context.Context) error {
}
// ExecBuild runs a pipeline for a build.
-//
-// nolint: funlen // ignore function length due to comments and log messages
func (c *client) ExecBuild(ctx context.Context) error {
// defer an upload of the build
//
@@ -489,7 +485,7 @@ func (c *client) ExecBuild(ctx context.Context) error {
// https://pkg.go.dev/golang.org/x/sync/errgroup?tab=doc#Group.Wait
c.err = stages.Wait()
if c.err != nil {
- return fmt.Errorf("unable to wait for stages: %v", c.err)
+ return fmt.Errorf("unable to wait for stages: %w", c.err)
}
return c.err
diff --git a/executor/linux/build_test.go b/executor/linux/build_test.go
index 86279bfb2..d690e65ec 100644
--- a/executor/linux/build_test.go
+++ b/executor/linux/build_test.go
@@ -431,7 +431,7 @@ func TestLinux_ExecBuild(t *testing.T) {
// in a privileged fashion.
err = _runtime.CreateVolume(context.Background(), _pipeline)
if err != nil {
- t.Errorf("unable to create runtime volume: %w", err)
+ t.Errorf("unable to create runtime volume: %v", err)
}
// TODO: hack - remove this
diff --git a/executor/linux/linux.go b/executor/linux/linux.go
index 50e490eaf..71ccd041e 100644
--- a/executor/linux/linux.go
+++ b/executor/linux/linux.go
@@ -54,7 +54,7 @@ type (
// New returns an Executor implementation that integrates with a Linux instance.
//
-// nolint: golint // ignore unexported type as it is intentional
+// nolint: revive // ignore unexported type as it is intentional
func New(opts ...Opt) (*client, error) {
// create new Linux client
c := new(client)
diff --git a/executor/linux/secret.go b/executor/linux/secret.go
index 0d0be10a6..ad2c2b25f 100644
--- a/executor/linux/secret.go
+++ b/executor/linux/secret.go
@@ -243,7 +243,7 @@ func (s *secretSvc) pull(secret *pipeline.Secret) (*library.Secret, error) {
secret.Value = _secret.GetValue()
default:
- return nil, fmt.Errorf("%s: %s", ErrUnrecognizedSecretType, secret.Type)
+ return nil, fmt.Errorf("%w: %s", ErrUnrecognizedSecretType, secret.Type)
}
return _secret, nil
@@ -303,8 +303,6 @@ func (s *secretSvc) stream(ctx context.Context, ctn *pipeline.Container) error {
logs.Write(append(scanner.Bytes(), []byte("\n")...))
// if we have at least 1000 bytes in our buffer
- //
- // nolint: gomnd // ignore magic number
if logs.Len() > 1000 {
logger.Trace(logs.String())
@@ -317,7 +315,6 @@ func (s *secretSvc) stream(ctx context.Context, ctn *pipeline.Container) error {
// send API call to append the logs for the init step
//
// https://pkg.go.dev/github.com/go-vela/sdk-go/vela?tab=doc#LogService.UpdateStep
- // nolint: lll // skip line length due to variable names
_log, _, err = s.client.Vela.Log.UpdateStep(s.client.repo.GetOrg(), s.client.repo.GetName(), s.client.build.GetNumber(), s.client.init.Number, _log)
if err != nil {
return err
diff --git a/executor/linux/service.go b/executor/linux/service.go
index cfd49eaed..66fa33093 100644
--- a/executor/linux/service.go
+++ b/executor/linux/service.go
@@ -230,13 +230,11 @@ func (c *client) StreamService(ctx context.Context, ctn *pipeline.Container) err
// create new buffer for uploading logs
logs := new(bytes.Buffer)
- // nolint: dupl // ignore similar code with step
switch c.logMethod {
case "time-chunks":
// create new channel for processing logs
done := make(chan bool)
- // nolint: dupl // ignore similar code
go func() {
logger.Debug("polling logs for container")
@@ -322,8 +320,6 @@ func (c *client) StreamService(ctx context.Context, ctn *pipeline.Container) err
logs.Write(append(scanner.Bytes(), []byte("\n")...))
// if we have at least 1000 bytes in our buffer
- //
- // nolint: gomnd // ignore magic number
if logs.Len() > 1000 {
logger.Trace(logs.String())
diff --git a/executor/linux/stage.go b/executor/linux/stage.go
index 21b738f0e..b52b5f827 100644
--- a/executor/linux/stage.go
+++ b/executor/linux/stage.go
@@ -151,6 +151,7 @@ func (c *client) DestroyStage(ctx context.Context, s *pipeline.Stage) error {
//
// https://pkg.go.dev/github.com/sirupsen/logrus?tab=doc#Entry.WithField
logger := c.Logger.WithField("stage", s.Name)
+
var err error
// destroy the steps for the stage
diff --git a/executor/linux/step.go b/executor/linux/step.go
index 3e76677bc..f823aede8 100644
--- a/executor/linux/step.go
+++ b/executor/linux/step.go
@@ -273,13 +273,11 @@ func (c *client) StreamStep(ctx context.Context, ctn *pipeline.Container) error
// create new buffer for uploading logs
logs := new(bytes.Buffer)
- // nolint: dupl // ignore similar code with service
switch c.logMethod {
case "time-chunks":
// create new channel for processing logs
done := make(chan bool)
- // nolint: dupl // ignore similar code
go func() {
logger.Debug("polling logs for container")
@@ -370,8 +368,6 @@ func (c *client) StreamStep(ctx context.Context, ctn *pipeline.Container) error
logs.Write(append(scanner.Bytes(), []byte("\n")...))
// if we have at least 1000 bytes in our buffer
- //
- // nolint: gomnd // ignore magic number
if logs.Len() > 1000 {
logger.Trace(logs.String())
@@ -474,5 +470,6 @@ func getSecretValues(ctn *pipeline.Container) []string {
secretValues = append(secretValues, strings.TrimSuffix(s, " "))
}
+
return secretValues
}
diff --git a/executor/linux/step_test.go b/executor/linux/step_test.go
index 9ce325912..ace74ba03 100644
--- a/executor/linux/step_test.go
+++ b/executor/linux/step_test.go
@@ -531,6 +531,7 @@ func TestLinux_getSecretValues(t *testing.T) {
if err != nil {
t.Errorf("unable to read from test data file secret. Err: %v", err)
}
+
tests := []struct {
want []string
container *pipeline.Container
diff --git a/executor/local/build.go b/executor/local/build.go
index 312ba8c84..488bc9314 100644
--- a/executor/local/build.go
+++ b/executor/local/build.go
@@ -133,8 +133,6 @@ func (c *client) PlanBuild(ctx context.Context) error {
}
// AssembleBuild prepares the containers within a build for execution.
-//
-// nolint: funlen // ignore function length due to comments
func (c *client) AssembleBuild(ctx context.Context) error {
// defer taking a snapshot of the build
//
@@ -340,7 +338,7 @@ func (c *client) ExecBuild(ctx context.Context) error {
// https://pkg.go.dev/golang.org/x/sync/errgroup?tab=doc#Group.Wait
c.err = stages.Wait()
if c.err != nil {
- return fmt.Errorf("unable to wait for stages: %v", c.err)
+ return fmt.Errorf("unable to wait for stages: %w", c.err)
}
return c.err
diff --git a/executor/local/local.go b/executor/local/local.go
index c922a1af4..6674931ab 100644
--- a/executor/local/local.go
+++ b/executor/local/local.go
@@ -35,7 +35,7 @@ type (
// New returns an Executor implementation that integrates with the local system.
//
-// nolint: golint // ignore unexported type as it is intentional
+// nolint: revive // ignore unexported type as it is intentional
func New(opts ...Opt) (*client, error) {
// create new local client
c := new(client)
diff --git a/executor/local/step_test.go b/executor/local/step_test.go
index 6d94dbc2a..c6dad3b42 100644
--- a/executor/local/step_test.go
+++ b/executor/local/step_test.go
@@ -1,4 +1,4 @@
-// Copyright (c) 1011 Target Brands, Inc. All rights reserved.
+// Copyright (c) 2022 Target Brands, Inc. All rights reserved.
//
// Use of this source code is governed by the LICENSE file in this repository.
diff --git a/internal/service/environment.go b/internal/service/environment.go
index 312f686a4..53051edc2 100644
--- a/internal/service/environment.go
+++ b/internal/service/environment.go
@@ -14,8 +14,6 @@ import (
// Environment attempts to update the environment variables
// for the container based off the library resources.
-//
-// nolint: lll // ignore long line length due to parameters
func Environment(c *pipeline.Container, b *library.Build, r *library.Repo, s *library.Service, version string) error {
// check if container or container environment are empty
if c == nil || c.Environment == nil {
diff --git a/internal/service/snapshot.go b/internal/service/snapshot.go
index 9a99f4770..c42e03b1c 100644
--- a/internal/service/snapshot.go
+++ b/internal/service/snapshot.go
@@ -17,8 +17,6 @@ import (
// Snapshot creates a moment in time record of the
// service and attempts to upload it to the server.
-//
-// nolint: lll // ignore long line length due to parameters
func Snapshot(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logrus.Entry, r *library.Repo, s *library.Service) {
// check if the build is not in a canceled status
if !strings.EqualFold(s.GetStatus(), constants.StatusCanceled) {
diff --git a/internal/service/upload.go b/internal/service/upload.go
index cb3108fbd..40eac48b9 100644
--- a/internal/service/upload.go
+++ b/internal/service/upload.go
@@ -16,8 +16,6 @@ import (
// Upload tracks the final state of the service
// and attempts to upload it to the server.
-//
-// nolint: lll // ignore long line length due to parameters
func Upload(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logrus.Entry, r *library.Repo, s *library.Service) {
// handle the service based off the status provided
switch s.GetStatus() {
@@ -41,8 +39,6 @@ func Upload(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logrus
// SHOULD NOT happen
//
// TODO: consider making this a constant
- //
- // nolint: gomnd // ignore magic number 137
s.SetExitCode(137)
s.SetFinished(time.Now().UTC().Unix())
s.SetStatus(constants.StatusKilled)
diff --git a/internal/step/environment.go b/internal/step/environment.go
index bff3cff9e..057004b90 100644
--- a/internal/step/environment.go
+++ b/internal/step/environment.go
@@ -14,8 +14,6 @@ import (
// Environment attempts to update the environment variables
// for the container based off the library resources.
-//
-// nolint: lll // ignore long line length due to parameters
func Environment(c *pipeline.Container, b *library.Build, r *library.Repo, s *library.Step, version string) error {
// check if container or container environment are empty
if c == nil || c.Environment == nil {
diff --git a/internal/step/snapshot.go b/internal/step/snapshot.go
index a426b4cba..92c030ec8 100644
--- a/internal/step/snapshot.go
+++ b/internal/step/snapshot.go
@@ -17,8 +17,6 @@ import (
// Snapshot creates a moment in time record of the
// step and attempts to upload it to the server.
-//
-// nolint: lll // ignore long line length due to parameters
func Snapshot(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logrus.Entry, r *library.Repo, s *library.Step) {
// check if the build is not in a canceled status
if !strings.EqualFold(s.GetStatus(), constants.StatusCanceled) {
@@ -67,8 +65,6 @@ func Snapshot(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logr
// SnapshotInit creates a moment in time record of the
// init step and attempts to upload it to the server.
-//
-// nolint: lll // ignore long line length due to parameters
func SnapshotInit(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logrus.Entry, r *library.Repo, s *library.Step, lg *library.Log) {
// check if the build is not in a canceled status
if !strings.EqualFold(s.GetStatus(), constants.StatusCanceled) {
diff --git a/internal/step/upload.go b/internal/step/upload.go
index 47e363907..3a917dc56 100644
--- a/internal/step/upload.go
+++ b/internal/step/upload.go
@@ -16,8 +16,6 @@ import (
// Upload tracks the final state of the step
// and attempts to upload it to the server.
-//
-// nolint: lll // ignore long line length due to parameters
func Upload(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logrus.Entry, r *library.Repo, s *library.Step) {
// handle the step based off the status provided
switch s.GetStatus() {
@@ -41,8 +39,6 @@ func Upload(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logrus
// SHOULD NOT happen
//
// TODO: consider making this a constant
- //
- // nolint: gomnd // ignore magic number 137
s.SetExitCode(137)
s.SetFinished(time.Now().UTC().Unix())
s.SetStatus(constants.StatusKilled)
diff --git a/internal/volume/volume.go b/internal/volume/volume.go
index ad18c647c..697a45247 100644
--- a/internal/volume/volume.go
+++ b/internal/volume/volume.go
@@ -48,7 +48,6 @@ func ParseWithError(_volume string) (*Volume, error) {
Destination: parts[0],
AccessMode: "ro",
}, nil
- // nolint: gomnd // ignore magic number
case 2:
// return the read-only volume with different source and destination
return &Volume{
@@ -56,7 +55,6 @@ func ParseWithError(_volume string) (*Volume, error) {
Destination: parts[1],
AccessMode: "ro",
}, nil
- // nolint: gomnd // ignore magic number
case 3:
// return the full volume with source, destination and access mode
return &Volume{
diff --git a/mock/docker/config.go b/mock/docker/config.go
index e7786e2b3..e1d2878ee 100644
--- a/mock/docker/config.go
+++ b/mock/docker/config.go
@@ -2,6 +2,7 @@
//
// Use of this source code is governed by the LICENSE file in this repository.
+// nolint: dupl // ignore similar code
package docker
import (
diff --git a/mock/docker/container.go b/mock/docker/container.go
index 32d0d2aca..d17c1ab73 100644
--- a/mock/docker/container.go
+++ b/mock/docker/container.go
@@ -63,7 +63,7 @@ func (c *ContainerService) ContainerCreate(ctx context.Context, config *containe
if strings.Contains(ctn, "notfound") &&
!strings.Contains(ctn, "ignorenotfound") {
return container.ContainerCreateCreatedBody{},
- // nolint:golint,stylecheck // messsage is capitalized to match Docker messages
+ // nolint:stylecheck // messsage is capitalized to match Docker messages
errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn))
}
@@ -72,7 +72,7 @@ func (c *ContainerService) ContainerCreate(ctx context.Context, config *containe
if strings.Contains(ctn, "not-found") &&
!strings.Contains(ctn, "ignore-not-found") {
return container.ContainerCreateCreatedBody{},
- // nolint:golint,stylecheck // messsage is capitalized to match Docker messages
+ // nolint:stylecheck // messsage is capitalized to match Docker messages
errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn))
}
@@ -81,7 +81,7 @@ func (c *ContainerService) ContainerCreate(ctx context.Context, config *containe
strings.Contains(config.Image, "not-found") {
return container.ContainerCreateCreatedBody{},
errdefs.NotFound(
- // nolint:golint,stylecheck // messsage is capitalized to match Docker messages
+ // nolint:stylecheck // messsage is capitalized to match Docker messages
fmt.Errorf("Error response from daemon: manifest for %s not found: manifest unknown", config.Image),
)
}
@@ -172,7 +172,7 @@ func (c *ContainerService) ContainerInspect(ctx context.Context, ctn string) (ty
if strings.Contains(ctn, "notfound") &&
!strings.Contains(ctn, "ignorenotfound") {
return types.ContainerJSON{},
- // nolint:golint,stylecheck // messsage is capitalized to match Docker messages
+ // nolint:stylecheck // messsage is capitalized to match Docker messages
errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn))
}
@@ -181,7 +181,7 @@ func (c *ContainerService) ContainerInspect(ctx context.Context, ctn string) (ty
if strings.Contains(ctn, "not-found") &&
!strings.Contains(ctn, "ignore-not-found") {
return types.ContainerJSON{},
- // nolint:golint,stylecheck // messsage is capitalized to match Docker messages
+ // nolint:stylecheck // messsage is capitalized to match Docker messages
errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn))
}
@@ -217,7 +217,7 @@ func (c *ContainerService) ContainerInspectWithRaw(ctx context.Context, ctn stri
strings.Contains(ctn, "not-found") {
return types.ContainerJSON{},
nil,
- // nolint:golint,stylecheck // messsage is capitalized to match Docker messages
+ // nolint:stylecheck // messsage is capitalized to match Docker messages
errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn))
}
@@ -256,7 +256,7 @@ func (c *ContainerService) ContainerKill(ctx context.Context, ctn, signal string
// check if the container is not found
if strings.Contains(ctn, "notfound") ||
strings.Contains(ctn, "not-found") {
- // nolint:golint,stylecheck // messsage is capitalized to match Docker messages
+ // nolint:stylecheck // messsage is capitalized to match Docker messages
return errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn))
}
@@ -285,7 +285,7 @@ func (c *ContainerService) ContainerLogs(ctx context.Context, ctn string, option
// check if the container is not found
if strings.Contains(ctn, "notfound") ||
strings.Contains(ctn, "not-found") {
- // nolint:golint,stylecheck // messsage is capitalized to match Docker messages
+ // nolint:stylecheck // messsage is capitalized to match Docker messages
return nil, errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn))
}
@@ -331,7 +331,7 @@ func (c *ContainerService) ContainerRemove(ctx context.Context, ctn string, opti
// check if the container is not found
if strings.Contains(ctn, "notfound") || strings.Contains(ctn, "not-found") {
- // nolint:golint,stylecheck // messsage is capitalized to match Docker messages
+ // nolint:stylecheck // messsage is capitalized to match Docker messages
return errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn))
}
@@ -375,7 +375,7 @@ func (c *ContainerService) ContainerStart(ctx context.Context, ctn string, optio
// check if the container is not found
if strings.Contains(ctn, "notfound") ||
strings.Contains(ctn, "not-found") {
- // nolint:golint,stylecheck // messsage is capitalized to match Docker messages
+ // nolint:stylecheck // messsage is capitalized to match Docker messages
return errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn))
}
@@ -412,7 +412,7 @@ func (c *ContainerService) ContainerStop(ctx context.Context, ctn string, timeou
// check if the container is not found
if strings.Contains(ctn, "notfound") || strings.Contains(ctn, "not-found") {
- // nolint:golint,stylecheck // messsage is capitalized to match Docker messages
+ // nolint:stylecheck // messsage is capitalized to match Docker messages
return errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn))
}
@@ -464,7 +464,7 @@ func (c *ContainerService) ContainerWait(ctx context.Context, ctn string, condit
// check if the container is not found
if strings.Contains(ctn, "notfound") || strings.Contains(ctn, "not-found") {
// propagate the error to the error channel
- // nolint:golint,stylecheck // messsage is capitalized to match Docker messages
+ // nolint:stylecheck // messsage is capitalized to match Docker messages
errCh <- errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn))
return ctnCh, errCh
diff --git a/mock/docker/docker.go b/mock/docker/docker.go
index 3528846ea..5b6a06041 100644
--- a/mock/docker/docker.go
+++ b/mock/docker/docker.go
@@ -23,7 +23,6 @@ const Version = "v1.40"
// New returns a client that is capable of handling
// Docker client calls and returning stub responses.
-// nolint:golint // returning unexported type intentionally
func New() (*mock, error) {
return &mock{
ConfigService: ConfigService{},
diff --git a/mock/docker/image.go b/mock/docker/image.go
index eecd81ab5..887d399ae 100644
--- a/mock/docker/image.go
+++ b/mock/docker/image.go
@@ -90,7 +90,7 @@ func (i *ImageService) ImageInspectWithRaw(ctx context.Context, image string) (t
return types.ImageInspect{},
nil,
errdefs.NotFound(
- // nolint:golint,stylecheck // messsage is capitalized to match Docker messages
+ // nolint:stylecheck // messsage is capitalized to match Docker messages
fmt.Errorf("Error response from daemon: manifest for %s not found: manifest unknown", image),
)
}
@@ -165,7 +165,7 @@ func (i *ImageService) ImagePull(ctx context.Context, image string, options type
!strings.Contains(image, "ignorenotfound") {
return nil,
errdefs.NotFound(
- // nolint:golint,stylecheck // messsage is capitalized to match Docker messages
+ // nolint:stylecheck // messsage is capitalized to match Docker messages
fmt.Errorf("Error response from daemon: manifest for %s not found: manifest unknown", image),
)
}
@@ -176,7 +176,7 @@ func (i *ImageService) ImagePull(ctx context.Context, image string, options type
!strings.Contains(image, "ignore-not-found") {
return nil,
errdefs.NotFound(
- // nolint:golint,stylecheck // messsage is capitalized to match Docker messages
+ // nolint:stylecheck // messsage is capitalized to match Docker messages
fmt.Errorf("Error response from daemon: manifest for %s not found: manifest unknown", image),
)
}
diff --git a/mock/docker/network.go b/mock/docker/network.go
index 9ec142c0e..a82b8ef7d 100644
--- a/mock/docker/network.go
+++ b/mock/docker/network.go
@@ -47,7 +47,7 @@ func (n *NetworkService) NetworkCreate(ctx context.Context, name string, options
if strings.Contains(name, "notfound") &&
!strings.Contains(name, "ignorenotfound") {
return types.NetworkCreateResponse{},
- // nolint:golint,stylecheck // messsage is capitalized to match Docker messages
+ // nolint:stylecheck // messsage is capitalized to match Docker messages
errdefs.NotFound(fmt.Errorf("Error: No such network: %s", name))
}
@@ -56,7 +56,7 @@ func (n *NetworkService) NetworkCreate(ctx context.Context, name string, options
if strings.Contains(name, "not-found") &&
!strings.Contains(name, "ignore-not-found") {
return types.NetworkCreateResponse{},
- // nolint:golint,stylecheck // messsage is capitalized to match Docker messages
+ // nolint:stylecheck // messsage is capitalized to match Docker messages
errdefs.NotFound(fmt.Errorf("Error: No such network: %s", name))
}
@@ -89,14 +89,14 @@ func (n *NetworkService) NetworkInspect(ctx context.Context, network string, opt
// check if the network is notfound
if strings.Contains(network, "notfound") {
return types.NetworkResource{},
- // nolint:golint,stylecheck // messsage is capitalized to match Docker messages
+ // nolint:stylecheck // messsage is capitalized to match Docker messages
errdefs.NotFound(fmt.Errorf("Error: No such network: %s", network))
}
// check if the network is not-found
if strings.Contains(network, "not-found") {
return types.NetworkResource{},
- // nolint:golint,stylecheck // messsage is capitalized to match Docker messages
+ // nolint:stylecheck // messsage is capitalized to match Docker messages
errdefs.NotFound(fmt.Errorf("Error: No such network: %s", network))
}
diff --git a/mock/docker/secret.go b/mock/docker/secret.go
index 88059c228..ca5286c04 100644
--- a/mock/docker/secret.go
+++ b/mock/docker/secret.go
@@ -2,6 +2,7 @@
//
// Use of this source code is governed by the LICENSE file in this repository.
+// nolint: dupl // ignore similar code
package docker
import (
diff --git a/mock/docker/volume.go b/mock/docker/volume.go
index db64c8043..18bb14e8c 100644
--- a/mock/docker/volume.go
+++ b/mock/docker/volume.go
@@ -39,7 +39,7 @@ func (v *VolumeService) VolumeCreate(ctx context.Context, options volume.VolumeC
if strings.Contains(options.Name, "notfound") &&
!strings.Contains(options.Name, "ignorenotfound") {
return types.Volume{},
- // nolint:golint,stylecheck // messsage is capitalized to match Docker messages
+ // nolint:stylecheck // messsage is capitalized to match Docker messages
errdefs.NotFound(fmt.Errorf("Error: No such volume: %s", options.Name))
}
@@ -48,7 +48,7 @@ func (v *VolumeService) VolumeCreate(ctx context.Context, options volume.VolumeC
if strings.Contains(options.Name, "not-found") &&
!strings.Contains(options.Name, "ignore-not-found") {
return types.Volume{},
- // nolint:golint,stylecheck // messsage is capitalized to match Docker messages
+ // nolint:stylecheck // messsage is capitalized to match Docker messages
errdefs.NotFound(fmt.Errorf("Error: No such volume: %s", options.Name))
}
@@ -79,14 +79,14 @@ func (v *VolumeService) VolumeInspect(ctx context.Context, volumeID string) (typ
// check if the volume is notfound
if strings.Contains(volumeID, "notfound") {
return types.Volume{},
- // nolint:golint,stylecheck // messsage is capitalized to match Docker messages
+ // nolint:stylecheck // messsage is capitalized to match Docker messages
errdefs.NotFound(fmt.Errorf("Error: No such volume: %s", volumeID))
}
// check if the volume is not-found
if strings.Contains(volumeID, "not-found") {
return types.Volume{},
- // nolint:golint,stylecheck // messsage is capitalized to match Docker messages
+ // nolint:stylecheck // messsage is capitalized to match Docker messages
errdefs.NotFound(fmt.Errorf("Error: No such volume: %s", volumeID))
}
@@ -116,14 +116,14 @@ func (v *VolumeService) VolumeInspectWithRaw(ctx context.Context, volumeID strin
// check if the volume is notfound
if strings.Contains(volumeID, "notfound") {
return types.Volume{}, nil,
- // nolint:golint,stylecheck // messsage is capitalized to match Docker messages
+ // nolint:stylecheck // messsage is capitalized to match Docker messages
errdefs.NotFound(fmt.Errorf("Error: No such volume: %s", volumeID))
}
// check if the volume is not-found
if strings.Contains(volumeID, "not-found") {
return types.Volume{}, nil,
- // nolint:golint,stylecheck // messsage is capitalized to match Docker messages
+ // nolint:stylecheck // messsage is capitalized to match Docker messages
errdefs.NotFound(fmt.Errorf("Error: No such volume: %s", volumeID))
}
diff --git a/router/middleware/executor/executor.go b/router/middleware/executor/executor.go
index f58682d9d..b8e3d65c4 100644
--- a/router/middleware/executor/executor.go
+++ b/router/middleware/executor/executor.go
@@ -64,6 +64,7 @@ func Establish() gin.HandlerFunc {
}
logrus.Debugf("Reading executor %s", param)
+
e, ok := executors[number]
if !ok {
msg := fmt.Sprintf("unable to get executor %s", param)
diff --git a/router/middleware/header.go b/router/middleware/header.go
index 5a7d85198..57eedcce1 100644
--- a/router/middleware/header.go
+++ b/router/middleware/header.go
@@ -40,6 +40,8 @@ func Options(c *gin.Context) {
// Secure is a middleware function that appends security
// and resource access headers.
func Secure(c *gin.Context) {
+ // Also consider adding Content-Security-Policy headers
+ // c.Header("Content-Security-Policy", "script-src 'self' https://cdnjs.cloudflare.com")
c.Header("Access-Control-Allow-Origin", "*")
c.Header("X-Frame-Options", "DENY")
c.Header("X-Content-Type-Options", "nosniff")
@@ -48,9 +50,6 @@ func Secure(c *gin.Context) {
if c.Request.TLS != nil {
c.Header("Strict-Transport-Security", "max-age=31536000")
}
-
- // Also consider adding Content-Security-Policy headers
- // c.Header("Content-Security-Policy", "script-src 'self' https://cdnjs.cloudflare.com")
}
// RequestVersion is a middleware function that injects the Vela API version
diff --git a/router/middleware/logger.go b/router/middleware/logger.go
index 754e401a2..b9431515b 100644
--- a/router/middleware/logger.go
+++ b/router/middleware/logger.go
@@ -29,6 +29,7 @@ func Logger(logger *logrus.Logger, timeFormat string, utc bool) gin.HandlerFunc
end := time.Now()
latency := end.Sub(start)
+
if utc {
end = end.UTC()
}
diff --git a/router/middleware/perm/perm.go b/router/middleware/perm/perm.go
index ee989c2df..135d452c3 100644
--- a/router/middleware/perm/perm.go
+++ b/router/middleware/perm/perm.go
@@ -26,10 +26,12 @@ func MustServer() gin.HandlerFunc {
}
msg := fmt.Sprintf("User %s is not a platform admin", u.GetName())
+
err := c.Error(fmt.Errorf(msg))
if err != nil {
logrus.Error(err)
}
+
c.AbortWithStatusJSON(http.StatusUnauthorized, types.Error{Message: &msg})
}
}
diff --git a/router/middleware/token/token_test.go b/router/middleware/token/token_test.go
index 98a5ac7f8..5dc5f3ee7 100644
--- a/router/middleware/token/token_test.go
+++ b/router/middleware/token/token_test.go
@@ -5,6 +5,7 @@
package token
import (
+ "context"
"fmt"
"net/http"
"strings"
@@ -16,7 +17,7 @@ func TestToken_Retrieve(t *testing.T) {
want := "foobar"
header := fmt.Sprintf("Bearer %s", want)
- request, _ := http.NewRequest(http.MethodGet, "/test", nil)
+ request, _ := http.NewRequestWithContext(context.Background(), http.MethodGet, "/test", nil)
request.Header.Set("Authorization", header)
// run test
@@ -32,7 +33,7 @@ func TestToken_Retrieve(t *testing.T) {
func TestToken_Retrieve_Error(t *testing.T) {
// setup types
- request, _ := http.NewRequest(http.MethodGet, "/test", nil)
+ request, _ := http.NewRequestWithContext(context.Background(), http.MethodGet, "/test", nil)
// run test
got, err := Retrieve(request)
diff --git a/router/pipeline.go b/router/pipeline.go
index a738b6f0d..59b406eea 100644
--- a/router/pipeline.go
+++ b/router/pipeline.go
@@ -1,6 +1,6 @@
// Copyright (c) 2022 Target Brands, Inc. All rights reserved.
//
-// Use of this source code is governed by the LICENSE file in this pipelinesitory.
+// Use of this source code is governed by the LICENSE file in this repository.
package router
diff --git a/runtime/context.go b/runtime/context.go
index 88c083033..0579fe60f 100644
--- a/runtime/context.go
+++ b/runtime/context.go
@@ -54,7 +54,7 @@ func FromGinContext(c *gin.Context) Engine {
func WithContext(c context.Context, e Engine) context.Context {
// set the runtime Engine in the context.Context
//
- // nolint: golint,staticcheck // ignore using string with context value
+ // nolint: revive,staticcheck // ignore using string with context value
return context.WithValue(c, key, e)
}
diff --git a/runtime/context_test.go b/runtime/context_test.go
index 9621cad71..6145d73f8 100644
--- a/runtime/context_test.go
+++ b/runtime/context_test.go
@@ -29,7 +29,7 @@ func TestRuntime_FromContext(t *testing.T) {
want Engine
}{
{
- // nolint: golint,staticcheck // ignore using string with context value
+ // nolint: staticcheck // ignore using string with context value
context: context.WithValue(context.Background(), key, _engine),
want: _engine,
},
@@ -38,7 +38,7 @@ func TestRuntime_FromContext(t *testing.T) {
want: nil,
},
{
- // nolint: golint,staticcheck // ignore using string with context value
+ // nolint: staticcheck // ignore using string with context value
context: context.WithValue(context.Background(), key, "foo"),
want: nil,
},
@@ -109,7 +109,7 @@ func TestRuntime_WithContext(t *testing.T) {
t.Errorf("unable to create runtime engine: %v", err)
}
- // nolint: golint,staticcheck // ignore using string with context value
+ // nolint: staticcheck // ignore using string with context value
want := context.WithValue(context.Background(), key, _engine)
// run test
diff --git a/runtime/docker/container.go b/runtime/docker/container.go
index 870360bce..9f5106ece 100644
--- a/runtime/docker/container.go
+++ b/runtime/docker/container.go
@@ -89,8 +89,6 @@ func (c *client) RemoveContainer(ctx context.Context, ctn *pipeline.Container) e
}
// RunContainer creates and starts the pipeline container.
-//
-// nolint: lll // ignore long line length due to variable names
func (c *client) RunContainer(ctx context.Context, ctn *pipeline.Container, b *pipeline.Build) error {
c.Logger.Tracef("running container %s", ctn.ID)
@@ -235,8 +233,6 @@ func (c *client) SetupContainer(ctx context.Context, ctn *pipeline.Container) er
}
// TailContainer captures the logs for the pipeline container.
-//
-// nolint: lll // ignore long line length due to variable names
func (c *client) TailContainer(ctx context.Context, ctn *pipeline.Container) (io.ReadCloser, error) {
c.Logger.Tracef("tailing output for container %s", ctn.ID)
diff --git a/runtime/docker/docker.go b/runtime/docker/docker.go
index 6b13a443b..c286c31f6 100644
--- a/runtime/docker/docker.go
+++ b/runtime/docker/docker.go
@@ -45,7 +45,7 @@ type client struct {
// New returns an Engine implementation that
// integrates with a Docker runtime.
//
-// nolint: golint // ignore returning unexported client
+// nolint: revive // ignore returning unexported client
func New(opts ...ClientOpt) (*client, error) {
// create new Docker client
c := new(client)
@@ -98,7 +98,7 @@ func New(opts ...ClientOpt) (*client, error) {
//
// This function is intended for running tests only.
//
-// nolint: golint // ignore returning unexported client
+// nolint: revive // ignore returning unexported client
func NewMock(opts ...ClientOpt) (*client, error) {
// create new Docker runtime client
c, err := New(opts...)
diff --git a/runtime/kubernetes/build.go b/runtime/kubernetes/build.go
index 3b2c5f744..d2fa71715 100644
--- a/runtime/kubernetes/build.go
+++ b/runtime/kubernetes/build.go
@@ -65,6 +65,7 @@ func (c *client) SetupBuild(ctx context.Context, b *pipeline.Build) error {
// before running AssembleBuild.
func (c *client) AssembleBuild(ctx context.Context, b *pipeline.Build) error {
c.Logger.Tracef("assembling build %s", b.ID)
+
var err error
// last minute Environment setup
@@ -74,11 +75,13 @@ func (c *client) AssembleBuild(ctx context.Context, b *pipeline.Build) error {
return err
}
}
+
for _, _stage := range b.Stages {
// TODO: remove hardcoded reference
if _stage.Name == "init" {
continue
}
+
for _, _step := range _stage.Steps {
err = c.setupContainerEnvironment(_step)
if err != nil {
@@ -86,20 +89,24 @@ func (c *client) AssembleBuild(ctx context.Context, b *pipeline.Build) error {
}
}
}
+
for _, _step := range b.Steps {
// TODO: remove hardcoded reference
if _step.Name == "init" {
continue
}
+
err = c.setupContainerEnvironment(_step)
if err != nil {
return err
}
}
+
for _, _secret := range b.Secrets {
if _secret.Origin.Empty() {
continue
}
+
err = c.setupContainerEnvironment(_secret.Origin)
if err != nil {
return err
@@ -115,6 +122,7 @@ func (c *client) AssembleBuild(ctx context.Context, b *pipeline.Build) error {
// send API call to create the pod
//
// https://pkg.go.dev/k8s.io/client-go/kubernetes/typed/core/v1?tab=doc#PodInterface
+ // nolint: contextcheck // ignore non-inherited new context
_, err = c.Kubernetes.CoreV1().
Pods(c.config.Namespace).
Create(context.Background(), c.Pod, metav1.CreateOptions{})
@@ -155,6 +163,7 @@ func (c *client) RemoveBuild(ctx context.Context, b *pipeline.Build) error {
c.Logger.Infof("removing pod %s", c.Pod.ObjectMeta.Name)
// send API call to delete the pod
+ // nolint: contextcheck // ignore non-inherited new context
err := c.Kubernetes.CoreV1().
Pods(c.config.Namespace).
Delete(context.Background(), c.Pod.ObjectMeta.Name, opts)
diff --git a/runtime/kubernetes/build_test.go b/runtime/kubernetes/build_test.go
index 8dbea5cc5..bec9ac11f 100644
--- a/runtime/kubernetes/build_test.go
+++ b/runtime/kubernetes/build_test.go
@@ -135,6 +135,7 @@ func TestKubernetes_AssembleBuild(t *testing.T) {
for _, test := range tests {
_engine, err := NewMock(test.k8sPod)
_engine.Pod = test.enginePod
+
if err != nil {
t.Errorf("unable to create runtime engine: %v", err)
}
@@ -207,10 +208,10 @@ func TestKubernetes_RemoveBuild(t *testing.T) {
if err != nil {
t.Errorf("unable to create runtime engine: %v", err)
}
+
_engine.createdPod = test.createdPod
err = _engine.RemoveBuild(context.Background(), test.pipeline)
-
if test.failure {
if err == nil {
t.Errorf("RemoveBuild should have returned err")
diff --git a/runtime/kubernetes/container.go b/runtime/kubernetes/container.go
index 752c73162..87f68cef3 100644
--- a/runtime/kubernetes/container.go
+++ b/runtime/kubernetes/container.go
@@ -33,6 +33,7 @@ func (c *client) InspectContainer(ctx context.Context, ctn *pipeline.Container)
// send API call to capture the container
//
// https://pkg.go.dev/k8s.io/client-go/kubernetes/typed/core/v1?tab=doc#PodInterface
+ // nolint: contextcheck // ignore non-inherited new context
pod, err := c.Kubernetes.CoreV1().Pods(c.config.Namespace).Get(
context.Background(),
c.Pod.ObjectMeta.Name,
@@ -70,8 +71,6 @@ func (c *client) RemoveContainer(ctx context.Context, ctn *pipeline.Container) e
}
// RunContainer creates and starts the pipeline container.
-//
-// nolint: lll // ignore long line length
func (c *client) RunContainer(ctx context.Context, ctn *pipeline.Container, b *pipeline.Build) error {
c.Logger.Tracef("running container %s", ctn.ID)
// parse image from step
@@ -87,6 +86,7 @@ func (c *client) RunContainer(ctx context.Context, ctn *pipeline.Container, b *p
// send API call to patch the pod with the new container image
//
// https://pkg.go.dev/k8s.io/client-go/kubernetes/typed/core/v1?tab=doc#PodInterface
+ // nolint: contextcheck // ignore non-inherited new context
_, err = c.Kubernetes.CoreV1().Pods(c.config.Namespace).Patch(
context.Background(),
c.Pod.ObjectMeta.Name,
@@ -156,6 +156,7 @@ func (c *client) SetupContainer(ctx context.Context, ctn *pipeline.Container) er
if err != nil {
return err
}
+
container.VolumeMounts = volumeMounts
// check if the image is allowed to run privileged
@@ -215,12 +216,11 @@ func (c *client) setupContainerEnvironment(ctn *pipeline.Container) error {
container.Env = append(container.Env, v1.EnvVar{Name: k, Value: v})
}
}
+
return nil
}
// TailContainer captures the logs for the pipeline container.
-//
-// nolint: lll // ignore long line length due to variable names
func (c *client) TailContainer(ctx context.Context, ctn *pipeline.Container) (io.ReadCloser, error) {
c.Logger.Tracef("tailing output for container %s", ctn.ID)
@@ -264,10 +264,9 @@ func (c *client) TailContainer(ctx context.Context, ctn *pipeline.Container) (io
reader := bufio.NewReader(stream)
// peek at container logs from the stream
- //
- // nolint: gomnd // ignore magic number
bytes, err := reader.Peek(5)
if err != nil {
+ // nolint: nilerr // ignore nil return
// skip so we resend API call to capture stream
return false, nil
}
@@ -325,6 +324,7 @@ func (c *client) WaitContainer(ctx context.Context, ctn *pipeline.Container) err
// https://pkg.go.dev/k8s.io/client-go/kubernetes/typed/core/v1?tab=doc#PodInterface
// ->
// https://pkg.go.dev/k8s.io/apimachinery/pkg/watch?tab=doc#Interface
+ // nolint: contextcheck // ignore non-inherited new context
watch, err := c.Kubernetes.CoreV1().Pods(c.config.Namespace).Watch(context.Background(), opts)
if err != nil {
return err
diff --git a/runtime/kubernetes/image.go b/runtime/kubernetes/image.go
index 0fe98dd2d..c0f88dc9e 100644
--- a/runtime/kubernetes/image.go
+++ b/runtime/kubernetes/image.go
@@ -42,7 +42,6 @@ func (c *client) InspectImage(ctx context.Context, ctn *pipeline.Container) ([]b
//
// create output for inspecting image
output := []byte(
- // nolint: lll // ignore line length due to string formatting with parameters
fmt.Sprintf("$ kubectl get pod -o=jsonpath='{.spec.containers[%d].image}' %s\n", ctn.Number, ctn.ID),
)
diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go
index 34818d014..99b27cf03 100644
--- a/runtime/kubernetes/kubernetes.go
+++ b/runtime/kubernetes/kubernetes.go
@@ -42,7 +42,7 @@ type client struct {
// New returns an Engine implementation that
// integrates with a Kubernetes runtime.
//
-// nolint: golint // ignore returning unexported client
+// nolint: revive // ignore returning unexported client
func New(opts ...ClientOpt) (*client, error) {
// create new Kubernetes client
c := new(client)
@@ -77,6 +77,7 @@ func New(opts ...ClientOpt) (*client, error) {
config *rest.Config
err error
)
+
if c.config.File == "" {
// https://pkg.go.dev/k8s.io/client-go/rest?tab=doc#InClusterConfig
config, err = rest.InClusterConfig()
@@ -111,7 +112,7 @@ func New(opts ...ClientOpt) (*client, error) {
//
// This function is intended for running tests only.
//
-// nolint: golint // ignore returning unexported client
+// nolint: revive // ignore returning unexported client
func NewMock(_pod *v1.Pod, opts ...ClientOpt) (*client, error) {
// create new Kubernetes client
c := new(client)
diff --git a/runtime/kubernetes/network.go b/runtime/kubernetes/network.go
index 7c3ee37cc..81ccfac16 100644
--- a/runtime/kubernetes/network.go
+++ b/runtime/kubernetes/network.go
@@ -18,7 +18,6 @@ import (
func (c *client) CreateNetwork(ctx context.Context, b *pipeline.Build) error {
c.Logger.Tracef("creating network for pipeline %s", b.ID)
- // nolint: lll // ignore long line length due to link
// create the network for the pod
//
// This is done due to the nature of how networking works inside the
diff --git a/version/version.go b/version/version.go
index 3368f7a64..30312ee24 100644
--- a/version/version.go
+++ b/version/version.go
@@ -34,7 +34,7 @@ var (
func New() *version.Version {
// check if a semantic tag was provided
if len(Tag) == 0 {
- logrus.Warningf("no semantic tag provided - defaulting to v0.0.0")
+ logrus.Warning("no semantic tag provided - defaulting to v0.0.0")
// set a fallback default for the tag
Tag = "v0.0.0"
@@ -42,7 +42,7 @@ func New() *version.Version {
v, err := semver.NewVersion(Tag)
if err != nil {
- fmt.Println(fmt.Errorf("unable to parse semantic version for %s: %v", Tag, err))
+ fmt.Println(fmt.Errorf("unable to parse semantic version for %s: %w", Tag, err))
}
return &version.Version{
From a76c1ab6edcfb16c83744b1b4775c54ba1ce2626 Mon Sep 17 00:00:00 2001
From: DaxJohnson
Date: Wed, 9 Mar 2022 12:05:13 -0600
Subject: [PATCH 2/2] chore(dep): update containerd to 1.4.13 (#283)
---
go.mod | 2 +-
go.sum | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/go.mod b/go.mod
index 8c81b7a19..39bd26049 100644
--- a/go.mod
+++ b/go.mod
@@ -35,7 +35,7 @@ require (
github.com/alicebob/miniredis/v2 v2.18.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
- github.com/containerd/containerd v1.4.8 // indirect
+ github.com/containerd/containerd v1.4.13 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
diff --git a/go.sum b/go.sum
index d785ca939..78214665e 100644
--- a/go.sum
+++ b/go.sum
@@ -110,8 +110,8 @@ github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnht
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
-github.com/containerd/containerd v1.4.8 h1:H0wkS4AbVKTg9vyvBdCBrxoax8AMObKbNz9Fl2N0i4Y=
-github.com/containerd/containerd v1.4.8/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
+github.com/containerd/containerd v1.4.13 h1:Z0CbagVdn9VN4K6htOCY/jApSw8YKP+RdLZ5dkXF8PM=
+github.com/containerd/containerd v1.4.13/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM=
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=