Skip to content

Commit 896efa2

Browse files
committed
Add FLEET_FORCE. Don't update Kibana config when Fleet Server running locally.
1 parent bf14e76 commit 896efa2

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

x-pack/elastic-agent/pkg/agent/application/handler_action_policy_change.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ func (h *handlerPolicyChange) Handle(ctx context.Context, a action, acker fleetA
6262
}
6363

6464
func (h *handlerPolicyChange) handleKibanaHosts(c *config.Config) (err error) {
65+
// do not update kibana host from policy; no setters provided with local Fleet Server
66+
if len(h.setters) == 0 {
67+
return nil
68+
}
69+
6570
cfg, err := configuration.NewFromConfig(c)
6671
if err != nil {
6772
return errors.New(err, "could not parse the configuration from the policy", errors.TypeConfig)

x-pack/elastic-agent/pkg/agent/application/managed_mode.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ func newManaged(
181181
agentInfo: agentInfo,
182182
config: cfg,
183183
store: store,
184-
setters: []clientSetter{acker},
184+
}
185+
if cfg.Fleet.Server == nil {
186+
// setters only set when not running a local Fleet Server
187+
policyChanger.setters = []clientSetter{acker}
185188
}
186189
actionDispatcher.MustRegister(
187190
&fleetapi.ActionPolicyChange{},

x-pack/elastic-agent/pkg/agent/cmd/container.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
"github.com/elastic/beats/v7/libbeat/kibana"
2121

22+
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/info"
2223
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/errors"
2324
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/cli"
2425
)
@@ -92,6 +93,10 @@ be used when the same credentials will be used across all the possible actions a
9293
KIBANA_HOST - kibana host [http://kibana:5601]
9394
KIBANA_USERNAME - kibana username [$ELASTICSEARCH_USERNAME]
9495
KIBANA_PASSWORD - kibana password [$ELASTICSEARCH_PASSWORD]
96+
97+
By default when this command starts it will check for an existing fleet.yml. If that file already exists then
98+
all the above actions will be skipped, because the Elastic Agent has already been enrolled. To ensure that enrollment
99+
occurs on every start of the container set FLEET_FORCE to 1.
95100
`,
96101
Run: func(c *cobra.Command, args []string) {
97102
if err := containerCmd(streams, c, flags, args); err != nil {
@@ -109,6 +114,13 @@ func containerCmd(streams *cli.IOStreams, cmd *cobra.Command, flags *globalFlags
109114
if err != nil {
110115
return err
111116
}
117+
118+
_, err = os.Stat(info.AgentConfigFile())
119+
if !os.IsNotExist(err) && !envBool("FLEET_FORCE") {
120+
// already enrolled, just run the standard run
121+
return run(flags, streams)
122+
}
123+
112124
// Remove FLEET_SETUP in 8.x
113125
// The FLEET_SETUP environment variable boolean is a fallback to the old name. The name was updated to
114126
// reflect that its setting up Fleet in Kibana versus setting up Fleet Server.

0 commit comments

Comments
 (0)