From f96943fb52b0e2e72d352483a167abeec42bbc9e Mon Sep 17 00:00:00 2001 From: Aleksandr Maus Date: Mon, 1 Mar 2021 09:10:20 -0500 Subject: [PATCH] Remove ES bootsrap code from Fleet Server (#105) * Moved it to testing/esutil package because it is still used for integration testing indices bootstrapping --- cmd/fleet/main.go | 25 +++---------------- dev-tools/integration/main.go | 8 +++--- .../pkg/{esboot => testing/esutil}/README.MD | 0 .../{esboot => testing/esutil}/bootstrap.go | 2 +- .../{esboot => testing/esutil}/datastream.go | 2 +- .../pkg/{esboot => testing/esutil}/esutil.go | 2 +- .../pkg/{esboot => testing/esutil}/ilm.go | 2 +- .../pkg/{esboot => testing/esutil}/index.go | 2 +- .../pkg/{esboot => testing/esutil}/strmap.go | 2 +- .../{esboot => testing/esutil}/template.go | 2 +- internal/pkg/testing/setup.go | 4 +-- 11 files changed, 16 insertions(+), 35 deletions(-) rename internal/pkg/{esboot => testing/esutil}/README.MD (100%) rename internal/pkg/{esboot => testing/esutil}/bootstrap.go (99%) rename internal/pkg/{esboot => testing/esutil}/datastream.go (98%) rename internal/pkg/{esboot => testing/esutil}/esutil.go (99%) rename internal/pkg/{esboot => testing/esutil}/ilm.go (99%) rename internal/pkg/{esboot => testing/esutil}/index.go (98%) rename internal/pkg/{esboot => testing/esutil}/strmap.go (97%) rename internal/pkg/{esboot => testing/esutil}/template.go (99%) diff --git a/cmd/fleet/main.go b/cmd/fleet/main.go index 730ab9f9e..68d918c3e 100644 --- a/cmd/fleet/main.go +++ b/cmd/fleet/main.go @@ -7,13 +7,14 @@ package fleet import ( "context" "fmt" - "github.com/elastic/go-ucfg" - "github.com/elastic/go-ucfg/yaml" "io" "os" "sync" "time" + "github.com/elastic/go-ucfg" + "github.com/elastic/go-ucfg/yaml" + "github.com/elastic/fleet-server/v7/internal/pkg/action" "github.com/elastic/fleet-server/v7/internal/pkg/bulk" "github.com/elastic/fleet-server/v7/internal/pkg/cache" @@ -21,9 +22,7 @@ import ( "github.com/elastic/fleet-server/v7/internal/pkg/coordinator" "github.com/elastic/fleet-server/v7/internal/pkg/dl" "github.com/elastic/fleet-server/v7/internal/pkg/env" - "github.com/elastic/fleet-server/v7/internal/pkg/esboot" "github.com/elastic/fleet-server/v7/internal/pkg/logger" - "github.com/elastic/fleet-server/v7/internal/pkg/migrate" "github.com/elastic/fleet-server/v7/internal/pkg/monitor" "github.com/elastic/fleet-server/v7/internal/pkg/policy" "github.com/elastic/fleet-server/v7/internal/pkg/profile" @@ -472,24 +471,6 @@ func (f *FleetServer) runServer(ctx context.Context, cfg *config.Config) (err er } sv := saved.NewMgr(bulker, savedObjectKey()) - // Initial indices bootstrapping, needed for agents actions development - // TODO: remove this after the indices bootstrapping logic implemented in ES plugin - bootFlag := env.GetStr( - "FLEET_ES_BOOT", - "", - ) - if bootFlag == "1" { - log.Debug().Msg("FLEET_ES_BOOT is set to true, perform bootstrap") - err = esboot.EnsureESIndices(ctx, es) - if err != nil { - return err - } - err = migrate.Migrate(ctx, log.Logger, sv, bulker) - if err != nil { - return err - } - } - // Replacing to errgroup context g, ctx := errgroup.WithContext(ctx) diff --git a/dev-tools/integration/main.go b/dev-tools/integration/main.go index 3484529ad..a4e329319 100644 --- a/dev-tools/integration/main.go +++ b/dev-tools/integration/main.go @@ -11,7 +11,7 @@ import ( "github.com/elastic/fleet-server/v7/internal/pkg/config" "github.com/elastic/fleet-server/v7/internal/pkg/es" - "github.com/elastic/fleet-server/v7/internal/pkg/esboot" + "github.com/elastic/fleet-server/v7/internal/pkg/testing/esutil" "github.com/rs/zerolog/log" ) @@ -34,15 +34,15 @@ func main() { es, err := es.NewClient(ctx, cfg) checkErr(err) - err = esboot.EnsureESIndices(ctx, es) + err = esutil.EnsureESIndices(ctx, es) checkErr(err) // Create .kibana index for integration tests // This temporarily until all the parts are unplugged from .kibana // Otherwise the fleet server fails to start at the moment const name = ".kibana" - err = esboot.EnsureIndex(ctx, es, name, kibanaMapping) - if errors.Is(err, esboot.ErrResourceAlreadyExists) { + err = esutil.EnsureIndex(ctx, es, name, kibanaMapping) + if errors.Is(err, esutil.ErrResourceAlreadyExists) { log.Info().Str("name", name).Msg("Index already exists") err = nil } diff --git a/internal/pkg/esboot/README.MD b/internal/pkg/testing/esutil/README.MD similarity index 100% rename from internal/pkg/esboot/README.MD rename to internal/pkg/testing/esutil/README.MD diff --git a/internal/pkg/esboot/bootstrap.go b/internal/pkg/testing/esutil/bootstrap.go similarity index 99% rename from internal/pkg/esboot/bootstrap.go rename to internal/pkg/testing/esutil/bootstrap.go index 9906a8f52..535f201d7 100644 --- a/internal/pkg/esboot/bootstrap.go +++ b/internal/pkg/testing/esutil/bootstrap.go @@ -2,7 +2,7 @@ // or more contributor license agreements. Licensed under the Elastic License; // you may not use this file except in compliance with the Elastic License. -package esboot +package esutil import ( "context" diff --git a/internal/pkg/esboot/datastream.go b/internal/pkg/testing/esutil/datastream.go similarity index 98% rename from internal/pkg/esboot/datastream.go rename to internal/pkg/testing/esutil/datastream.go index da518aaab..d31a37b78 100644 --- a/internal/pkg/esboot/datastream.go +++ b/internal/pkg/testing/esutil/datastream.go @@ -2,7 +2,7 @@ // or more contributor license agreements. Licensed under the Elastic License; // you may not use this file except in compliance with the Elastic License. -package esboot +package esutil import ( "context" diff --git a/internal/pkg/esboot/esutil.go b/internal/pkg/testing/esutil/esutil.go similarity index 99% rename from internal/pkg/esboot/esutil.go rename to internal/pkg/testing/esutil/esutil.go index a6c251e7d..1bace262b 100644 --- a/internal/pkg/esboot/esutil.go +++ b/internal/pkg/testing/esutil/esutil.go @@ -2,7 +2,7 @@ // or more contributor license agreements. Licensed under the Elastic License; // you may not use this file except in compliance with the Elastic License. -package esboot +package esutil import ( "encoding/json" diff --git a/internal/pkg/esboot/ilm.go b/internal/pkg/testing/esutil/ilm.go similarity index 99% rename from internal/pkg/esboot/ilm.go rename to internal/pkg/testing/esutil/ilm.go index 34256c3e5..16dc28271 100644 --- a/internal/pkg/esboot/ilm.go +++ b/internal/pkg/testing/esutil/ilm.go @@ -2,7 +2,7 @@ // or more contributor license agreements. Licensed under the Elastic License; // you may not use this file except in compliance with the Elastic License. -package esboot +package esutil import ( "context" diff --git a/internal/pkg/esboot/index.go b/internal/pkg/testing/esutil/index.go similarity index 98% rename from internal/pkg/esboot/index.go rename to internal/pkg/testing/esutil/index.go index a6ebcd877..6b61534af 100644 --- a/internal/pkg/esboot/index.go +++ b/internal/pkg/testing/esutil/index.go @@ -2,7 +2,7 @@ // or more contributor license agreements. Licensed under the Elastic License; // you may not use this file except in compliance with the Elastic License. -package esboot +package esutil import ( "context" diff --git a/internal/pkg/esboot/strmap.go b/internal/pkg/testing/esutil/strmap.go similarity index 97% rename from internal/pkg/esboot/strmap.go rename to internal/pkg/testing/esutil/strmap.go index 9794655aa..3e0950ff1 100644 --- a/internal/pkg/esboot/strmap.go +++ b/internal/pkg/testing/esutil/strmap.go @@ -2,7 +2,7 @@ // or more contributor license agreements. Licensed under the Elastic License; // you may not use this file except in compliance with the Elastic License. -package esboot +package esutil type stringMap map[string]interface{} diff --git a/internal/pkg/esboot/template.go b/internal/pkg/testing/esutil/template.go similarity index 99% rename from internal/pkg/esboot/template.go rename to internal/pkg/testing/esutil/template.go index bbea76279..0873c4885 100644 --- a/internal/pkg/esboot/template.go +++ b/internal/pkg/testing/esutil/template.go @@ -2,7 +2,7 @@ // or more contributor license agreements. Licensed under the Elastic License; // you may not use this file except in compliance with the Elastic License. -package esboot +package esutil import ( "context" diff --git a/internal/pkg/testing/setup.go b/internal/pkg/testing/setup.go index 84a30b5c7..03acdc368 100644 --- a/internal/pkg/testing/setup.go +++ b/internal/pkg/testing/setup.go @@ -15,7 +15,7 @@ import ( "github.com/elastic/fleet-server/v7/internal/pkg/bulk" "github.com/elastic/fleet-server/v7/internal/pkg/config" - "github.com/elastic/fleet-server/v7/internal/pkg/esboot" + "github.com/elastic/fleet-server/v7/internal/pkg/testing/esutil" ) var defaultCfg config.Config @@ -53,7 +53,7 @@ func SetupBulk(ctx context.Context, t *testing.T, opts ...bulk.BulkOpt) bulk.Bul func SetupIndex(ctx context.Context, t *testing.T, bulker bulk.Bulk, mapping string) string { t.Helper() index := xid.New().String() - err := esboot.EnsureIndex(ctx, bulker.Client(), index, mapping) + err := esutil.EnsureIndex(ctx, bulker.Client(), index, mapping) if err != nil { t.Fatal(err) }