diff --git a/engine/api/api.go b/engine/api/api.go index 99f5cc6b88..74c0b8bc90 100644 --- a/engine/api/api.go +++ b/engine/api/api.go @@ -181,11 +181,10 @@ type Configuration struct { Token string `toml:"token" comment:"Token shared between Izanami and CDS to be able to send webhooks from izanami" json:"-"` } `toml:"izanami" comment:"Feature flipping provider: https://maif.github.io/izanami" json:"izanami"` } `toml:"features" comment:"###########################\n CDS Features flipping Settings \n##########################" json:"features"` - Services []sdk.ServiceConfiguration `toml:"services" comment:"###########################\n CDS Services Settings \n##########################" json:"services"` - DefaultOS string `toml:"defaultOS" default:"linux" comment:"if no model and os/arch is specified in your job's requirements then spawn worker on this operating system (example: freebsd, linux, windows)" json:"defaultOS"` - DefaultArch string `toml:"defaultArch" default:"amd64" comment:"if no model and no os/arch is specified in your job's requirements then spawn worker on this architecture (example: amd64, arm, 386)" json:"defaultArch"` - DefaultRegion string `toml:"defaultRegion" default:"" comment:"Optional. If no region in your job's requirements then spawn worker with this region. You need to have an hatchery managing this region." json:"defaultRegion"` - Graylog struct { + Services []sdk.ServiceConfiguration `toml:"services" comment:"###########################\n CDS Services Settings \n##########################" json:"services"` + DefaultOS string `toml:"defaultOS" default:"linux" comment:"if no model and os/arch is specified in your job's requirements then spawn worker on this operating system (example: freebsd, linux, windows)" json:"defaultOS"` + DefaultArch string `toml:"defaultArch" default:"amd64" comment:"if no model and no os/arch is specified in your job's requirements then spawn worker on this architecture (example: amd64, arm, 386)" json:"defaultArch"` + Graylog struct { AccessToken string `toml:"accessToken" json:"-"` Stream string `toml:"stream" json:"-"` URL string `toml:"url" comment:"Example: http://localhost:9000" json:"url"` @@ -813,7 +812,7 @@ func (a *API) Serve(ctx context.Context) error { }, a.PanicDump()) sdk.GoRoutine(ctx, "workflow.Initialize", func(ctx context.Context) { - workflow.Initialize(ctx, a.DBConnectionFactory.GetDBMap, a.Cache, a.Config.URL.UI, a.Config.DefaultOS, a.Config.DefaultArch, a.Config.DefaultRegion) + workflow.Initialize(ctx, a.DBConnectionFactory.GetDBMap, a.Cache, a.Config.URL.UI, a.Config.DefaultOS, a.Config.DefaultArch) }, a.PanicDump()) sdk.GoRoutine(ctx, "PushInElasticSearch", func(ctx context.Context) { diff --git a/engine/api/workflow/gorp_model.go b/engine/api/workflow/gorp_model.go index aa4beaddd3..d82fbfd136 100644 --- a/engine/api/workflow/gorp_model.go +++ b/engine/api/workflow/gorp_model.go @@ -189,23 +189,6 @@ func (j JobRun) WorkflowNodeRunJob() (sdk.WorkflowNodeJobRun, error) { }) } } - if defaultRegion != "" { - var regionFound bool - for _, req := range jr.Job.Action.Requirements { - if req.Type == sdk.RegionRequirement { - regionFound = true - break - } - } - - if !regionFound { - jr.Job.Action.Requirements = append(jr.Job.Action.Requirements, sdk.Requirement{ - Name: defaultRegion, - Type: sdk.RegionRequirement, - Value: defaultRegion, - }) - } - } return jr, nil } diff --git a/engine/api/workflow/init.go b/engine/api/workflow/init.go index 861313bd56..8811a76f0b 100644 --- a/engine/api/workflow/init.go +++ b/engine/api/workflow/init.go @@ -10,14 +10,13 @@ import ( "github.com/ovh/cds/sdk/log" ) -var baseUIURL, defaultOS, defaultArch, defaultRegion string +var baseUIURL, defaultOS, defaultArch string //Initialize starts goroutines for workflows -func Initialize(ctx context.Context, DBFunc func() *gorp.DbMap, store cache.Store, uiURL, confDefaultOS, confDefaultArch, confDefaultRegion string) { +func Initialize(ctx context.Context, DBFunc func() *gorp.DbMap, store cache.Store, uiURL, confDefaultOS, confDefaultArch string) { baseUIURL = uiURL defaultOS = confDefaultOS defaultArch = confDefaultArch - defaultRegion = confDefaultRegion tickStop := time.NewTicker(30 * time.Minute) tickHeart := time.NewTicker(10 * time.Second) defer tickHeart.Stop() @@ -42,8 +41,3 @@ func Initialize(ctx context.Context, DBFunc func() *gorp.DbMap, store cache.Stor } } } - -// SetDefaultRegion is used by unit tests -func SetDefaultRegion(r string) { - defaultRegion = r -} diff --git a/engine/api/workflow_queue_test.go b/engine/api/workflow_queue_test.go index 2d1ecc7753..cf15aa8536 100644 --- a/engine/api/workflow_queue_test.go +++ b/engine/api/workflow_queue_test.go @@ -501,63 +501,6 @@ func Test_postTakeWorkflowJobHandler(t *testing.T) { assert.Len(t, wkrDB.PrivateKey, 32) } -func Test_postTakeWorkflowJobHandlerDefautlRegion(t *testing.T) { - api, _, router := newTestAPI(t) - - ctx := testRunWorkflow(t, api, router) - testGetWorkflowJobAsWorker(t, api, router, &ctx) - require.NotNil(t, ctx.job) - - //Prepare request - vars := map[string]string{ - "key": ctx.project.Key, - "permWorkflowName": ctx.workflow.Name, - "id": fmt.Sprintf("%d", ctx.job.ID), - } - - //Register the worker - testRegisterWorker(t, api, router, &ctx) - - // Add cdn config - api.Config.CDN = cdn.Configuration{ - TCP: sdk.TCPServer{ - Port: 8090, - Addr: "localhost", - }, - } - - uri := router.GetRoute("POST", api.postTakeWorkflowJobHandler, vars) - require.NotEmpty(t, uri) - - workflow.SetDefaultRegion("my-region") - - //This call must work - req := assets.NewJWTAuthentifiedRequest(t, ctx.workerToken, "POST", uri, nil) - rec := httptest.NewRecorder() - router.Mux.ServeHTTP(rec, req) - require.Equal(t, 200, rec.Code) - - pbji := &sdk.WorkflowNodeJobRunData{} - require.NoError(t, json.Unmarshal(rec.Body.Bytes(), pbji)) - - run, err := workflow.LoadNodeJobRun(context.TODO(), api.mustDB(), api.Cache, ctx.job.ID) - require.NoError(t, err) - assert.Equal(t, "Building", run.Status) - assert.Equal(t, ctx.model.Name, run.Model) - assert.Equal(t, ctx.worker.Name, run.WorkerName) - assert.NotEmpty(t, run.HatcheryName) - - var found bool - for _, v := range run.Job.Action.Requirements { - if v.Type == sdk.RegionRequirement { - require.Equal(t, "my-region", v.Value) - found = true - } - } - require.Equal(t, true, found) - -} - func Test_postTakeWorkflowInvalidJobHandler(t *testing.T) { api, _, router := newTestAPI(t)