-
Notifications
You must be signed in to change notification settings - Fork 433
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(engine): hatchery as a uservice - auth #3326
Conversation
Signed-off-by: Yvonnick Esnault <[email protected]>
Signed-off-by: Yvonnick Esnault <[email protected]>
WIP do not merge yet |
engine/api/hatchery.go
Outdated
@@ -34,37 +32,35 @@ func (api *API) registerHatcheryHandler() service.Handler { | |||
return sdk.WrapError(err, "registerHatcheryHandler> Cannot load hatchery %s", hatch.Name) | |||
} | |||
|
|||
tx, errBegin := api.mustDB().Begin() | |||
defer tx.Rollback() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error return value of tx.Rollback
is not checked
Signed-off-by: Yvonnick Esnault <[email protected]>
Signed-off-by: Yvonnick Esnault <[email protected]>
Signed-off-by: Yvonnick Esnault <[email protected]>
Signed-off-by: Yvonnick Esnault <[email protected]>
Signed-off-by: Yvonnick Esnault <[email protected]>
Signed-off-by: Yvonnick Esnault <[email protected]>
Signed-off-by: Yvonnick Esnault <[email protected]>
Signed-off-by: Yvonnick Esnault <[email protected]>
Signed-off-by: Yvonnick Esnault <[email protected]>
CDS Report ut-engine#5975.1 ✘
|
if hatchery.RatioService == 100 { | ||
where = " AND contains_service = true " | ||
} else if hatchery.RatioService == 0 { | ||
where = " AND (contains_service is NULL or contains_service = false) " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
contains_service is NULL . is mandatory ???
engine/api/workflow/gorp_model.go
Outdated
@@ -89,6 +89,7 @@ type JobRun struct { | |||
ExecGroups sql.NullString `db:"exec_groups"` | |||
PlatformPluginBinaries sql.NullString `db:"platform_plugin_binaries"` | |||
BookedBy sdk.Hatchery `db:"-"` | |||
ContainsService sql.NullBool `db:"contains_service"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sql.Bool ? ( is false is applied on old lines)
engine/sql/128_hatchery_type.sql
Outdated
|
||
ALTER TABLE hatchery | ||
ADD COLUMN worker_model_id BIGINT, | ||
ADD COLUMN model_type VARCHAR(50) DEFAULT '', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not used
engine/sql/128_hatchery_type.sql
Outdated
-- +migrate Up | ||
|
||
ALTER TABLE hatchery | ||
ADD COLUMN worker_model_id BIGINT, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove worker_model_id, localhatchery must check requirement from its path
engine/api/hatchery/hatchery.go
Outdated
var errg error | ||
h.UID, errg = generateID() | ||
hatchery.UID, errg = generateID() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not using sdk.UUID()
?
engine/api/hatchery/gorp_model.go
Outdated
) | ||
|
||
// Hatchery is a gorp wrapper around sdk.Hatchery | ||
type Hatchery sdk.Hatchery |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this type should be private
engine/api/hatchery/hatchery.go
Outdated
Cmd: "worker --api={{.API}} --token={{.Token}} --basedir={{.BaseDir}} --model={{.Model}} --name={{.Name}} --hatchery={{.Hatchery}} --hatchery-name={{.HatcheryName}} --insecure={{.HTTPInsecure}} --booked-workflow-job-id={{.WorkflowJobID}} --booked-pb-job-id={{.PipelineBuildJobID}} --single-use --force-exit", | ||
} | ||
if err := worker.InsertWorkerModel(db, &hatchery.Model); err != nil && strings.Contains(err.Error(), "idx_worker_model_name") { | ||
return sdk.ErrModelNameExist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may be we should update the model and not raise an error
engine/api/hatchery/hatchery.go
Outdated
} | ||
return nil, err | ||
return nil, sdk.ErrNotFound |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
really ?
engine/api/hatchery/hatchery.go
Outdated
|
||
var h sdk.Hatchery | ||
var wmID sql.NullInt64 | ||
var hatchery Hatchery | ||
hasher := sha512.New() | ||
hashed := base64.StdEncoding.EncodeToString(hasher.Sum([]byte(token))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
engine/api/hatchery/hatchery.go
Outdated
|
||
return nil | ||
} | ||
|
||
func generateID() (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this, sdk.UUID exists
engine/api/services.go
Outdated
} | ||
if svcs[i].Type == "hatchery" { | ||
log.Info("killDeadServices> Delete dead hatchery: %v", &svcs[i].Name) | ||
if err := hatchery.DeleteHatcheryByName(db, svcs[i].Name); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we shouldn't have to delete manually the hatchery when we remove the service. There should be a foreign key and a delete cascade
engine/api/services.go
Outdated
} | ||
case <-ctx.Done(): | ||
if err := ctx.Err(); err != nil { | ||
log.Error("Exiting killDeadServices: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return ?
Signed-off-by: Yvonnick Esnault <[email protected]>
Signed-off-by: Yvonnick Esnault <[email protected]>
Signed-off-by: Yvonnick Esnault <[email protected]>
engine/api/api_routes.go
Outdated
@@ -248,7 +246,6 @@ func (api *API) InitRouter() { | |||
r.Handle("/project/{permProjectKey}/push/workflows", r.POST(api.postWorkflowPushHandler)) | |||
|
|||
// Workflows run | |||
r.Handle("/project/{permProjectKey}/runs", r.GET(api.getWorkflowAllRunsHandler, EnableTracing())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not delete this
engine/api/hatchery/hatchery.go
Outdated
WHERE ( | ||
hatchery.group_id = ANY( | ||
services.type = 'hatchery' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the sdk constant
engine/api/hatchery/hatchery.go
Outdated
WHERE ( | ||
hatchery.group_id = ANY( | ||
services.type = 'hatchery' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idem
engine/api/mon_db.go
Outdated
} | ||
|
||
if _, err := workflow.LoadNodeJobRunQueue(ctx, api.mustDB(), api.Cache, permissions, groupsID, usr, nil, nil, nil); err != nil { | ||
if _, err := workflow.LoadNodeJobRunQueue(ctx, api.mustDB(), api.Cache, "", nil, permissions, groupsID, usr, nil, nil, nil); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too mush optional parameters
we need more specialized function of an option struct
engine/api/workflow_run.go
Outdated
@@ -136,18 +136,6 @@ func (api *API) searchWorkflowRun(ctx context.Context, w http.ResponseWriter, r | |||
return service.WriteJSON(w, runs, code) | |||
} | |||
|
|||
func (api *API) getWorkflowAllRunsHandler() service.Handler { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope
@@ -60,14 +60,29 @@ func LoadNodeJobRunQueue(ctx context.Context, db gorp.SqlExecutor, store cache.S | |||
statuses = []string{sdk.StatusWaiting.String()} | |||
} | |||
|
|||
var where string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the sql query is unreadable :(
how can we improve this code ?
engine/api/workflow_queue.go
Outdated
@@ -753,7 +754,15 @@ func getSinceUntilLimitHeader(ctx context.Context, w http.ResponseWriter, r *htt | |||
limit, _ = strconv.Atoi(limitHeader) | |||
} | |||
|
|||
return since, until, limit | |||
ratioServiceHeader := r.Header.Get("X-CDS-Ratio-Service") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why header and not queryParam ?
engine/api/workflow_queue.go
Outdated
@@ -702,7 +702,7 @@ func (api *API) countWorkflowJobQueueHandler() service.Handler { | |||
|
|||
func (api *API) getWorkflowJobQueueHandler() service.Handler { | |||
return func(ctx context.Context, w http.ResponseWriter, r *http.Request) error { | |||
since, until, limit := getSinceUntilLimitHeader(ctx, w, r) | |||
since, until, limit, modelType, ratioService := getQueueHeaders(ctx, w, r) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any tests on this new options
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests added
engine/hatchery/local/local.go
Outdated
} | ||
} | ||
|
||
for _, r := range tmp { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
declare capa here with a good length or capacity :)
Signed-off-by: Yvonnick Esnault <[email protected]>
Signed-off-by: Yvonnick Esnault <[email protected]>
Signed-off-by: Yvonnick Esnault <[email protected]>
Signed-off-by: Yvonnick Esnault <[email protected]>
Signed-off-by: Yvonnick Esnault <[email protected]>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Signed-off-by: Yvonnick Esnault <[email protected]>
This comment has been minimized.
This comment has been minimized.
Signed-off-by: Yvonnick Esnault <[email protected]>
Signed-off-by: Yvonnick Esnault <[email protected]>
Signed-off-by: Yvonnick Esnault <[email protected]>
Signed-off-by: Yvonnick Esnault <[email protected]>
CDS Report build-engine-cli-tools#6067.0 ✘
|
Signed-off-by: Yvonnick Esnault <[email protected]>
Signed-off-by: Yvonnick Esnault <[email protected]>
engine/api/build_test.go
Outdated
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/ovh/cds/engine/api/services" | ||
"github.com/ovh/cds/engine/api/sessionstore" | ||
"github.com/ovh/cds/sdk/namesgenerator" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
order
Signed-off-by: Yvonnick Esnault <[email protected]>
close #3315 (with 5f461f6 too)
Signed-off-by: Yvonnick Esnault [email protected]