Skip to content

Commit

Permalink
Add FLEET_FORCE. Don't update Kibana config when Fleet Server running…
Browse files Browse the repository at this point in the history
… locally.
  • Loading branch information
blakerouse committed Mar 1, 2021
1 parent bf14e76 commit 896efa2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ func (h *handlerPolicyChange) Handle(ctx context.Context, a action, acker fleetA
}

func (h *handlerPolicyChange) handleKibanaHosts(c *config.Config) (err error) {
// do not update kibana host from policy; no setters provided with local Fleet Server
if len(h.setters) == 0 {
return nil
}

cfg, err := configuration.NewFromConfig(c)
if err != nil {
return errors.New(err, "could not parse the configuration from the policy", errors.TypeConfig)
Expand Down
5 changes: 4 additions & 1 deletion x-pack/elastic-agent/pkg/agent/application/managed_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ func newManaged(
agentInfo: agentInfo,
config: cfg,
store: store,
setters: []clientSetter{acker},
}
if cfg.Fleet.Server == nil {
// setters only set when not running a local Fleet Server
policyChanger.setters = []clientSetter{acker}
}
actionDispatcher.MustRegister(
&fleetapi.ActionPolicyChange{},
Expand Down
12 changes: 12 additions & 0 deletions x-pack/elastic-agent/pkg/agent/cmd/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

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

"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/info"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/errors"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/cli"
)
Expand Down Expand Up @@ -92,6 +93,10 @@ be used when the same credentials will be used across all the possible actions a
KIBANA_HOST - kibana host [http://kibana:5601]
KIBANA_USERNAME - kibana username [$ELASTICSEARCH_USERNAME]
KIBANA_PASSWORD - kibana password [$ELASTICSEARCH_PASSWORD]
By default when this command starts it will check for an existing fleet.yml. If that file already exists then
all the above actions will be skipped, because the Elastic Agent has already been enrolled. To ensure that enrollment
occurs on every start of the container set FLEET_FORCE to 1.
`,
Run: func(c *cobra.Command, args []string) {
if err := containerCmd(streams, c, flags, args); err != nil {
Expand All @@ -109,6 +114,13 @@ func containerCmd(streams *cli.IOStreams, cmd *cobra.Command, flags *globalFlags
if err != nil {
return err
}

_, err = os.Stat(info.AgentConfigFile())
if !os.IsNotExist(err) && !envBool("FLEET_FORCE") {
// already enrolled, just run the standard run
return run(flags, streams)
}

// Remove FLEET_SETUP in 8.x
// The FLEET_SETUP environment variable boolean is a fallback to the old name. The name was updated to
// reflect that its setting up Fleet in Kibana versus setting up Fleet Server.
Expand Down

0 comments on commit 896efa2

Please sign in to comment.