From e86109e560f0663397d40d254c71e8922cc85578 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. --- x-pack/elastic-agent/CHANGELOG.next.asciidoc | 1 + .../actions/handlers/handler_action_policy_change.go | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/x-pack/elastic-agent/CHANGELOG.next.asciidoc b/x-pack/elastic-agent/CHANGELOG.next.asciidoc index 4eeacb4c2462..ae4acaa856a8 100644 --- a/x-pack/elastic-agent/CHANGELOG.next.asciidoc +++ b/x-pack/elastic-agent/CHANGELOG.next.asciidoc @@ -65,6 +65,7 @@ - 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 a82b39b67637..d05be4a57b59 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 {