Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/vela-worker/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import (

// exec is a helper function to poll the queue
// and execute Vela pipelines for the Worker.
// nolint: nilerr // ignore returning nil - don't want to crash worker
//
//nolint:nilerr // ignore returning nil - don't want to crash worker
func (w *Worker) exec(index int) error {
var err error

Expand Down
4 changes: 3 additions & 1 deletion cmd/vela-worker/operate.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func (w *Worker) operate(ctx context.Context) error {
registryWorker.SetLastCheckedIn(time.Now().UTC().Unix())

// register or update the worker
//nolint:contextcheck // ignore passing context
err = w.checkIn(registryWorker)
if err != nil {
logrus.Error(err)
Expand All @@ -74,6 +75,7 @@ func (w *Worker) operate(ctx context.Context) error {
// setup the queue
//
// https://pkg.go.dev/github.com/go-vela/server/queue?tab=doc#New
//nolint:contextcheck // ignore passing context
w.Queue, err = queue.New(w.Config.Queue)
if err != nil {
return err
Expand Down Expand Up @@ -107,7 +109,7 @@ func (w *Worker) operate(ctx context.Context) error {
// exec operator subprocess to poll and execute builds
// (do not pass the context to avoid errors in one
// executor+build inadvertently canceling other builds)
// nolint: contextcheck // ignore passing context
//nolint:contextcheck // ignore passing context
err = w.exec(id)
if err != nil {
// log the error received from the executor
Expand Down
6 changes: 4 additions & 2 deletions cmd/vela-worker/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"os/signal"
"syscall"
"time"

"github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"
Expand All @@ -34,8 +35,9 @@ func (w *Worker) Start() error {
httpHandler, tls := w.server()

server := &http.Server{
Addr: fmt.Sprintf(":%s", w.Config.API.Address.Port()),
Handler: httpHandler,
Addr: fmt.Sprintf(":%s", w.Config.API.Address.Port()),
Handler: httpHandler,
ReadHeaderTimeout: 60 * time.Second,
}

// goroutine to check for signals to gracefully finish all functions
Expand Down
2 changes: 1 addition & 1 deletion executor/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: revive,staticcheck // ignore using string with context value
//nolint:revive,staticcheck // ignore using string with context value
return context.WithValue(c, key, e)
}

Expand Down
6 changes: 3 additions & 3 deletions executor/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestExecutor_FromContext(t *testing.T) {
}{
{
name: "valid executor in context",
// nolint: staticcheck,revive // ignore using string with context value
//nolint:staticcheck,revive // ignore using string with context value
context: context.WithValue(context.Background(), key, _engine),
want: _engine,
},
Expand All @@ -68,7 +68,7 @@ func TestExecutor_FromContext(t *testing.T) {
},
{
name: "invalid executor in context",
// nolint: staticcheck,revive // ignore using string with context value
//nolint:staticcheck,revive // ignore using string with context value
context: context.WithValue(context.Background(), key, "foo"),
want: nil,
},
Expand Down Expand Up @@ -185,7 +185,7 @@ func TestExecutor_WithContext(t *testing.T) {
t.Errorf("unable to create linux engine: %v", err)
}

// nolint: staticcheck,revive // ignore using string with context value
//nolint:staticcheck,revive // ignore using string with context value
want := context.WithValue(context.Background(), key, _engine)

// run test
Expand Down
3 changes: 1 addition & 2 deletions executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ import (
"github.com/sirupsen/logrus"
)

// nolint: godot // ignore period at end for comment ending in a list
//
// New creates and returns a Vela engine capable of
// integrating with the configured executor.
//
// Currently the following executors are supported:
//
// * linux
// * local
// .
func New(s *Setup) (Engine, error) {
// validate the setup being provided
//
Expand Down
7 changes: 4 additions & 3 deletions executor/linux/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ func (c *client) GetRepo() (*library.Repo, error) {
}

// CancelBuild cancels the current build in execution.
// nolint: funlen // process of going through steps/services/stages is verbose and could be funcitonalized
//
//nolint:funlen // process of going through steps/services/stages is verbose and could be funcitonalized
func (c *client) CancelBuild() (*library.Build, error) {
// get the current build from the client
b, err := c.GetBuild()
Expand All @@ -65,7 +66,7 @@ func (c *client) CancelBuild() (*library.Build, error) {
}

// cancel non successful services
// nolint: dupl // false positive, steps/services are different
//nolint:dupl // false positive, steps/services are different
for _, _service := range pipeline.Services {
// load the service from the client
//
Expand Down Expand Up @@ -106,7 +107,7 @@ func (c *client) CancelBuild() (*library.Build, error) {
}

// cancel non successful steps
// nolint: dupl // false positive, steps/services are different
//nolint:dupl // false positive, steps/services are different
for _, _step := range pipeline.Steps {
// load the step from the client
//
Expand Down
6 changes: 4 additions & 2 deletions executor/linux/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (c *client) CreateBuild(ctx context.Context) error {
// send API call to update the build
//
// https://pkg.go.dev/github.com/go-vela/sdk-go/vela?tab=doc#BuildService.Update
//nolint:contextcheck // ignore passing context
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: %w", c.err)
Expand Down Expand Up @@ -162,6 +163,7 @@ func (c *client) PlanBuild(ctx context.Context) error {

c.Logger.Infof("pulling %s %s secret %s", secret.Engine, secret.Type, secret.Name)

//nolint:contextcheck // ignore passing context
s, err := c.secret.pull(secret)
if err != nil {
c.err = err
Expand Down Expand Up @@ -189,7 +191,7 @@ 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 and logging messages
//nolint:funlen // ignore function length due to comments and logging messages
func (c *client) AssembleBuild(ctx context.Context) error {
// defer taking a snapshot of the build
//
Expand Down Expand Up @@ -268,7 +270,7 @@ func (c *client) AssembleBuild(ctx context.Context) error {
for _, s := range c.pipeline.Stages {
// TODO: remove hardcoded reference
//
// nolint: goconst // ignore making a constant for now
//nolint:goconst // ignore making a constant for now
if s.Name == "init" {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions executor/linux/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type (
err error
}

// nolint: structcheck // ignore false positive
//nolint:structcheck // ignore false positive
svc struct {
client *client
}
Expand Down Expand Up @@ -86,7 +86,7 @@ func Equal(a, b *client) bool {

// New returns an Executor implementation that integrates with a Linux instance.
//
// nolint: revive // 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)
Expand Down
4 changes: 3 additions & 1 deletion executor/linux/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ func (s *secretSvc) exec(ctx context.Context, p *pipeline.SecretSlice) error {
// send API call to update the build
//
// https://pkg.go.dev/github.com/go-vela/sdk-go/vela?tab=doc#StepService.Update
//nolint:contextcheck // ignore passing context
_, _, err = s.client.Vela.Step.Update(s.client.repo.GetOrg(), s.client.repo.GetName(), s.client.build.GetNumber(), _init)
if err != nil {
s.client.Logger.Errorf("unable to upload init state: %v", err)
Expand All @@ -186,7 +187,7 @@ func (s *secretSvc) exec(ctx context.Context, p *pipeline.SecretSlice) error {

// pull defines a function that pulls the secrets from the server for a given pipeline.
func (s *secretSvc) pull(secret *pipeline.Secret) (*library.Secret, error) {
// nolint: staticcheck // reports the value is never used but we return it
//nolint:staticcheck // reports the value is never used but we return it
_secret := new(library.Secret)

switch secret.Type {
Expand Down Expand Up @@ -314,6 +315,7 @@ 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:contextcheck // ignore passing context
_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
Expand Down
4 changes: 2 additions & 2 deletions executor/linux/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ package linux
import (
"context"
"flag"
"io/ioutil"
"net/http/httptest"
"os"
"testing"

"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -290,7 +290,7 @@ func TestLinux_Secret_exec(t *testing.T) {
// run tests
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
file, _ := ioutil.ReadFile(test.pipeline)
file, _ := os.ReadFile(test.pipeline)

p, _, err := compiler.
Duplicate().
Expand Down
10 changes: 7 additions & 3 deletions executor/linux/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"io"
"time"

"github.com/go-vela/types/constants"
Expand Down Expand Up @@ -84,6 +84,7 @@ func (c *client) PlanService(ctx context.Context, ctn *pipeline.Container) error
// send API call to update the service
//
// https://pkg.go.dev/github.com/go-vela/sdk-go/vela?tab=doc#SvcService.Update
//nolint:contextcheck // ignore passing context
_service, _, err = c.Vela.Svc.Update(c.repo.GetOrg(), c.repo.GetName(), c.build.GetNumber(), _service)
if err != nil {
return err
Expand All @@ -105,6 +106,7 @@ func (c *client) PlanService(ctx context.Context, ctn *pipeline.Container) error
// send API call to capture the service log
//
// https://pkg.go.dev/github.com/go-vela/sdk-go/vela?tab=doc#LogService.GetService
//nolint:contextcheck // ignore passing context
_log, _, err := c.Vela.Log.GetService(c.repo.GetOrg(), c.repo.GetName(), c.build.GetNumber(), _service.GetNumber())
if err != nil {
return err
Expand Down Expand Up @@ -155,7 +157,7 @@ func (c *client) ExecService(ctx context.Context, ctn *pipeline.Container) error

// StreamService tails the output for a service.
//
// nolint: funlen // ignore function length
//nolint:funlen // ignore function length
func (c *client) StreamService(ctx context.Context, ctn *pipeline.Container) error {
// update engine logger with service metadata
//
Expand All @@ -181,7 +183,7 @@ func (c *client) StreamService(ctx context.Context, ctn *pipeline.Container) err
defer rc.Close()

// read all output from the runtime container
data, err := ioutil.ReadAll(rc)
data, err := io.ReadAll(rc)
if err != nil {
logger.Errorf("unable to read container output for upload: %v", err)

Expand All @@ -204,6 +206,7 @@ func (c *client) StreamService(ctx context.Context, ctn *pipeline.Container) err
// send API call to update the logs for the service
//
// https://pkg.go.dev/github.com/go-vela/sdk-go/vela?tab=doc#LogService.UpdateService
//nolint:contextcheck // ignore passing context
_, _, err = c.Vela.Log.UpdateService(c.repo.GetOrg(), c.repo.GetName(), c.build.GetNumber(), ctn.Number, _log)
if err != nil {
logger.Errorf("unable to upload container logs: %v", err)
Expand Down Expand Up @@ -323,6 +326,7 @@ func (c *client) StreamService(ctx context.Context, ctn *pipeline.Container) err
// send API call to append the logs for the service
//
// https://pkg.go.dev/github.com/go-vela/sdk-go/vela?tab=doc#LogService.UpdateService
//nolint:contextcheck // ignore passing context
_log, _, err = c.Vela.Log.UpdateService(c.repo.GetOrg(), c.repo.GetName(), c.build.GetNumber(), ctn.Number, _log)
if err != nil {
return err
Expand Down
10 changes: 7 additions & 3 deletions executor/linux/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"io"
"strings"
"time"

Expand Down Expand Up @@ -91,6 +91,7 @@ func (c *client) PlanStep(ctx context.Context, ctn *pipeline.Container) error {
// send API call to update the step
//
// https://pkg.go.dev/github.com/go-vela/sdk-go/vela?tab=doc#StepService.Update
//nolint:contextcheck // ignore passing context
_step, _, err = c.Vela.Step.Update(c.repo.GetOrg(), c.repo.GetName(), c.build.GetNumber(), _step)
if err != nil {
return err
Expand All @@ -112,6 +113,7 @@ func (c *client) PlanStep(ctx context.Context, ctn *pipeline.Container) error {
// send API call to capture the step log
//
// https://pkg.go.dev/github.com/go-vela/sdk-go/vela?tab=doc#LogService.GetStep
//nolint:contextcheck // ignore passing context
_log, _, err := c.Vela.Log.GetStep(c.repo.GetOrg(), c.repo.GetName(), c.build.GetNumber(), _step.GetNumber())
if err != nil {
return err
Expand Down Expand Up @@ -186,7 +188,7 @@ func (c *client) ExecStep(ctx context.Context, ctn *pipeline.Container) error {

// StreamStep tails the output for a step.
//
// nolint: funlen // ignore function length
//nolint:funlen // ignore function length
func (c *client) StreamStep(ctx context.Context, ctn *pipeline.Container) error {
// TODO: remove hardcoded reference
if ctn.Name == "init" {
Expand Down Expand Up @@ -219,7 +221,7 @@ func (c *client) StreamStep(ctx context.Context, ctn *pipeline.Container) error
defer rc.Close()

// read all output from the runtime container
data, err := ioutil.ReadAll(rc)
data, err := io.ReadAll(rc)
if err != nil {
logger.Errorf("unable to read container output for upload: %v", err)

Expand Down Expand Up @@ -247,6 +249,7 @@ func (c *client) StreamStep(ctx context.Context, ctn *pipeline.Container) error
// send API call to update the logs for the step
//
// https://pkg.go.dev/github.com/go-vela/sdk-go/vela?tab=doc#LogService.UpdateStep
//nolint:contextcheck // ignore passing context
_, _, err = c.Vela.Log.UpdateStep(c.repo.GetOrg(), c.repo.GetName(), c.build.GetNumber(), ctn.Number, _log)
if err != nil {
logger.Errorf("unable to upload container logs: %v", err)
Expand Down Expand Up @@ -376,6 +379,7 @@ func (c *client) StreamStep(ctx context.Context, ctn *pipeline.Container) error
// send API call to append the logs for the step
//
// https://pkg.go.dev/github.com/go-vela/sdk-go/vela?tab=doc#LogStep.UpdateStep
//nolint:contextcheck // ignore passing context
_log, _, err = c.Vela.Log.UpdateStep(c.repo.GetOrg(), c.repo.GetName(), c.build.GetNumber(), ctn.Number, _log)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions executor/linux/step_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package linux

import (
"context"
"io/ioutil"
"net/http/httptest"
"os"
"reflect"
"testing"

Expand Down Expand Up @@ -566,7 +566,7 @@ func TestLinux_DestroyStep(t *testing.T) {
}

func TestLinux_getSecretValues(t *testing.T) {
fileSecret, err := ioutil.ReadFile("./testdata/step/secret_text.txt")
fileSecret, err := os.ReadFile("./testdata/step/secret_text.txt")
if err != nil {
t.Errorf("unable to read from test data file secret. Err: %v", err)
}
Expand Down
7 changes: 4 additions & 3 deletions executor/local/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ func (c *client) GetRepo() (*library.Repo, error) {
}

// CancelBuild cancels the current build in execution.
// nolint: funlen // process of going through steps/services/stages is verbose and could be funcitonalized
//
//nolint:funlen // process of going through steps/services/stages is verbose and could be funcitonalized
func (c *client) CancelBuild() (*library.Build, error) {
// get the current build from the client
b, err := c.GetBuild()
Expand All @@ -65,7 +66,7 @@ func (c *client) CancelBuild() (*library.Build, error) {
}

// cancel non successful services
// nolint: dupl // false positive, steps/services are different
//nolint:dupl // false positive, steps/services are different
for _, _service := range pipeline.Services {
// load the service from the client
//
Expand Down Expand Up @@ -106,7 +107,7 @@ func (c *client) CancelBuild() (*library.Build, error) {
}

// cancel non successful steps
// nolint: dupl // false positive, steps/services are different
//nolint:dupl // false positive, steps/services are different
for _, _step := range pipeline.Steps {
// load the step from the client
//
Expand Down
Loading