Skip to content

Commit 1348b9c

Browse files
mergify[bot]blakerousepierrehilbert
authored
Make delayed enrollment try indefinitely (#4727) (#4800)
* Make delay enrollment indefinite. * Add changelog entry. (cherry picked from commit c14df02) Co-authored-by: Blake Rouse <blake.rouse@elastic.co> Co-authored-by: Pierre HILBERT <pierre.hilbert@elastic.co>
1 parent c988eb7 commit 1348b9c

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Kind can be one of:
2+
# - breaking-change: a change to previously-documented behavior
3+
# - deprecation: functionality that is being removed in a later release
4+
# - bug-fix: fixes a problem in a previous version
5+
# - enhancement: extends functionality but does not break or fix existing behavior
6+
# - feature: new functionality
7+
# - known-issue: problems that we are aware of in a given version
8+
# - security: impacts on the security of a product or a user’s deployment.
9+
# - upgrade: important information for someone upgrading from a prior version
10+
# - other: does not fit into any of the other categories
11+
kind: bug-fix
12+
13+
# Change summary; a 80ish characters long description of the change.
14+
summary: Make delayed enrollment try indefinitely
15+
16+
# Long description; in case the summary is not enough to describe the change
17+
# this field accommodate a description without length limits.
18+
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
19+
#description:
20+
21+
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
22+
component:
23+
24+
# PR URL; optional; the PR number that added the changeset.
25+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
26+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
27+
# Please provide it if you are adding a fragment for a different PR.
28+
pr: https://github.com/elastic/elastic-agent/pull/4727
29+
30+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
31+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
32+
issue: https://github.com/elastic/elastic-agent/issues/4716

internal/pkg/agent/cmd/run.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,18 @@ func tryDelayEnroll(ctx context.Context, logger *logger.Logger, cfg *configurati
548548
if err != nil {
549549
return nil, err
550550
}
551-
err = c.Execute(ctx, cli.NewIOStreams())
552-
if err != nil {
553-
return nil, err
551+
// perform the enrollment in a loop, it should keep trying to enroll no matter what
552+
// the enrollCmd has built in backoff so no need to wrap this in its own backoff as well
553+
for {
554+
if ctx.Err() != nil {
555+
return nil, ctx.Err()
556+
}
557+
err = c.Execute(ctx, cli.NewIOStreams())
558+
if err == nil {
559+
// enrollment was successful
560+
break
561+
}
562+
logger.Error(fmt.Errorf("failed to perform delayed enrollment (will try again): %w", err))
554563
}
555564
err = os.Remove(enrollPath)
556565
if err != nil {

0 commit comments

Comments
 (0)