Skip to content

Commit 96d569b

Browse files
timhuynh94TimHuynhKellyMerrick
authored
fix(int)!: fix int types and update to urfave v3 (#632)
* fix(int): fix int types * chore(urfave cli): bump to v3 * converting some of the flags * more v3 * more changes to v3 * chore(deps): update server to current main * point to latest sdk-go * make clean --------- Co-authored-by: TimHuynh <[email protected]> Co-authored-by: Kelly Merrick <[email protected]>
1 parent 96e8f70 commit 96d569b

28 files changed

+388
-275
lines changed

cmd/vela-worker/flags.go

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
package main
44

55
import (
6+
"context"
7+
"fmt"
8+
"strings"
69
"time"
710

8-
"github.com/urfave/cli/v2"
11+
"github.com/urfave/cli/v3"
912

1013
"github.com/go-vela/server/queue"
1114
"github.com/go-vela/worker/executor"
@@ -19,43 +22,56 @@ func flags() []cli.Flag {
1922
f := []cli.Flag{
2023

2124
&cli.StringFlag{
22-
EnvVars: []string{"WORKER_ADDR", "VELA_WORKER_ADDR", "VELA_WORKER"},
2325
Name: "worker.addr",
2426
Usage: "Worker server address as a fully qualified url (<scheme>://<host>)",
27+
Sources: cli.EnvVars("WORKER_ADDR", "VELA_WORKER_ADDR", "VELA_WORKER"),
28+
Action: func(_ context.Context, _ *cli.Command, v string) error {
29+
// check if the worker address has a scheme
30+
if !strings.Contains(v, "://") {
31+
return fmt.Errorf("worker address must be fully qualified (<scheme>://<host>)")
32+
}
33+
34+
// check if the worker address has a trailing slash
35+
if strings.HasSuffix(v, "/") {
36+
return fmt.Errorf("worker address must not have trailing slash")
37+
}
38+
39+
return nil
40+
},
2541
},
2642

2743
&cli.DurationFlag{
28-
EnvVars: []string{"WORKER_CHECK_IN", "VELA_CHECK_IN", "CHECK_IN"},
2944
Name: "checkIn",
3045
Usage: "time to wait in between checking in with the server",
46+
Sources: cli.EnvVars("WORKER_CHECK_IN", "VELA_CHECK_IN", "CHECK_IN"),
3147
Value: 15 * time.Minute,
3248
},
3349

3450
// Build Flags
3551

3652
&cli.IntFlag{
37-
EnvVars: []string{"WORKER_BUILD_LIMIT", "VELA_BUILD_LIMIT", "BUILD_LIMIT"},
3853
Name: "build.limit",
3954
Usage: "maximum amount of builds that can run concurrently",
55+
Sources: cli.EnvVars("WORKER_BUILD_LIMIT", "VELA_BUILD_LIMIT", "BUILD_LIMIT"),
4056
Value: 1,
4157
},
4258
&cli.DurationFlag{
43-
EnvVars: []string{"WORKER_BUILD_TIMEOUT", "VELA_BUILD_TIMEOUT", "BUILD_TIMEOUT"},
4459
Name: "build.timeout",
4560
Usage: "maximum amount of time a build can run for",
61+
Sources: cli.EnvVars("WORKER_BUILD_TIMEOUT", "VELA_BUILD_TIMEOUT", "BUILD_TIMEOUT"),
4662
Value: 30 * time.Minute,
4763
},
4864

4965
// Logger Flags
5066

5167
&cli.StringFlag{
52-
EnvVars: []string{"WORKER_LOG_FORMAT", "VELA_LOG_FORMAT", "LOG_FORMAT"},
5368
Name: "log.format",
5469
Usage: "set log format for the worker",
70+
Sources: cli.EnvVars("WORKER_LOG_FORMAT", "VELA_LOG_FORMAT", "LOG_FORMAT"),
5571
Value: "json",
5672
},
5773
&cli.StringFlag{
58-
EnvVars: []string{"WORKER_LOG_LEVEL", "VELA_LOG_LEVEL", "LOG_LEVEL"},
74+
Sources: cli.EnvVars("WORKER_LOG_LEVEL", "VELA_LOG_LEVEL", "LOG_LEVEL"),
5975
Name: "log.level",
6076
Usage: "set log level for the worker",
6177
Value: "info",
@@ -64,30 +80,30 @@ func flags() []cli.Flag {
6480
// Server Flags
6581

6682
&cli.StringFlag{
67-
EnvVars: []string{"WORKER_SERVER_ADDR", "VELA_SERVER_ADDR", "VELA_SERVER", "SERVER_ADDR"},
6883
Name: "server.addr",
6984
Usage: "Vela server address as a fully qualified url (<scheme>://<host>)",
85+
Sources: cli.EnvVars("WORKER_SERVER_ADDR", "VELA_SERVER_ADDR", "VELA_SERVER", "SERVER_ADDR"),
7086
},
7187
&cli.StringFlag{
72-
EnvVars: []string{"WORKER_SERVER_SECRET", "VELA_SERVER_SECRET", "SERVER_SECRET"},
7388
Name: "server.secret",
7489
Usage: "secret used for server <-> worker communication",
90+
Sources: cli.EnvVars("WORKER_SERVER_SECRET", "VELA_SERVER_SECRET", "SERVER_SECRET"),
7591
Value: "",
7692
},
7793
&cli.StringFlag{
78-
EnvVars: []string{"WORKER_SERVER_CERT", "VELA_SERVER_CERT", "SERVER_CERT"},
7994
Name: "server.cert",
8095
Usage: "optional TLS certificate for https",
96+
Sources: cli.EnvVars("WORKER_SERVER_CERT", "VELA_SERVER_CERT", "SERVER_CERT"),
8197
},
8298
&cli.StringFlag{
83-
EnvVars: []string{"WORKER_SERVER_CERT_KEY", "VELA_SERVER_CERT_KEY", "SERVER_CERT_KEY"},
8499
Name: "server.cert-key",
85100
Usage: "optional TLS certificate key",
101+
Sources: cli.EnvVars("WORKER_SERVER_CERT_KEY", "VELA_SERVER_CERT_KEY", "SERVER_CERT_KEY"),
86102
},
87103
&cli.StringFlag{
88-
EnvVars: []string{"WORKER_SERVER_TLS_MIN_VERSION", "VELA_SERVER_TLS_MIN_VERSION", "SERVER_TLS_MIN_VERSION"},
89104
Name: "server.tls-min-version",
90105
Usage: "optional TLS minimum version requirement",
106+
Sources: cli.EnvVars("WORKER_SERVER_TLS_MIN_VERSION", "VELA_SERVER_TLS_MIN_VERSION", "SERVER_TLS_MIN_VERSION"),
91107
Value: "1.2",
92108
},
93109
}

cmd/vela-worker/main.go

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
package main
44

55
import (
6+
"context"
67
"encoding/json"
78
"fmt"
89
"os"
9-
"time"
1010

1111
"github.com/sirupsen/logrus"
12-
"github.com/urfave/cli/v2"
12+
"github.com/urfave/cli/v3"
1313

1414
_ "github.com/joho/godotenv/autoload"
1515

@@ -45,35 +45,20 @@ func main() {
4545
// output the version information to stdout
4646
fmt.Fprintf(os.Stdout, "%s\n", string(bytes))
4747

48-
app := cli.NewApp()
49-
50-
// Worker Information
51-
52-
app.Name = "vela-worker"
53-
app.HelpName = "vela-worker"
54-
app.Usage = "Vela build daemon designed for executing pipelines"
55-
app.Copyright = "Copyright 2019 Target Brands, Inc. All rights reserved."
56-
app.Authors = []*cli.Author{
57-
{
58-
Name: "Vela Admins",
59-
60-
},
48+
cmd := cli.Command{
49+
Name: "vela-worker",
50+
Version: v.Semantic(),
51+
Action: run,
52+
Usage: "Vela build daemon designed for executing pipelines",
6153
}
6254

63-
// Worker Metadata
64-
65-
app.Action = run
66-
app.Compiled = time.Now()
67-
app.Version = v.Semantic()
68-
6955
// Worker Flags
7056

71-
app.Flags = flags()
57+
cmd.Flags = flags()
7258

7359
// Worker Start
7460

75-
err = app.Run(os.Args)
76-
if err != nil {
61+
if err = cmd.Run(context.Background(), os.Args); err != nil {
7762
logrus.Fatal(err)
7863
}
7964
}

cmd/vela-worker/operate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func (w *Worker) operate(ctx context.Context) error {
3131
registryWorker.SetHostname(w.Config.API.Address.Hostname())
3232
registryWorker.SetAddress(w.Config.API.Address.String())
3333
registryWorker.SetActive(true)
34-
registryWorker.SetBuildLimit(int64(w.Config.Build.Limit))
34+
registryWorker.SetBuildLimit(int32(w.Config.Build.Limit))
3535

3636
// set routes from config if set or defaulted to `vela`
3737
if (len(w.Config.Queue.Routes) > 0) && (w.Config.Queue.Routes[0] != "NONE" && w.Config.Queue.Routes[0] != "") {

cmd/vela-worker/run.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
package main
44

55
import (
6+
"context"
67
"fmt"
78
"net/url"
89

910
"github.com/gin-gonic/gin"
1011
"github.com/sirupsen/logrus"
11-
"github.com/urfave/cli/v2"
12+
"github.com/urfave/cli/v3"
1213

1314
_ "github.com/joho/godotenv/autoload"
1415

@@ -22,7 +23,7 @@ import (
2223

2324
// run executes the worker based
2425
// off the configuration provided.
25-
func run(c *cli.Context) error {
26+
func run(ctx context.Context, c *cli.Command) error {
2627
// set log format for the worker
2728
switch c.String("log.format") {
2829
case "t", "text", "Text", "TEXT":
@@ -95,15 +96,15 @@ func run(c *cli.Context) error {
9596
},
9697
// build configuration
9798
Build: &Build{
98-
Limit: c.Int("build.limit"),
99+
Limit: int(c.Int("build.limit")),
99100
Timeout: c.Duration("build.timeout"),
100101
},
101102
// build configuration
102103
CheckIn: c.Duration("checkIn"),
103104
// executor configuration
104105
Executor: &executor.Setup{
105106
Driver: c.String("executor.driver"),
106-
MaxLogSize: c.Uint("executor.max_log_size"),
107+
MaxLogSize: uint(c.Uint("executor.max_log_size")),
107108
LogStreamingTimeout: c.Duration("executor.log_streaming_timeout"),
108109
EnforceTrustedRepos: c.Bool("executor.enforce-trusted-repos"),
109110
OutputCtn: outputsCtn,
@@ -119,7 +120,7 @@ func run(c *cli.Context) error {
119120
ConfigFile: c.String("runtime.config"),
120121
Namespace: c.String("runtime.namespace"),
121122
PodsTemplateName: c.String("runtime.pods-template-name"),
122-
PodsTemplateFile: c.Path("runtime.pods-template-file"),
123+
PodsTemplateFile: c.String("runtime.pods-template-file"),
123124
HostVolumes: c.StringSlice("runtime.volumes"),
124125
PrivilegedImages: c.StringSlice("runtime.privileged-images"),
125126
DropCapabilities: c.StringSlice("runtime.drop-capabilities"),

executor/executor_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ var (
260260
Link: vela.String("https://github.com/github/octocat"),
261261
Clone: vela.String("https://github.com/github/octocat.git"),
262262
Branch: vela.String("main"),
263-
Timeout: vela.Int64(60),
263+
Timeout: vela.Int32(60),
264264
Visibility: vela.String("public"),
265265
Private: vela.Bool(false),
266266
Trusted: vela.Bool(false),
@@ -271,9 +271,9 @@ var (
271271

272272
_build = &api.Build{
273273
ID: vela.Int64(1),
274-
Number: vela.Int(1),
274+
Number: vela.Int64(1),
275275
Repo: _repo,
276-
Parent: vela.Int(1),
276+
Parent: vela.Int64(1),
277277
Event: vela.String("push"),
278278
Status: vela.String("success"),
279279
Error: vela.String(""),

executor/flags.go

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package executor
55
import (
66
"time"
77

8-
"github.com/urfave/cli/v2"
8+
"github.com/urfave/cli/v3"
99

1010
"github.com/go-vela/server/constants"
1111
)
@@ -18,35 +18,47 @@ var Flags = []cli.Flag{
1818
// Executor Flags
1919

2020
&cli.StringFlag{
21-
EnvVars: []string{"VELA_EXECUTOR_DRIVER", "EXECUTOR_DRIVER"},
22-
FilePath: "/vela/executor/driver",
23-
Name: "executor.driver",
24-
Usage: "driver to be used for the executor",
25-
Value: constants.DriverLinux,
21+
Name: "executor.driver",
22+
Usage: "driver to be used for the executor",
23+
Sources: cli.NewValueSourceChain(
24+
cli.EnvVar("VELA_EXECUTOR_DRIVER"),
25+
cli.EnvVar("EXECUTOR_DRIVER"),
26+
cli.File("/vela/executor/driver"),
27+
),
28+
Value: constants.DriverLinux,
2629
},
2730
&cli.UintFlag{
28-
EnvVars: []string{"VELA_EXECUTOR_MAX_LOG_SIZE", "EXECUTOR_MAX_LOG_SIZE"},
29-
FilePath: "/vela/executor/max_log_size",
30-
Name: "executor.max_log_size",
31-
Usage: "maximum log size (in bytes)",
31+
Name: "executor.max_log_size",
32+
Usage: "maximum log size (in bytes)",
33+
Sources: cli.NewValueSourceChain(
34+
cli.EnvVar("VELA_EXECUTOR_MAX_LOG_SIZE"),
35+
cli.EnvVar("EXECUTOR_MAX_LOG_SIZE"),
36+
cli.File("/vela/executor/max_log_size"),
37+
),
3238
},
3339
&cli.DurationFlag{
34-
EnvVars: []string{"WORKER_LOG_STREAMING_TIMEOUT", "VELA_LOG_STREAMING_TIMEOUT", "LOG_STREAMING_TIMEOUT"},
3540
Name: "executor.log_streaming_timeout",
3641
Usage: "maximum amount of time to wait for log streaming after build completes",
42+
Sources: cli.EnvVars("WORKER_LOG_STREAMING_TIMEOUT", "VELA_LOG_STREAMING_TIMEOUT", "LOG_STREAMING_TIMEOUT"),
3743
Value: 5 * time.Minute,
3844
},
3945
&cli.BoolFlag{
40-
EnvVars: []string{"VELA_EXECUTOR_ENFORCE_TRUSTED_REPOS", "EXECUTOR_ENFORCE_TRUSTED_REPOS"},
41-
FilePath: "/vela/executor/enforce_trusted_repos",
42-
Name: "executor.enforce-trusted-repos",
43-
Usage: "enforce trusted repo restrictions for privileged images",
44-
Value: true,
46+
Name: "executor.enforce-trusted-repos",
47+
Usage: "enforce trusted repo restrictions for privileged images",
48+
Sources: cli.NewValueSourceChain(
49+
cli.EnvVar("VELA_EXECUTOR_ENFORCE_TRUSTED_REPOS"),
50+
cli.EnvVar("EXECUTOR_ENFORCE_TRUSTED_REPOS"),
51+
cli.File("/vela/executor/enforce_trusted_repos"),
52+
),
53+
Value: true,
4554
},
4655
&cli.StringFlag{
47-
EnvVars: []string{"VELA_EXECUTOR_OUTPUTS_IMAGE", "EXECUTOR_OUTPUTS_IMAGE"},
48-
FilePath: "/vela/executor/outputs_image",
49-
Name: "executor.outputs-image",
50-
Usage: "image used for the outputs container sidecar",
56+
Name: "executor.outputs-image",
57+
Usage: "image used for the outputs container sidecar",
58+
Sources: cli.NewValueSourceChain(
59+
cli.EnvVar("VELA_EXECUTOR_OUTPUTS_IMAGE"),
60+
cli.EnvVar("EXECUTOR_OUTPUTS_IMAGE"),
61+
cli.File("/vela/executor/outputs_image"),
62+
),
5163
},
5264
}

executor/linux/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ func (c *client) AssembleBuild(ctx context.Context) error {
396396
}
397397

398398
// create outputs container with a timeout equal to the repo timeout
399-
c.err = c.outputs.create(ctx, c.OutputCtn, (int64(60) * c.build.GetRepo().GetTimeout()))
399+
c.err = c.outputs.create(ctx, c.OutputCtn, int64(60*c.build.GetRepo().GetTimeout()))
400400
if c.err != nil {
401401
return fmt.Errorf("unable to create outputs container: %w", c.err)
402402
}

0 commit comments

Comments
 (0)