Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ linters:
- unparam
- unused
- whitespace
- wsl
- wsl_v5
settings:
dupl:
threshold: 100
Expand All @@ -51,6 +51,10 @@ linters:
require-explanation: true
require-specific: true
allow-unused: false
wsl_v5:
allow-first-in-block: true
allow-whole-block: false
branch-max-lines: 2
exclusions:
generated: lax
presets:
Expand Down
7 changes: 4 additions & 3 deletions cmd/vela-worker/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
// exec is a helper function to poll the queue
// and execute Vela pipelines for the Worker.
//
//nolint:nilerr,funlen // ignore returning nil - don't want to crash worker
//nolint:gocyclo,funlen // ignore cyclomatic complexity and function length
func (w *Worker) exec(index int, config *api.Worker) error {
var err error

Expand Down Expand Up @@ -347,6 +347,7 @@ func (w *Worker) exec(index int, config *api.Worker) error {
// log/event streaming uses buildCtx so that it is not subject to the timeout.
go func() {
defer wg.Done()

logger.Info("streaming build logs")
// execute the build with the executor
err = _executor.StreamBuild(buildCtx)
Expand All @@ -372,9 +373,9 @@ func (w *Worker) getWorkerStatusFromConfig(config *api.Worker) string {
switch rb := len(config.GetRunningBuilds()); {
case rb == 0:
return constants.WorkerStatusIdle
case rb < w.Config.Build.Limit:
case rb < int(w.Config.Build.Limit):
return constants.WorkerStatusAvailable
case rb == w.Config.Build.Limit:
case rb == int(w.Config.Build.Limit):
return constants.WorkerStatusBusy
default:
return constants.WorkerStatusError
Expand Down
2 changes: 1 addition & 1 deletion cmd/vela-worker/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func flags() []cli.Flag {

// Build Flags

&cli.IntFlag{
&cli.Int32Flag{
Name: "build.limit",
Usage: "maximum amount of builds that can run concurrently",
Sources: cli.EnvVars("WORKER_BUILD_LIMIT", "VELA_BUILD_LIMIT", "BUILD_LIMIT"),
Expand Down
6 changes: 3 additions & 3 deletions cmd/vela-worker/operate.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (w *Worker) operate(ctx context.Context) error {
registryWorker.SetHostname(w.Config.API.Address.Hostname())
registryWorker.SetAddress(w.Config.API.Address.String())
registryWorker.SetActive(true)
registryWorker.SetBuildLimit(int32(w.Config.Build.Limit))
registryWorker.SetBuildLimit(w.Config.Build.Limit)

// set routes from config if set or defaulted to `vela`
if (len(w.Config.Queue.Routes) > 0) && (w.Config.Queue.Routes[0] != "NONE" && w.Config.Queue.Routes[0] != "") {
Expand Down Expand Up @@ -131,7 +131,6 @@ func (w *Worker) operate(ctx context.Context) error {
}

w.QueueCheckedIn, err = w.queueCheckIn(gctx, registryWorker)

if err != nil {
// queue check in failed, retry
logrus.Errorf("unable to ping queue %v", err)
Expand Down Expand Up @@ -162,7 +161,7 @@ func (w *Worker) operate(ctx context.Context) error {
})

// iterate till the configured build limit
for i := 0; i < w.Config.Build.Limit; i++ {
for i := 0; i < int(w.Config.Build.Limit); i++ {
// evaluate and capture i at each iteration
//
// https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables
Expand Down Expand Up @@ -193,6 +192,7 @@ func (w *Worker) operate(ctx context.Context) error {

continue
}

select {
case <-gctx.Done():
logrus.WithFields(logrus.Fields{
Expand Down
6 changes: 3 additions & 3 deletions cmd/vela-worker/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ func run(ctx context.Context, c *cli.Command) error {
},
// build configuration
Build: &Build{
Limit: int(c.Int("build.limit")),
Limit: c.Int32("build.limit"),
Timeout: c.Duration("build.timeout"),
},
// build configuration
CheckIn: c.Duration("checkIn"),
// executor configuration
Executor: &executor.Setup{
Driver: c.String("executor.driver"),
MaxLogSize: uint(c.Uint("executor.max_log_size")),
MaxLogSize: c.Uint("executor.max_log_size"),
LogStreamingTimeout: c.Duration("executor.log_streaming_timeout"),
EnforceTrustedRepos: c.Bool("executor.enforce-trusted-repos"),
OutputCtn: outputsCtn,
Expand Down Expand Up @@ -172,5 +172,5 @@ func run(ctx context.Context, c *cli.Command) error {
}

// start the worker
return w.Start()
return w.Start(ctx)
}
10 changes: 8 additions & 2 deletions cmd/vela-worker/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
// serve traffic for web and API requests. The
// operator subprocess enables the Worker to
// poll the queue and execute Vela pipelines.
func (w *Worker) Start() error {
func (w *Worker) Start(ctx context.Context) error {
// create the context for controlling the worker subprocesses
ctx, done := context.WithCancel(context.Background())
ctx, done := context.WithCancel(ctx)
// create the errgroup for managing worker subprocesses
//
// https://pkg.go.dev/golang.org/x/sync/errgroup#Group
Expand All @@ -47,17 +47,21 @@ func (w *Worker) Start() error {
select {
case sig := <-signalChannel:
logrus.Infof("Received signal: %s", sig)

err := server.Shutdown(ctx)
if err != nil {
logrus.Error(err)
}

done()
case <-gctx.Done():
logrus.Info("Closing signal goroutine")

err := server.Shutdown(ctx)
if err != nil {
logrus.Error(err)
}

return gctx.Err()
}

Expand All @@ -67,7 +71,9 @@ func (w *Worker) Start() error {
// spawn goroutine for starting the server
g.Go(func() error {
var err error

logrus.Info("starting worker server")

if tlsCfg != nil {
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
Expand Down
2 changes: 1 addition & 1 deletion cmd/vela-worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type (

// Build represents the worker configuration for build information.
Build struct {
Limit int
Limit int32
Timeout time.Duration
}

Expand Down
2 changes: 1 addition & 1 deletion executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ var (
ID: "step_github_octocat_1_init",
Directory: "/home/github/octocat",
Image: "#init",
Name: "init",
Name: constants.InitName,
Number: 1,
Pull: "always",
},
Expand Down
14 changes: 0 additions & 14 deletions executor/linux/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ func (c *client) GetPipeline() (*pipeline.Build, error) {
}

// CancelBuild cancels the current build in execution.
//
//nolint:funlen // process of going through steps/services/stages is verbose and could be funcitonalized
func (c *client) CancelBuild() (*api.Build, error) {
// get the current build from the client
b, err := c.GetBuild()
Expand Down Expand Up @@ -76,16 +74,12 @@ func (c *client) CancelBuild() (*api.Build, error) {
switch s.GetStatus() {
// service is in a error state
case constants.StatusError:
break
// service is in a failure state
case constants.StatusFailure:
break
// service is in a killed state
case constants.StatusKilled:
break
// service is in a success state
case constants.StatusSuccess:
break
default:
// update the service with a canceled state
s.SetStatus(constants.StatusCanceled)
Expand Down Expand Up @@ -117,16 +111,12 @@ func (c *client) CancelBuild() (*api.Build, error) {
switch s.GetStatus() {
// step is in a error state
case constants.StatusError:
break
// step is in a failure state
case constants.StatusFailure:
break
// step is in a killed state
case constants.StatusKilled:
break
// step is in a success state
case constants.StatusSuccess:
break
default:
// update the step with a canceled state
s.SetStatus(constants.StatusCanceled)
Expand Down Expand Up @@ -160,16 +150,12 @@ func (c *client) CancelBuild() (*api.Build, error) {
switch s.GetStatus() {
// stage is in a error state
case constants.StatusError:
break
// stage is in a failure state
case constants.StatusFailure:
break
// stage is in a killed state
case constants.StatusKilled:
break
// stage is in a success state
case constants.StatusSuccess:
break
default:
// update the step with a canceled state
s.SetStatus(constants.StatusCanceled)
Expand Down
21 changes: 7 additions & 14 deletions executor/linux/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,8 @@ func (c *client) AssembleBuild(ctx context.Context) error {

// create the stages for the pipeline
for _, s := range c.pipeline.Stages {
// TODO: remove hardcoded reference
//
//nolint:goconst // ignore making a constant for now
if s.Name == "init" {
if s.Name == constants.InitName {
continue
}

Expand All @@ -308,8 +306,7 @@ func (c *client) AssembleBuild(ctx context.Context) error {

// create the steps for the pipeline
for _, s := range c.pipeline.Steps {
// TODO: remove hardcoded reference
if s.Name == "init" {
if s.Name == constants.InitName {
continue
}

Expand Down Expand Up @@ -480,8 +477,7 @@ func (c *client) ExecBuild(ctx context.Context) error {

// execute the steps for the pipeline
for _, _step := range c.pipeline.Steps {
// TODO: remove hardcoded reference
if _step.Name == "init" {
if _step.Name == constants.InitName {
continue
}

Expand Down Expand Up @@ -573,8 +569,7 @@ func (c *client) ExecBuild(ctx context.Context) error {

// iterate through each stage in the pipeline
for _, _stage := range c.pipeline.Stages {
// TODO: remove hardcoded reference
if _stage.Name == "init" {
if _stage.Name == constants.InitName {
continue
}

Expand Down Expand Up @@ -691,7 +686,7 @@ func (c *client) StreamBuild(ctx context.Context) error {
// into the container right before execution, rather than
// during build planning. It is only available for the Docker runtime.
//
//nolint:funlen // explanation takes up a lot of lines

func loadLazySecrets(c *client, _step *pipeline.Container) error {
_log := new(api.Log)

Expand Down Expand Up @@ -872,8 +867,7 @@ func (c *client) DestroyBuild(ctx context.Context) error {

// destroy the steps for the pipeline
for _, _step := range c.pipeline.Steps {
// TODO: remove hardcoded reference
if _step.Name == "init" {
if _step.Name == constants.InitName {
continue
}

Expand All @@ -887,8 +881,7 @@ func (c *client) DestroyBuild(ctx context.Context) error {

// destroy the stages for the pipeline
for _, _stage := range c.pipeline.Stages {
// TODO: remove hardcoded reference
if _stage.Name == "init" {
if _stage.Name == constants.InitName {
continue
}

Expand Down
Loading