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(worker): add worker registration #503

Closed
wants to merge 474 commits into from
Closed

Conversation

timhuynh94
Copy link
Contributor

@timhuynh94 timhuynh94 commented Aug 30, 2023

Changes:

  • functionally "group" SERVER_SECRET, QUEUE_PUBLIC_KEY and QUEUE_ADDRESS and treat them as a WorkerRegistration payload
  • if all 3 are passed to the worker in ENV then skip registration
  • if any are not provided, block until /register is hit
  • in api/register.go extract (1) token (2) pub key (3) queue address from the json body and pass it along through one channel that uses WorkerRegistration struct

Depends on #498 , #307

jbrockopp and others added 30 commits October 27, 2021 11:02
* revert: stream container logs

* feat: add flag to enable streaming logs

* feat(executor): add logic to stream logs if enabled

* enhance: make log publishing method configurable

* enhance: use configurable log publishing method

* chore: configure time log publish method for local

* chore: address linter feedback

* chore: fix tests for code changes

* chore: address linter feedback v2
* enhance(version): add fallback for empty tag

* enhance(version): use go version from runtime library

* chore: clean go code
* StepFromContainer -> StepFromContainerEnvironment

* Use library.StepFromBuildContainer to create new Steps

* update go-vela/types

* go mod tidy

Co-authored-by: David May <[email protected]>
* initial changes

* add some replace logic for secret masking

* bringing in new types

* fix go mod validate

* multi line compatibility and initial testing work

* added testing for internal secret masking

* add back accidental deletion of error checking

Co-authored-by: Jordan Brockopp <[email protected]>
* update copyright year to 2022

* fix quotes
@timhuynh94 timhuynh94 marked this pull request as ready for review August 30, 2023 21:08
@timhuynh94 timhuynh94 requested a review from a team as a code owner August 30, 2023 21:08
@timhuynh94 timhuynh94 changed the title V21 queue registration feat (worker): Add worker registration Sep 5, 2023
@wass3r wass3r changed the title feat (worker): Add worker registration feat(worker): add worker registration Sep 6, 2023
@codecov
Copy link

codecov bot commented Sep 6, 2023

Codecov Report

Merging #503 (92f1d04) into main (dd23185) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #503   +/-   ##
=======================================
  Coverage   83.44%   83.44%           
=======================================
  Files          69       69           
  Lines        5381     5381           
=======================================
  Hits         4490     4490           
  Misses        746      746           
  Partials      145      145           
Files Changed Coverage Δ
router/middleware/worker_registration.go 100.00% <100.00%> (ø)

}

c.JSON(http.StatusOK, "successfully passed token to worker")
}

// validatePubKey is a helper function to validate
// the provided pubkey
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
Comment should end in a period (godot)

}

// validateQueueAddress is a helper function to validate
// the provided queue address
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
Comment should end in a period (godot)

@@ -127,3 +149,44 @@ func getSubjectFromToken(token string) (string, error) {

return sub, nil
}

// validatePubKey is a helper function to validate
// the provided pubkey
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
Comment should end in a period (godot)

//
// Use of this source code is governed by the LICENSE file in this repository.

package worker

import (
"encoding/base64"
"fmt"
"github.com/go-vela/server/util"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
File is not goimports-ed (goimports)

@@ -5,6 +5,7 @@
package middleware

import (
"github.com/go-vela/types/library"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
File is not goimports-ed (goimports)

"fmt"
"github.com/go-vela/server/util"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
File is not goimports-ed (goimports)

@@ -13,12 +14,13 @@ import (
"github.com/gin-gonic/gin"
)

func TestMiddleware_RegisterToken(t *testing.T) {
func TestMiddleware_WorkerRegistration(t *testing.T) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
unnecessary leading newline (whitespace)

@@ -45,7 +45,6 @@ func (w *Worker) exec(index int, config *library.Worker) error {
if err != nil {
return err
}

if item == nil {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
if statements should only be cuddled with assignments (wsl)

// once worker created/check in, queue details are used to setup queue here.
w.Config.Queue.Address = t.GetQueueAddress()
w.Config.Queue.PublicKey = t.GetPublicKey()
logrus.Trace("Validating queue details")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
only cuddled expressions if assigning variable or using from line above (wsl)

@@ -173,6 +191,7 @@ func (w *Worker) operate(ctx context.Context) error {
// (do not pass the context to avoid errors in one
// executor+build inadvertently canceling other builds)
//nolint:contextcheck // ignore passing context

err = w.exec(id, registryWorker)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
Function exec->exec$1 should pass the context parameter (contextcheck)

@timhuynh94 timhuynh94 closed this Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.