From 3a87d2c1a3c033dd640946b5f331087185022a9e Mon Sep 17 00:00:00 2001 From: richardlt Date: Fri, 19 Aug 2022 15:50:29 +0200 Subject: [PATCH] refactor(hatchery): add CDN configuration to Worker spawn args Signed-off-by: richardlt --- engine/api/workflow_queue.go | 4 +- engine/hatchery/kubernetes/kubernetes.go | 15 +--- engine/hatchery/kubernetes/services_test.go | 3 +- engine/hatchery/local/local.go | 15 +--- engine/hatchery/marathon/marathon.go | 15 +--- engine/hatchery/openstack/init.go | 7 +- engine/hatchery/openstack/openstack.go | 10 --- engine/hatchery/serve.go | 84 +++++++++++++------ engine/hatchery/swarm/swarm.go | 17 +--- engine/hatchery/swarm/swarm_util_logs_test.go | 3 +- engine/hatchery/vsphere/hatchery.go | 5 -- engine/hatchery/vsphere/init.go | 29 ++----- engine/service/types.go | 16 +++- .../action/builtin_artifact_download.go | 4 +- engine/worker/internal/types.go | 2 +- engine/worker/pkg/workerruntime/types.go | 25 +++--- sdk/hatchery/hatchery.go | 4 - sdk/hatchery/types.go | 2 - 18 files changed, 113 insertions(+), 147 deletions(-) diff --git a/engine/api/workflow_queue.go b/engine/api/workflow_queue.go index e22e3db2f6..766a8e2000 100644 --- a/engine/api/workflow_queue.go +++ b/engine/api/workflow_queue.go @@ -107,13 +107,11 @@ func (api *API) postTakeWorkflowJobHandler() service.Handler { return sdk.WrapError(err, "cannot takeJob nodeJobRunID:%d", id) } - // Get CDN TCP Addr - // Get CDN TCP Addr + // FIXME remove CDN info from payload, this information should be injected by the hatchery pbji.GelfServiceAddr, pbji.GelfServiceAddrEnableTLS, err = services.GetCDNPublicTCPAdress(ctx, api.mustDB()) if err != nil { return err } - pbji.CDNHttpAddr, err = services.GetCDNPublicHTTPAdress(ctx, api.mustDB()) if err != nil { return err diff --git a/engine/hatchery/kubernetes/kubernetes.go b/engine/hatchery/kubernetes/kubernetes.go index 1ba1db6dc4..20790446b0 100644 --- a/engine/hatchery/kubernetes/kubernetes.go +++ b/engine/hatchery/kubernetes/kubernetes.go @@ -12,7 +12,6 @@ import ( jwt "github.com/golang-jwt/jwt" "github.com/gorilla/mux" "github.com/rockbears/log" - "github.com/sirupsen/logrus" apiv1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" @@ -38,8 +37,8 @@ var _ hatchery.InterfaceWithModels = new(HatcheryKubernetes) // InitHatchery register local hatchery with its worker model func (h *HatcheryKubernetes) InitHatchery(ctx context.Context) error { - if err := h.Common.RefreshServiceLogger(ctx); err != nil { - log.Error(ctx, "hatchery> kubernetes> cannot get cdn configuration : %v", err) + if err := h.Common.Init(ctx, h); err != nil { + return err } h.GoRoutines.Run(context.Background(), "hatchery kubernetes routines", func(ctx context.Context) { h.routines(ctx) @@ -411,10 +410,6 @@ func (h *HatcheryKubernetes) SpawnWorker(ctx context.Context, spawnArgs hatchery return sdk.WithStack(err) } -func (h *HatcheryKubernetes) GetLogger() *logrus.Logger { - return h.ServiceLogger -} - // WorkersStarted returns the number of instances started but // not necessarily register on CDS yet func (h *HatcheryKubernetes) WorkersStarted(ctx context.Context) ([]string, error) { @@ -446,12 +441,6 @@ func (h *HatcheryKubernetes) routines(ctx context.Context) { for { select { case <-ticker.C: - h.GoRoutines.Exec(ctx, "getCDNConfiguration", func(ctx context.Context) { - if err := h.Common.RefreshServiceLogger(ctx); err != nil { - log.ErrorWithStackTrace(ctx, sdk.WrapError(err, "cannot get cdn configuration")) - } - }) - h.GoRoutines.Exec(ctx, "getServicesLogs", func(ctx context.Context) { if err := h.getServicesLogs(ctx); err != nil { log.ErrorWithStackTrace(ctx, sdk.WrapError(err, "cannot get service logs")) diff --git a/engine/hatchery/kubernetes/services_test.go b/engine/hatchery/kubernetes/services_test.go index 8a751de402..e673d52d35 100644 --- a/engine/hatchery/kubernetes/services_test.go +++ b/engine/hatchery/kubernetes/services_test.go @@ -34,7 +34,8 @@ func Test_serviceLogs(t *testing.T) { gock.New("http://lolcat.api").Get("/worker").Reply(http.StatusOK).JSON([]sdk.Worker{{Name: "pod-name"}}) gock.New("http://lolcat.api").Get("/config/cdn").Reply(http.StatusOK).JSON(sdk.CDNConfig{TCPURL: "tcphost:8090"}) - require.NoError(t, h.RefreshServiceLogger(context.TODO())) + + require.NoError(t, h.Common.Init(context.TODO(), h)) podsList := v1.PodList{ Items: []v1.Pod{ diff --git a/engine/hatchery/local/local.go b/engine/hatchery/local/local.go index 1ec809dc58..ea98b3fa7c 100644 --- a/engine/hatchery/local/local.go +++ b/engine/hatchery/local/local.go @@ -16,7 +16,6 @@ import ( jwt "github.com/golang-jwt/jwt" "github.com/gorilla/mux" "github.com/rockbears/log" - "github.com/sirupsen/logrus" "github.com/ovh/cds/engine/api" "github.com/ovh/cds/engine/service" @@ -258,8 +257,8 @@ func (h *HatcheryLocal) WorkersStarted(ctx context.Context) ([]string, error) { // InitHatchery register local hatchery with its worker model func (h *HatcheryLocal) InitHatchery(ctx context.Context) error { h.workers = make(map[string]workerCmd) - if err := h.RefreshServiceLogger(ctx); err != nil { - log.Error(ctx, "Hatchery> local> Cannot get cdn configuration : %v", err) + if err := h.Common.Init(ctx, h); err != nil { + return nil } h.GoRoutines.Run(ctx, "hatchery locale routines", func(ctx context.Context) { h.routines(ctx) @@ -267,11 +266,6 @@ func (h *HatcheryLocal) InitHatchery(ctx context.Context) error { return nil } -// GetLogger retuns the hatchery local logger -func (h *HatcheryLocal) GetLogger() *logrus.Logger { - return h.ServiceLogger -} - func (h *HatcheryLocal) routines(ctx context.Context) { ticker := time.NewTicker(10 * time.Second) defer ticker.Stop() @@ -284,11 +278,6 @@ func (h *HatcheryLocal) routines(ctx context.Context) { log.Warn(ctx, "Cannot kill awol workers: %s", err) } }) - h.GoRoutines.Exec(ctx, "local-refreshCDNConfiguration", func(ctx context.Context) { - if err := h.RefreshServiceLogger(ctx); err != nil { - log.Error(ctx, "Hatchery> local> Cannot get cdn configuration : %v", err) - } - }) case <-ctx.Done(): if ctx.Err() != nil { log.Error(ctx, "Hatchery> local> Exiting routines") diff --git a/engine/hatchery/marathon/marathon.go b/engine/hatchery/marathon/marathon.go index 2407bdbfd1..aa676881e0 100644 --- a/engine/hatchery/marathon/marathon.go +++ b/engine/hatchery/marathon/marathon.go @@ -16,7 +16,6 @@ import ( jwt "github.com/golang-jwt/jwt" "github.com/gorilla/mux" "github.com/rockbears/log" - "github.com/sirupsen/logrus" "github.com/ovh/cds/engine/api" "github.com/ovh/cds/engine/service" @@ -35,11 +34,6 @@ func New() *HatcheryMarathon { var _ hatchery.InterfaceWithModels = new(HatcheryMarathon) -// GetLogger return the logger -func (h *HatcheryMarathon) GetLogger() *logrus.Logger { - return h.ServiceLogger -} - // Init cdsclient config. func (h *HatcheryMarathon) Init(config interface{}) (cdsclient.ServiceConfig, error) { var cfg cdsclient.ServiceConfig @@ -441,8 +435,8 @@ func (h *HatcheryMarathon) WorkersStarted(ctx context.Context) ([]string, error) // InitHatchery only starts killing routine of worker not registered func (h *HatcheryMarathon) InitHatchery(ctx context.Context) error { - if err := h.RefreshServiceLogger(ctx); err != nil { - log.Error(ctx, "Hatchery> marathon> Cannot get cdn configuration : %v", err) + if err := h.Common.Init(ctx, h); err != nil { + return err } h.GoRoutines.Run(ctx, "marathon-routines", func(ctx context.Context) { h.routines(ctx) @@ -467,11 +461,6 @@ func (h *HatcheryMarathon) routines(ctx context.Context) { log.Warn(context.Background(), "Cannot kill awol workers: %s", err) } }) - h.GoRoutines.Exec(ctx, "marathon-refreshCDNConfiguration", func(ctx context.Context) { - if err := h.RefreshServiceLogger(ctx); err != nil { - log.Error(ctx, "Hatchery> marathon> Cannot get cdn configuration : %v", err) - } - }) case <-ctx.Done(): if ctx.Err() != nil { log.Error(ctx, "Hatchery> marathon> Exiting routines") diff --git a/engine/hatchery/openstack/init.go b/engine/hatchery/openstack/init.go index 1ae8154ea9..60992b2ba6 100644 --- a/engine/hatchery/openstack/init.go +++ b/engine/hatchery/openstack/init.go @@ -17,6 +17,10 @@ import ( // then list available models // then list available images func (h *HatcheryOpenstack) InitHatchery(ctx context.Context) error { + if err := h.Common.Init(ctx, h); err != nil { + return err + } + workersAlive = map[string]int64{} authOpts := gophercloud.AuthOptions{ @@ -51,9 +55,6 @@ func (h *HatcheryOpenstack) InitHatchery(ctx context.Context) error { log.Warn(ctx, "Error on initIPStatus(): %v", err) } - if err := h.RefreshServiceLogger(ctx); err != nil { - log.Error(ctx, "Hatchery> openstack> Cannot get cdn configuration : %v", err) - } h.GoRoutines.Run(ctx, "hatchery openstack routines", func(ctx context.Context) { h.main(ctx) }) diff --git a/engine/hatchery/openstack/openstack.go b/engine/hatchery/openstack/openstack.go index dca3dd0002..63174f614b 100644 --- a/engine/hatchery/openstack/openstack.go +++ b/engine/hatchery/openstack/openstack.go @@ -13,7 +13,6 @@ import ( "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" "github.com/gorilla/mux" "github.com/rockbears/log" - "github.com/sirupsen/logrus" "github.com/ovh/cds/engine/api" "github.com/ovh/cds/engine/service" @@ -214,13 +213,8 @@ func (h *HatcheryOpenstack) CanSpawn(ctx context.Context, model *sdk.Model, jobI return true } -func (h *HatcheryOpenstack) GetLogger() *logrus.Logger { - return h.ServiceLogger -} - func (h *HatcheryOpenstack) main(ctx context.Context) { serverListTick := time.NewTicker(10 * time.Second).C - cdnConfTick := time.NewTicker(10 * time.Second).C killAwolServersTick := time.NewTicker(30 * time.Second).C killErrorServersTick := time.NewTicker(60 * time.Second).C killDisabledWorkersTick := time.NewTicker(60 * time.Second).C @@ -235,10 +229,6 @@ func (h *HatcheryOpenstack) main(ctx context.Context) { h.killErrorServers(ctx) case <-killDisabledWorkersTick: h.killDisabledWorkers() - case <-cdnConfTick: - if err := h.RefreshServiceLogger(ctx); err != nil { - log.Error(ctx, "Hatchery> openstack> Cannot get cdn configuration : %v", err) - } case <-ctx.Done(): if ctx.Err() != nil { log.Error(ctx, "Hatchery> openstack> Exiting routines") diff --git a/engine/hatchery/serve.go b/engine/hatchery/serve.go index 26b19eb3b1..020d011698 100644 --- a/engine/hatchery/serve.go +++ b/engine/hatchery/serve.go @@ -14,7 +14,6 @@ import ( "time" "github.com/rockbears/log" - "gopkg.in/square/go-jose.v2" "github.com/ovh/cds/engine/api" "github.com/ovh/cds/engine/service" @@ -116,23 +115,40 @@ func (c *Common) GetPrivateKey() *rsa.PrivateKey { return c.Common.PrivateKey } -func (c *Common) RefreshServiceLogger(ctx context.Context) error { - cdnConfig, err := c.Client.ConfigCDN() - if err != nil { - if sdk.ErrorIs(err, sdk.ErrNotFound) { - c.CDNLogsURL = "" - c.ServiceLogger = nil +func (c *Common) Init(ctx context.Context, h hatchery.Interface) error { + c.CDNConfig.HTTPURL = h.Configuration().CDN.URL + c.CDNConfig.TCPURL = h.Configuration().CDN.TCP.URL + c.CDNConfig.TCPURLEnableTLS = h.Configuration().CDN.TCP.EnableTLS + + // Init CDN config from Hatchery config or public CDN information + if c.CDNConfig.HTTPURL == "" || c.CDNConfig.TCPURL == "" { + // Load CDN information from CDS API + var cfg sdk.CDNConfig + var err error + for { + cfg, err = c.Client.ConfigCDN() + if err == nil { + break + } + err = sdk.NewErrorFrom(err, "cannot get CDN config from CDS API, retrying...") + log.ErrorWithStackTrace(ctx, err) + time.Sleep(2 * time.Second) + } + if c.CDNConfig.HTTPURL == "" { + c.CDNConfig.HTTPURL = cfg.HTTPURL + } + if c.CDNConfig.TCPURL == "" { + c.CDNConfig.TCPURL = cfg.TCPURL + c.CDNConfig.TCPURLEnableTLS = cfg.TCPURLEnableTLS } - return err - } - if cdnConfig.TCPURL == c.CDNLogsURL { - return nil } - c.CDNLogsURL = cdnConfig.TCPURL + return c.initServiceLogger(ctx) +} + +func (c *Common) initServiceLogger(ctx context.Context) error { if c.Signer == nil { - var signer jose.Signer - signer, err = jws.NewSigner(c.Common.PrivateKey) + signer, err := jws.NewSigner(c.Common.PrivateKey) if err != nil { return sdk.WithStack(err) } @@ -140,12 +156,12 @@ func (c *Common) RefreshServiceLogger(ctx context.Context) error { } var graylogCfg = &hook.Config{ - Addr: c.CDNLogsURL, + Addr: c.CDNConfig.TCPURL, Protocol: "tcp", } - if cdnConfig.TCPURLEnableTLS { - tcpCDNUrl := c.CDNLogsURL + if c.CDNConfig.TCPURLEnableTLS { + tcpCDNUrl := c.CDNConfig.TCPURL // Check if the url has a scheme // We have to remove if to retrieve the hostname if i := strings.Index(tcpCDNUrl, "://"); i > -1 { @@ -260,6 +276,17 @@ func (c *Common) GenerateWorkerConfig(ctx context.Context, h hatchery.Interface, httpInsecure = h.Configuration().API.HTTP.Insecure } + cdnURL := h.Configuration().Provision.WorkerCDN.URL + if cdnURL == "" { + cdnURL = c.CDNConfig.HTTPURL + } + cdnTCP := h.Configuration().Provision.WorkerCDN.TCP.URL + cdnTCPEnableTLS := h.Configuration().Provision.WorkerCDN.TCP.EnableTLS + if cdnTCP == "" { + cdnTCP = c.CDNConfig.TCPURL + cdnTCPEnableTLS = c.CDNConfig.TCPURLEnableTLS + } + envvars := make(map[string]string, len(h.Configuration().Provision.InjectEnvVars)) for _, e := range h.Configuration().Provision.InjectEnvVars { @@ -272,16 +299,19 @@ func (c *Common) GenerateWorkerConfig(ctx context.Context, h hatchery.Interface, } cfg := workerruntime.WorkerConfig{ - Name: spawnArgs.WorkerName, - BookedJobID: spawnArgs.JobID, - HatcheryName: h.Name(), - Model: spawnArgs.ModelName(), - APIToken: spawnArgs.WorkerToken, - APIEndpoint: apiURL, - APIEndpointInsecure: httpInsecure, - InjectEnvVars: envvars, - Region: h.Configuration().Provision.Region, - Basedir: h.Configuration().Provision.WorkerBasedir, + Name: spawnArgs.WorkerName, + BookedJobID: spawnArgs.JobID, + HatcheryName: h.Name(), + Model: spawnArgs.ModelName(), + APIToken: spawnArgs.WorkerToken, + APIEndpoint: apiURL, + APIEndpointInsecure: httpInsecure, + CDNEndpoint: cdnURL, + GelfServiceAddr: cdnTCP, + GelfServiceAddrEnableTLS: cdnTCPEnableTLS, + InjectEnvVars: envvars, + Region: h.Configuration().Provision.Region, + Basedir: h.Configuration().Provision.WorkerBasedir, Log: cdslog.Conf{ GraylogHost: h.Configuration().Provision.WorkerLogsOptions.Graylog.Host, GraylogPort: strconv.Itoa(h.Configuration().Provision.WorkerLogsOptions.Graylog.Port), diff --git a/engine/hatchery/swarm/swarm.go b/engine/hatchery/swarm/swarm.go index 85f800f810..da8dbd7edf 100644 --- a/engine/hatchery/swarm/swarm.go +++ b/engine/hatchery/swarm/swarm.go @@ -39,6 +39,10 @@ var _ hatchery.InterfaceWithModels = new(HatcherySwarm) // InitHatchery connect the hatchery to the docker api func (h *HatcherySwarm) InitHatchery(ctx context.Context) error { + if err := h.Common.Init(ctx, h); err != nil { + return err + } + h.dockerClients = map[string]*dockerClient{} if len(h.Config.DockerEngines) == 0 { @@ -173,9 +177,6 @@ func (h *HatcherySwarm) InitHatchery(ctx context.Context) error { } } - if err := h.RefreshServiceLogger(ctx); err != nil { - log.Error(ctx, "Hatchery> swarm> Cannot get cdn configuration : %v", err) - } h.GoRoutines.Run(ctx, "swarm", func(ctx context.Context) { h.routines(ctx) }) @@ -506,10 +507,6 @@ func (h *HatcherySwarm) WorkersStarted(ctx context.Context) ([]string, error) { return res, nil } -func (h *HatcherySwarm) GetLogger() *logrus.Logger { - return h.ServiceLogger -} - // Start inits client and routines for hatchery func (h *HatcherySwarm) Start(ctx context.Context) error { return hatchery.Create(ctx, h) @@ -551,12 +548,6 @@ func (h *HatcherySwarm) routines(ctx context.Context) { h.GoRoutines.Exec(ctx, "killAwolWorker", func(ctx context.Context) { _ = h.killAwolWorker(ctx) }) - - h.GoRoutines.Exec(ctx, "refreshCDNConfiguration", func(ctx context.Context) { - if err := h.RefreshServiceLogger(ctx); err != nil { - log.Error(ctx, "Hatchery> swarm> Cannot get cdn configuration : %v", err) - } - }) case <-ctx.Done(): if ctx.Err() != nil { log.Error(ctx, "Hatchery> Swarm> Exiting routines") diff --git a/engine/hatchery/swarm/swarm_util_logs_test.go b/engine/hatchery/swarm/swarm_util_logs_test.go index c6beb1b0c9..f35fa81b82 100644 --- a/engine/hatchery/swarm/swarm_util_logs_test.go +++ b/engine/hatchery/swarm/swarm_util_logs_test.go @@ -34,7 +34,8 @@ func Test_serviceLogs(t *testing.T) { gock.New("https://cds-api.local").Get("/worker").Reply(http.StatusOK).JSON([]sdk.Worker{{Name: "swarmy-model1-w1"}}) gock.New("https://cds-api.local").Get("/config/cdn").Reply(http.StatusOK).JSON(sdk.CDNConfig{TCPURL: "tcphost:8090"}) - require.NoError(t, h.RefreshServiceLogger(context.TODO())) + + require.NoError(t, h.Common.Init(context.TODO(), h)) containers := []types.Container{ { diff --git a/engine/hatchery/vsphere/hatchery.go b/engine/hatchery/vsphere/hatchery.go index 1c90ce0650..84562dd929 100644 --- a/engine/hatchery/vsphere/hatchery.go +++ b/engine/hatchery/vsphere/hatchery.go @@ -9,7 +9,6 @@ import ( jwt "github.com/golang-jwt/jwt" "github.com/gorilla/mux" "github.com/rockbears/log" - "github.com/sirupsen/logrus" "github.com/vmware/govmomi/vim25/mo" "github.com/vmware/govmomi/vim25/types" @@ -48,10 +47,6 @@ func (h *HatcheryVSphere) Init(config interface{}) (cdsclient.ServiceConfig, err return cfg, nil } -func (h *HatcheryVSphere) GetLogger() *logrus.Logger { - return h.ServiceLogger -} - // ApplyConfiguration apply an object of type HatcheryConfiguration after checking it func (h *HatcheryVSphere) ApplyConfiguration(cfg interface{}) error { if err := h.CheckConfiguration(cfg); err != nil { diff --git a/engine/hatchery/vsphere/init.go b/engine/hatchery/vsphere/init.go index 5df38078d5..712dbeadc1 100644 --- a/engine/hatchery/vsphere/init.go +++ b/engine/hatchery/vsphere/init.go @@ -14,6 +14,10 @@ import ( // InitHatchery create new client for vsphere func (h *HatcheryVSphere) InitHatchery(ctx context.Context) error { + if err := h.Common.Init(ctx, h); err != nil { + return err + } + // Connect and login to ESX or vCenter c, err := h.newGovmomiClient(ctx) if err != nil { @@ -30,12 +34,6 @@ func (h *HatcheryVSphere) InitHatchery(ctx context.Context) error { } } - if err := h.RefreshServiceLogger(ctx); err != nil { - ctx = sdk.ContextWithStacktrace(ctx, err) - log.Error(ctx, "unable get cdn configuration : %v", err) - } - - cdnConfTick := time.NewTicker(60 * time.Second) killAwolServersTick := time.NewTicker(2 * time.Minute) killDisabledWorkersTick := time.NewTicker(2 * time.Minute) provisioningTick := time.NewTicker(2 * time.Minute) @@ -82,23 +80,6 @@ func (h *HatcheryVSphere) InitHatchery(ctx context.Context) error { }, ) - h.GoRoutines.Run(ctx, "hatchery-vsphere-refresh-service-logger", - func(ctx context.Context) { - defer cdnConfTick.Stop() - for { - select { - case <-ctx.Done(): - return - case <-cdnConfTick.C: - if err := h.RefreshServiceLogger(ctx); err != nil { - ctx = sdk.ContextWithStacktrace(ctx, err) - log.Error(ctx, "unable to get cdn configuration : %v", err) - } - } - } - }, - ) - log.Info(ctx, "vSphere hatchery initialized") return nil @@ -114,7 +95,7 @@ func (h *HatcheryVSphere) newGovmomiClient(ctx context.Context) (*govmomi.Client return nil, sdk.WrapError(err, "cannot parse url") } - log.Info(ctx, "initializing connection to https://%v", h.Config.VSphereEndpoint) + log.Info(ctx, "initializing connection to https://%v", h.Config.VSphereEndpoint) // Connect and log in to ESX or vCenter return govmomi.NewClient(ctx, u, false) diff --git a/engine/service/types.go b/engine/service/types.go index c095d15542..aefddc81c8 100644 --- a/engine/service/types.go +++ b/engine/service/types.go @@ -45,6 +45,13 @@ type HatcheryCommonConfiguration struct { RequestTimeout int `toml:"requestTimeout" default:"10" comment:"Request CDS API: timeout in seconds" json:"requestTimeout"` MaxHeartbeatFailures int `toml:"maxHeartbeatFailures" default:"10" comment:"Maximum allowed consecutives failures on heatbeat routine" json:"maxHeartbeatFailures"` } `toml:"api" json:"api"` + CDN struct { + URL string `toml:"url" default:"http://localhost:8089" commented:"true" comment:"Address to access CDN HTTP server, let empty or commented to use the public URL that is returned by the CDS API." json:"url"` + TCP struct { + EnableTLS bool `toml:"enableTLS" commented:"true" comment:"Enable TLS for CDN TCP connection" json:"enable_tls"` + URL string `toml:"url" default:"localhost:8090" commented:"true" comment:"Address to access CDN TCP server, let empty or commented to use the public URL that is returned by the CDS API." json:"url"` + } `toml:"tcp" json:"tcp"` + } `toml:"cdn" json:"cdn"` Provision struct { InjectEnvVars []string `toml:"injectEnvVars" commented:"true" comment:"Inject env variables in workers" json:"-" mapstructure:"injectEnvVars"` MaxWorker int `toml:"maxWorker" default:"10" comment:"Maximum allowed simultaneous workers" json:"maxWorker"` @@ -57,6 +64,13 @@ type HatcheryCommonConfiguration struct { URL string `toml:"url" default:"" commented:"false" comment:"CDS API URL for worker, let empty or commented to use the same URL that is used by the Hatchery. Example: http://localhost:8081" 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:"workerApiHttp" json:"workerApiHttp"` + WorkerCDN struct { + URL string `toml:"url" default:"" commented:"true" comment:"Address to access CDN HTTP server for worker, let empty or commented to use the same URL that is used by the Hatchery." json:"url"` + TCP struct { + EnableTLS bool `toml:"enableTLS" commented:"true" comment:"Enable TLS for CDN TCP connection" json:"enable_tls"` + URL string `toml:"url" default:"" commented:"true" comment:"Address to access CDN TCP server, let empty or commented to use the same URL that is used by the Hatchery." json:"url"` + } `toml:"tcp" json:"tcp"` + } `toml:"workerCdn" json:"workerCdn"` WorkerBasedir string `toml:"workerBasedir" commented:"true" comment:"Worker Basedir" json:"workerBasedir"` WorkerLogsOptions struct { Level string `toml:"level" comment:"Worker log level" json:"level"` @@ -117,7 +131,7 @@ type Common struct { ServiceInstance *sdk.Service PrivateKey *rsa.PrivateKey Signer jose.Signer - CDNLogsURL string + CDNConfig sdk.CDNConfig ServiceLogger *logrus.Logger GoRoutines *sdk.GoRoutines Region string diff --git a/engine/worker/internal/action/builtin_artifact_download.go b/engine/worker/internal/action/builtin_artifact_download.go index 63cc34fa18..d37b238dd5 100644 --- a/engine/worker/internal/action/builtin_artifact_download.go +++ b/engine/worker/internal/action/builtin_artifact_download.go @@ -178,13 +178,13 @@ func GetArtifactFromIntegrationPlugin(ctx context.Context, wk workerruntime.Runt if err != nil { wk.SendLog(ctx, workerruntime.LevelInfo, "Can read run result data: "+err.Error()) wg.Done() - return res, err + continue } opts := sdk.ParametersToMap(wk.Parameters()) repoName := opts[fmt.Sprintf("cds.integration.artifact_manager.%s", sdk.ArtifactoryConfigCdsRepository)] if repoName != artData.RepoName { - wg.Done() wk.SendLog(ctx, workerruntime.LevelDebug, fmt.Sprintf("%s does not match configured repo name %s - skipped", repoName, artData.RepoName)) + wg.Done() continue } diff --git a/engine/worker/internal/types.go b/engine/worker/internal/types.go index 2208e92f63..57dbdfeeb6 100644 --- a/engine/worker/internal/types.go +++ b/engine/worker/internal/types.go @@ -42,7 +42,7 @@ type CurrentWorker struct { basedir afero.Fs manualExit bool gelfLogger *logger - cdnHttpAddr string + cdnHttpAddr string // FIXME get CDN information from worker config stepLogLine int64 httpPort int32 currentJob struct { diff --git a/engine/worker/pkg/workerruntime/types.go b/engine/worker/pkg/workerruntime/types.go index 2293afddea..73dd15fc21 100644 --- a/engine/worker/pkg/workerruntime/types.go +++ b/engine/worker/pkg/workerruntime/types.go @@ -16,17 +16,20 @@ import ( ) type WorkerConfig struct { - Name string `json:"name"` - Basedir string `json:"basedir"` - Log cdslog.Conf `json:"log"` - HatcheryName string `json:"hatchery_name"` - APIEndpoint string `json:"api_endpoint"` - APIEndpointInsecure bool `json:"api_endpoint_insecure,omitempty"` - APIToken string `json:"api_token"` - Model string `json:"model"` - BookedJobID int64 `json:"booked_job_id,omitempty"` - Region string `json:"region,omitempty"` - InjectEnvVars map[string]string `json:"inject_env_vars,omitempty"` + Name string `json:"name"` + Basedir string `json:"basedir"` + Log cdslog.Conf `json:"log"` + HatcheryName string `json:"hatchery_name"` + APIEndpoint string `json:"api_endpoint"` + APIEndpointInsecure bool `json:"api_endpoint_insecure,omitempty"` + APIToken string `json:"api_token"` + CDNEndpoint string `json:"cdn_endpoint"` + GelfServiceAddr string `json:"gelf_service_addr"` + GelfServiceAddrEnableTLS bool `json:"gelf_service_addr_enable_tls,omitempty"` + Model string `json:"model"` + BookedJobID int64 `json:"booked_job_id,omitempty"` + Region string `json:"region,omitempty"` + InjectEnvVars map[string]string `json:"inject_env_vars,omitempty"` } func (cfg WorkerConfig) EncodeBase64() string { diff --git a/sdk/hatchery/hatchery.go b/sdk/hatchery/hatchery.go index a4ca73ca6e..feb31457a5 100644 --- a/sdk/hatchery/hatchery.go +++ b/sdk/hatchery/hatchery.go @@ -146,10 +146,6 @@ func Create(ctx context.Context, h Interface) error { if j.ID == 0 { continue } - if h.GetLogger() == nil { - log.Error(ctx, "logger not found, don't spawn workers") - continue - } currentCtx, currentCancel := context.WithTimeout(context.Background(), 10*time.Minute) fields := log.FieldValues(ctx) diff --git a/sdk/hatchery/types.go b/sdk/hatchery/types.go index 0631410bb5..d0932743b7 100644 --- a/sdk/hatchery/types.go +++ b/sdk/hatchery/types.go @@ -6,7 +6,6 @@ import ( jwt "github.com/golang-jwt/jwt" "github.com/rockbears/log" - "github.com/sirupsen/logrus" "go.opencensus.io/stats" "github.com/ovh/cds/engine/service" @@ -112,7 +111,6 @@ type Interface interface { Configuration() service.HatcheryCommonConfiguration Serve(ctx context.Context) error GetPrivateKey() *rsa.PrivateKey - GetLogger() *logrus.Logger GetGoRoutines() *sdk.GoRoutines }