-
Notifications
You must be signed in to change notification settings - Fork 148
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
Conversation
Pinging @elastic/elastic-agent (Team:Elastic-Agent) |
SonarQube Quality Gate |
💔 Build Failed
Expand to view the summary
Build stats
Steps errorsExpand to view the steps failures
|
🌐 Coverage report
|
@AndersonQ Shouldn't we have a changelog as this is a bug? |
There was a problem hiding this 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{}) { |
There was a problem hiding this comment.
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:
- Define a global error value instead of a type for
ErrDaemonReload
, wrap it as the inner error along with the real error and keep usingerrors.Is
- Keep the new type
ErrDaemonReload
, remove theIs
custom implementation from the type and do all the checks usingerrors.As
explicitly as you are asserting the type not the value
internal/pkg/agent/cmd/enroll_cmd.go
Outdated
func (e *ErrDaemonReload) Is(err error) bool { | ||
var errDaemonReload *ErrDaemonReload | ||
return errors.As(err, &errDaemonReload) | ||
} |
There was a problem hiding this comment.
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{})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comments above
7ab23e6
to
8a20ac8
Compare
This pull request is now in conflicts. Could you fix it? 🙏
|
got stale |
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
[ ] I have made corresponding changes to the documentation[ ] I have made corresponding change to the default configuration files[ ] I have added an entry in./changelog/fragments
using the changelog toolHow to test this PR locally
Start a agent container to enroll on fleet, it should succeed
Related issues
Logs
See #3628
Questions to ask yourself