Skip to content

Commit

Permalink
[Elastic Agent] Fix picking correct policy id for fleet-server (#25352)
Browse files Browse the repository at this point in the history
When running the container command, the policy id configured in the fleet-setup.yml file was only picked up, when fleet-server was not enabled. If a fleet-server policy is set, this will be set as the default.

Later on this setup call should be improved that not both setups are possible. Currently it could be that the fleet enroll and fleet server setup policy are not identical.

To partially test this PR, I did run the elastic agent locally as following:

```
sudo STATE_PATH=${GOPATH}/src/github.com/elastic/beats/x-pack/elastic-agent/state ./elastic-agent container
```

Adjust the path to your needs. In addition, I put the currently checked in fleet-setup.yml file into state directory. In parallel, an elastic-stack setup was running.
  • Loading branch information
ruflin authored Apr 28, 2021
1 parent f1fea95 commit 362d485
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion x-pack/elastic-agent/CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
- Fixed: limit for retries to Kibana configurable {issue}25063[25063]
- Fix issue with status and inspect inside of container {pull}25204[25204]
- Remove FLEET_SERVER_POLICY_NAME env variable as it was not used {pull}25149[25149]
- Reduce log level for listener cleanup to debug {pull}25274
- Passing in policy id to container command works {pull}25352[25352]
- Reduce log level for listener cleanup to debug {pull}25274[25274]

==== New features

Expand Down
7 changes: 4 additions & 3 deletions x-pack/elastic-agent/pkg/agent/cmd/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ func logError(streams *cli.IOStreams, err error) {
fmt.Fprintf(streams.Err, "Error: %v\n", err)
}

func logInfo(streams *cli.IOStreams, msg string) {
fmt.Fprintln(streams.Out, msg)
func logInfo(streams *cli.IOStreams, a ...interface{}) {
fmt.Fprintln(streams.Out, a...)
}

func logContainerCmd(streams *cli.IOStreams, cmd *cobra.Command) error {
Expand Down Expand Up @@ -292,10 +292,11 @@ func runContainerCmd(streams *cli.IOStreams, cmd *cobra.Command, cfg setupConfig
return err
}
}
policyID := ""
policyID := cfg.FleetServer.PolicyID
if policy != nil {
policyID = policy.ID
}
logInfo(streams, "Policy selected for enrollment: ", policyID)
cmdArgs, err := buildEnrollArgs(cfg, token, policyID)
if err != nil {
return err
Expand Down

0 comments on commit 362d485

Please sign in to comment.