From c6c9aef5c7edd1c1eb3b29e137c8968354e2c517 Mon Sep 17 00:00:00 2001 From: Blake Rouse Date: Thu, 13 May 2021 20:03:18 -0400 Subject: [PATCH] [Elastic Agent] Handle case where policy doesn't contain Fleet connection information (#25707) * Handle case where policy doesn't contain Fleet connection information. * Add changelog entry. (cherry picked from commit e86109e560f0663397d40d254c71e8922cc85578) --- x-pack/elastic-agent/CHANGELOG.next.asciidoc | 2 ++ .../actions/handlers/handler_action_policy_change.go | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/x-pack/elastic-agent/CHANGELOG.next.asciidoc b/x-pack/elastic-agent/CHANGELOG.next.asciidoc index b5befcd4b19..e28707cdbbd 100644 --- a/x-pack/elastic-agent/CHANGELOG.next.asciidoc +++ b/x-pack/elastic-agent/CHANGELOG.next.asciidoc @@ -65,6 +65,8 @@ - Fixed issue when unversioned home is set and invoked watcher failing with ENOENT {issue}25371[25371] - Fixed Elastic Agent: expecting Dict and received *transpiler.Key for '0' {issue}24453[24453] - Fix AckBatch to do nothing when no actions passed {pull}25562[25562] +- Add error log entry when listener creation fails {issue}23483[23482] +- Handle case where policy doesn't contain Fleet connection information {pull}25707[25707] ==== New features diff --git a/x-pack/elastic-agent/pkg/agent/application/pipeline/actions/handlers/handler_action_policy_change.go b/x-pack/elastic-agent/pkg/agent/application/pipeline/actions/handlers/handler_action_policy_change.go index a82b39b6763..d05be4a57b5 100644 --- a/x-pack/elastic-agent/pkg/agent/application/pipeline/actions/handlers/handler_action_policy_change.go +++ b/x-pack/elastic-agent/pkg/agent/application/pipeline/actions/handlers/handler_action_policy_change.go @@ -100,6 +100,14 @@ func (h *PolicyChange) handleFleetServerHosts(ctx context.Context, c *config.Con if len(h.setters) == 0 { return nil } + data, err := c.ToMapStr() + if err != nil { + return errors.New(err, "could not convert the configuration from the policy", errors.TypeConfig) + } + if _, ok := data["fleet"]; !ok { + // no fleet information in the configuration (skip checking client) + return nil + } cfg, err := configuration.NewFromConfig(c) if err != nil {