Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(build_token): worker changes for build token implementation #427

Merged
merged 4 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 2 additions & 3 deletions cmd/vela-worker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

// helper function to setup the queue from the CLI arguments.
func setupClient(s *Server) (*vela.Client, error) {
func setupClient(s *Server, token string) (*vela.Client, error) {
logrus.Debug("creating vela client from worker configuration")

// create a new Vela client from the server configuration
Expand All @@ -21,11 +21,10 @@ func setupClient(s *Server) (*vela.Client, error) {
if err != nil {
return nil, err
}

// set token for authentication with the server
//
// https://pkg.go.dev/github.com/go-vela/sdk-go/vela?tab=doc#AuthenticationService.SetTokenAuth
vela.Authentication.SetTokenAuth(s.Secret)
vela.Authentication.SetTokenAuth(token)

return vela, nil
}
14 changes: 13 additions & 1 deletion cmd/vela-worker/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ func (w *Worker) exec(index int) error {
return nil
}

// GET build token from server to setup execBuildClient
bt, _, err := w.VelaClient.Build.GetBuildToken(item.Repo.GetOrg(), item.Repo.GetName(), item.Build.GetNumber())
ecrupper marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
logrus.Errorf("Unable to GetBuildToken: %s", err)
return err
}
// set up build client with build token as auth
execBuildClient, err := setupClient(w.Config.Server, bt.GetToken())
if err != nil {
return err
}

// create logger with extra metadata
//
// https://pkg.go.dev/github.com/sirupsen/logrus?tab=doc#WithFields
Expand Down Expand Up @@ -79,7 +91,7 @@ func (w *Worker) exec(index int) error {
LogStreamingTimeout: w.Config.Executor.LogStreamingTimeout,
EnforceTrustedRepos: w.Config.Executor.EnforceTrustedRepos,
PrivilegedImages: w.Config.Runtime.PrivilegedImages,
Client: w.VelaClient,
Client: execBuildClient,
Hostname: w.Config.API.Address.Hostname(),
Runtime: w.Runtime,
Build: item.Build,
Expand Down
4 changes: 2 additions & 2 deletions cmd/vela-worker/operate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
func (w *Worker) operate(ctx context.Context) error {
var err error

// setup the client
w.VelaClient, err = setupClient(w.Config.Server)
// setup the vela client with the server
w.VelaClient, err = setupClient(w.Config.Server, w.Config.Server.Secret)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/vela-worker/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/sirupsen/logrus"
)

// checkIn is a helper function to to phone home to the server.
// checkIn is a helper function to phone home to the server.
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())
Expand Down