Skip to content

Commit

Permalink
Inject only when state is not restored (elastic#25664)
Browse files Browse the repository at this point in the history
  • Loading branch information
michalpristas authored May 12, 2021
1 parent 99ba1a2 commit 96cb26b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,18 @@ func New(
cfg *configuration.FleetAgentConfig,
rawConfig *config.Config,
wrapped gateway.FleetGateway,
emitter pipeline.EmitterFunc) (gateway.FleetGateway, error) {
if cfg.Server == nil {
emitter pipeline.EmitterFunc,
injectServer bool) (gateway.FleetGateway, error) {
if cfg.Server == nil || !injectServer {
// not running a local Fleet Server
return wrapped, nil
}

injectedCfg, err := injectFleetServer(rawConfig)
if err != nil {
return nil, errors.New(err, "failed to inject fleet-server input to start local Fleet Server", errors.TypeConfig)
}

return &fleetServerWrapper{
bgContext: ctx,
log: log,
Expand Down
5 changes: 3 additions & 2 deletions x-pack/elastic-agent/pkg/agent/application/managed_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,15 @@ func newManaged(
)

actions := stateStore.Actions()

stateRestored := false
if len(actions) > 0 && !managedApplication.wasUnenrolled() {
// TODO(ph) We will need an improvement on fleet, if there is an error while dispatching a
// persisted action on disk we should be able to ask Fleet to get the latest configuration.
// But at the moment this is not possible because the policy change was acked.
if err := store.ReplayActions(log, actionDispatcher, actionAcker, actions...); err != nil {
log.Errorf("could not recover state, error %+v, skipping...", err)
}
stateRestored = true
}

gateway, err := fleetgateway.New(
Expand All @@ -263,7 +264,7 @@ func newManaged(
if err != nil {
return nil, err
}
gateway, err = localgateway.New(managedApplication.bgContext, log, cfg.Fleet, rawConfig, gateway, emit)
gateway, err = localgateway.New(managedApplication.bgContext, log, cfg.Fleet, rawConfig, gateway, emit, !stateRestored)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 96cb26b

Please sign in to comment.