Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore enroll cmd failing to restart daemon if running on a container #3631

Closed
wants to merge 3 commits into from

Conversation

AndersonQ
Copy link
Member

@AndersonQ AndersonQ commented Oct 18, 2023

What does this PR do?

Makes the container command to ignore the enroll command not being able to restart the daemon. There is no daemon on a container, therefore nothing to be restarted.

Why is it important?

If the enroll command fails when the agent container is started for the 1st time to enroll on fleet-server, it'd fail and exit.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [ ] I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • [ ] I have added an entry in ./changelog/fragments using the changelog tool
  • I have added an integration test or an E2E test

How to test this PR locally

Start a agent container to enroll on fleet, it should succeed

docker run \
  --env FLEET_ENROLL=1 \
  --env FLEET_URL=https://fleet-url:8220/ \
  --env FLEET_ENROLLMENT_TOKEN=SOME_TOKEN \
  --env FLEET_INSERUCE=true \
  docker.elastic.co/beats/elastic-agent:8.12.0-SNAPSHOT

Related issues

Logs

See #3628

Questions to ask yourself

  • How are we going to support this in production?
  • How are we going to measure its adoption?
  • How are we going to debug this?
  • What are the metrics I should take care of?
  • ...

@AndersonQ AndersonQ added bug Something isn't working Team:Elastic-Agent Label for the Agent team skip-changelog backport-v8.11.0 Automated backport with mergify labels Oct 18, 2023
@AndersonQ AndersonQ self-assigned this Oct 18, 2023
@AndersonQ AndersonQ requested a review from a team as a code owner October 18, 2023 17:50
@elasticmachine
Copy link
Contributor

Pinging @elastic/elastic-agent (Team:Elastic-Agent)

@AndersonQ AndersonQ requested a review from cmacknz October 18, 2023 17:59
@elastic-sonarqube
Copy link

@elasticmachine
Copy link
Contributor

elasticmachine commented Oct 18, 2023

💔 Build Failed

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2023-10-19T15:03:42.778+0000

  • Duration: 6 min 20 sec

Steps errors 1

Expand to view the steps failures

check
  • Took 1 min 7 sec . View more details here
  • Description: make check-ci

❕ Flaky test report

No test was executed to be analysed.

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages.

  • run integration tests : Run the Elastic Agent Integration tests.

  • run end-to-end tests : Generate the packages and run the E2E Tests.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@elasticmachine
Copy link
Contributor

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 98.81% (83/84) 👍
Files 67.105% (204/304) 👍
Classes 65.78% (371/564) 👍 0.061
Methods 53.107% (1171/2205) 👍 0.064
Lines 39.337% (13640/34675) 👎 -0.025
Conditionals 100.0% (0/0) 💚

@pierrehilbert
Copy link
Contributor

@AndersonQ Shouldn't we have a changelog as this is a bug?

Copy link
Member

@pchila pchila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to see the ErrDaemonReload.Is implementation cleaned up before this code is merged.

@@ -318,6 +318,10 @@ func runContainerCmd(streams *cli.IOStreams, cfg setupConfig) error {
}
err = enroll.Wait()
if err != nil {
if errors.Is(err, &ErrDaemonReload{}) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are using errors.Is it usually means that you want to check a specific error value (which is usually a global value in some package): for example

errors.Is(err, fs.ErrNotExist)

where the error value is defined like this

I see that you forced the implementation of errors.Is on the error type using errors.As below and this is a bit of a smell (you are changing the semantics of errors.Is).

The way I see we have 2 options here:

  1. Define a global error value instead of a type for ErrDaemonReload , wrap it as the inner error along with the real error and keep using errors.Is
  2. Keep the new type ErrDaemonReload, remove the Is custom implementation from the type and do all the checks using errors.As explicitly as you are asserting the type not the value

Comment on lines 131 to 134
func (e *ErrDaemonReload) Is(err error) bool {
var errDaemonReload *ErrDaemonReload
return errors.As(err, &errDaemonReload)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above: Is should compare the error values, not types

err := fmt.Errorf("some wrapping: %w",
&ErrDaemonReload{err: errors.New("some error")})

assert.True(t, errors.Is(err, &ErrDaemonReload{}))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments above

@AndersonQ AndersonQ marked this pull request as draft October 19, 2023 15:04
@mergify
Copy link
Contributor

mergify bot commented Oct 24, 2023

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b 3628-docker-enroll upstream/3628-docker-enroll
git merge upstream/main
git push upstream 3628-docker-enroll

@AndersonQ
Copy link
Member Author

got stale

@AndersonQ AndersonQ closed this Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v8.11.0 Automated backport with mergify bug Something isn't working skip-changelog Team:Elastic-Agent Label for the Agent team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Elastic Agent enroll fails to restart daemon on docker
4 participants