Skip to content

Commit

Permalink
Remove ES bootsrap code from Fleet Server (#105)
Browse files Browse the repository at this point in the history
* Moved it to testing/esutil package because it is still used for
  integration testing indices bootstrapping
  • Loading branch information
aleksmaus authored Mar 1, 2021
1 parent 366abd8 commit f96943f
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 35 deletions.
25 changes: 3 additions & 22 deletions cmd/fleet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@ 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"
"github.com/elastic/fleet-server/v7/internal/pkg/config"
"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"
Expand Down Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions dev-tools/integration/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/testing/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit f96943f

Please sign in to comment.