Skip to content

Commit

Permalink
feat(hatchery): allow to set specific api url for workers (#5773)
Browse files Browse the repository at this point in the history
Signed-off-by: richardlt <[email protected]>
  • Loading branch information
richardlt authored Mar 22, 2021
1 parent aaeea69 commit 25dda4d
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 84 deletions.
15 changes: 2 additions & 13 deletions engine/hatchery/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,19 +191,8 @@ func (h *HatcheryKubernetes) SpawnWorker(ctx context.Context, spawnArgs hatchery
}
}

udataParam := sdk.WorkerArgs{
API: h.Configuration().API.HTTP.URL,
Token: spawnArgs.WorkerToken,
HTTPInsecure: h.Config.API.HTTP.Insecure,
Name: spawnArgs.WorkerName,
Model: spawnArgs.Model.Group.Name + "/" + spawnArgs.Model.Name,
HatcheryName: h.Name(),
TTL: h.Config.WorkerTTL,
GraylogHost: h.Configuration().Provision.WorkerLogsOptions.Graylog.Host,
GraylogPort: h.Configuration().Provision.WorkerLogsOptions.Graylog.Port,
GraylogExtraKey: h.Configuration().Provision.WorkerLogsOptions.Graylog.ExtraKey,
GraylogExtraValue: h.Configuration().Provision.WorkerLogsOptions.Graylog.ExtraValue,
}
udataParam := h.GenerateWorkerArgs(h, spawnArgs)
udataParam.TTL = h.Config.WorkerTTL

udataParam.WorkflowJobID = spawnArgs.JobID

Expand Down
19 changes: 4 additions & 15 deletions engine/hatchery/local/worker_spawn.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,10 @@ func (h *HatcheryLocal) SpawnWorker(ctx context.Context, spawnArgs hatchery.Spaw

log.Info(ctx, "HatcheryLocal.SpawnWorker> basedir: %s", basedir)

udataParam := sdk.WorkerArgs{
API: h.Configuration().API.HTTP.URL,
Token: spawnArgs.WorkerToken,
BaseDir: basedir,
HTTPInsecure: h.Config.API.HTTP.Insecure,
Name: spawnArgs.WorkerName,
Model: spawnArgs.ModelName(),
HatcheryName: h.Name(),
GraylogHost: h.Configuration().Provision.WorkerLogsOptions.Graylog.Host,
GraylogPort: h.Configuration().Provision.WorkerLogsOptions.Graylog.Port,
GraylogExtraKey: h.Configuration().Provision.WorkerLogsOptions.Graylog.ExtraKey,
GraylogExtraValue: h.Configuration().Provision.WorkerLogsOptions.Graylog.ExtraValue,
WorkerBinary: path.Join(h.BasedirDedicated, h.getWorkerBinaryName()),
WorkflowJobID: spawnArgs.JobID,
}
udataParam := h.GenerateWorkerArgs(h, spawnArgs)
udataParam.BaseDir = basedir
udataParam.WorkerBinary = path.Join(h.BasedirDedicated, h.getWorkerBinaryName())
udataParam.WorkflowJobID = spawnArgs.JobID

tmpl, errt := template.New("cmd").Parse(workerCmdTmpl)
if errt != nil {
Expand Down
17 changes: 3 additions & 14 deletions engine/hatchery/marathon/marathon.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,20 +237,9 @@ func (h *HatcheryMarathon) SpawnWorker(ctx context.Context, spawnArgs hatchery.S
instance := 1
forcePull := strings.HasSuffix(spawnArgs.Model.ModelDocker.Image, ":latest")

udataParam := sdk.WorkerArgs{
API: h.Configuration().API.HTTP.URL,
Token: spawnArgs.WorkerToken,
HTTPInsecure: h.Config.API.HTTP.Insecure,
Name: spawnArgs.WorkerName,
TTL: h.Config.WorkerTTL,
Model: spawnArgs.Model.Path(),
HatcheryName: h.Name(),
GraylogHost: h.Configuration().Provision.WorkerLogsOptions.Graylog.Host,
GraylogPort: h.Configuration().Provision.WorkerLogsOptions.Graylog.Port,
GraylogExtraKey: h.Configuration().Provision.WorkerLogsOptions.Graylog.ExtraKey,
GraylogExtraValue: h.Configuration().Provision.WorkerLogsOptions.Graylog.ExtraValue,
WorkflowJobID: spawnArgs.JobID,
}
udataParam := h.GenerateWorkerArgs(h, spawnArgs)
udataParam.TTL = h.Config.WorkerTTL
udataParam.WorkflowJobID = spawnArgs.JobID

tmpl, errt := template.New("cmd").Parse(spawnArgs.Model.ModelDocker.Cmd)
if errt != nil {
Expand Down
16 changes: 3 additions & 13 deletions engine/hatchery/openstack/spawn.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,10 @@ func (h *HatcheryOpenstack) SpawnWorker(ctx context.Context, spawnArgs hatchery.
if err != nil {
return err
}
udataParam := sdk.WorkerArgs{
API: h.Configuration().API.HTTP.URL,
Name: spawnArgs.WorkerName,
Token: spawnArgs.WorkerToken,
Model: spawnArgs.Model.Group.Name + "/" + spawnArgs.Model.Name,
HatcheryName: h.Name(),
TTL: h.Config.WorkerTTL,
FromWorkerImage: withExistingImage,
GraylogHost: h.Configuration().Provision.WorkerLogsOptions.Graylog.Host,
GraylogPort: h.Configuration().Provision.WorkerLogsOptions.Graylog.Port,
GraylogExtraKey: h.Configuration().Provision.WorkerLogsOptions.Graylog.ExtraKey,
GraylogExtraValue: h.Configuration().Provision.WorkerLogsOptions.Graylog.ExtraValue,
}

udataParam := h.GenerateWorkerArgs(h, spawnArgs)
udataParam.TTL = h.Config.WorkerTTL
udataParam.FromWorkerImage = withExistingImage
udataParam.WorkflowJobID = spawnArgs.JobID

var buffer bytes.Buffer
Expand Down
22 changes: 22 additions & 0 deletions engine/hatchery/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,25 @@ func getStatusHandler(h hatchery.Interface) service.HandlerFunc {
}
}
}

func (c *Common) GenerateWorkerArgs(h hatchery.Interface, spawnArgs hatchery.SpawnArguments) sdk.WorkerArgs {
apiURL := h.Configuration().Provision.WorkerAPIHTTP.URL
httpInsecure := h.Configuration().Provision.WorkerAPIHTTP.Insecure
if apiURL == "" {
apiURL = h.Configuration().API.HTTP.URL
httpInsecure = h.Configuration().API.HTTP.Insecure
}

return sdk.WorkerArgs{
API: apiURL,
HTTPInsecure: httpInsecure,
Token: spawnArgs.WorkerToken,
Name: spawnArgs.WorkerName,
Model: spawnArgs.ModelName(),
HatcheryName: h.Name(),
GraylogHost: h.Configuration().Provision.WorkerLogsOptions.Graylog.Host,
GraylogPort: h.Configuration().Provision.WorkerLogsOptions.Graylog.Port,
GraylogExtraKey: h.Configuration().Provision.WorkerLogsOptions.Graylog.ExtraKey,
GraylogExtraValue: h.Configuration().Provision.WorkerLogsOptions.Graylog.ExtraValue,
}
}
16 changes: 2 additions & 14 deletions engine/hatchery/swarm/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,20 +379,8 @@ func (h *HatcherySwarm) SpawnWorker(ctx context.Context, spawnArgs hatchery.Spaw
return errDockerOpts
}

udataParam := sdk.WorkerArgs{
API: h.Config.API.HTTP.URL,
Token: spawnArgs.WorkerToken,
HTTPInsecure: h.Config.API.HTTP.Insecure,
Name: spawnArgs.WorkerName,
Model: spawnArgs.Model.Group.Name + "/" + spawnArgs.Model.Name,
TTL: h.Config.WorkerTTL,
HatcheryName: h.Name(),
GraylogHost: h.Config.Provision.WorkerLogsOptions.Graylog.Host,
GraylogPort: h.Config.Provision.WorkerLogsOptions.Graylog.Port,
GraylogExtraKey: h.Config.Provision.WorkerLogsOptions.Graylog.ExtraKey,
GraylogExtraValue: h.Config.Provision.WorkerLogsOptions.Graylog.ExtraValue,
}

udataParam := h.GenerateWorkerArgs(h, spawnArgs)
udataParam.TTL = h.Config.WorkerTTL
udataParam.WorkflowJobID = spawnArgs.JobID

tmpl, errt := template.New("cmd").Parse(spawnArgs.Model.ModelDocker.Cmd)
Expand Down
23 changes: 9 additions & 14 deletions engine/hatchery/vsphere/spawn.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,20 +322,15 @@ func (h *HatcheryVSphere) launchScriptWorker(ctx context.Context, name string, j
if errt != nil {
return errt
}
udataParam := sdk.WorkerArgs{
API: h.Config.API.HTTP.URL,
Name: name,
Token: token,
Model: model.Group.Name + "/" + model.Name,
HatcheryName: h.Name(),
TTL: h.Config.WorkerTTL,
FromWorkerImage: true,
GraylogHost: h.Config.Provision.WorkerLogsOptions.Graylog.Host,
GraylogPort: h.Config.Provision.WorkerLogsOptions.Graylog.Port,
GraylogExtraKey: h.Config.Provision.WorkerLogsOptions.Graylog.ExtraKey,
GraylogExtraValue: h.Config.Provision.WorkerLogsOptions.Graylog.ExtraValue,
WorkflowJobID: jobID,
}

udataParam := h.GenerateWorkerArgs(h, hatchery.SpawnArguments{
WorkerToken: token,
WorkerName: name,
Model: &model,
})
udataParam.TTL = h.Config.WorkerTTL
udataParam.FromWorkerImage = true
udataParam.WorkflowJobID = jobID

var buffer bytes.Buffer
if err := tmpl.Execute(&buffer, udataParam); err != nil {
Expand Down
6 changes: 5 additions & 1 deletion engine/service/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ type HatcheryCommonConfiguration struct {
RegisterFrequency int `toml:"registerFrequency" default:"60" comment:"Check if some worker model have to be registered each n Seconds" json:"registerFrequency"`
Region string `toml:"region" default:"" comment:"region of this hatchery - optional. With a free text as 'myregion', user can set a prerequisite 'region' with value 'myregion' on CDS Job" json:"region"`
IgnoreJobWithNoRegion bool `toml:"ignoreJobWithNoRegion" default:"false" comment:"Ignore job without a region prerequisite if ignoreJobWithNoRegion=true"`
WorkerLogsOptions struct {
WorkerAPIHTTP struct {
URL string `toml:"url" default:"http://localhost:8081" commented:"true" comment:"CDS API URL for worker, let empty or commented to use the same URL that is used by the Hatchery" json:"url"`
Insecure bool `toml:"insecure" default:"false" commented:"true" comment:"sslInsecureSkipVerify, set to true if you use a self-signed SSL on CDS API" json:"insecure"`
} `toml:"http" json:"http"`
WorkerLogsOptions struct {
Graylog struct {
Host string `toml:"host" comment:"Example: thot.ovh.com" json:"host"`
Port int `toml:"port" comment:"Example: 12202" json:"port"`
Expand Down

0 comments on commit 25dda4d

Please sign in to comment.