Skip to content

Commit c45abb4

Browse files
committed
Merge branch 'main' into bitnami-kubectl-delete
2 parents 4a185fa + ff80471 commit c45abb4

24 files changed

+1266
-355
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: bug-fix
2+
summary: fix reporting of scheduled upgrade details across restarts and cancels
3+
component: elastic-agent
4+
pr: https://github.com/elastic/elastic-agent/pull/9562
5+
issue: https://github.com/elastic/elastic-agent/issues/8778
Lines changed: 32 additions & 0 deletions
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: Fix missing liveness healthcheck during container enrollment
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: elastic-agent
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/9612
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/9611

internal/pkg/agent/application/actions/handlers/handler_action_upgrade_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func TestUpgradeHandler(t *testing.T) {
115115
return nil, nil
116116
},
117117
},
118-
nil, nil, nil, nil, nil, false, nil, nil)
118+
nil, nil, nil, nil, nil, false, nil, nil, nil)
119119
//nolint:errcheck // We don't need the termination state of the Coordinator
120120
go c.Run(ctx)
121121

@@ -174,7 +174,7 @@ func TestUpgradeHandlerSameVersion(t *testing.T) {
174174
return nil, err
175175
},
176176
},
177-
nil, nil, nil, nil, nil, false, nil, nil)
177+
nil, nil, nil, nil, nil, false, nil, nil, nil)
178178
//nolint:errcheck // We don't need the termination state of the Coordinator
179179
go c.Run(ctx)
180180

@@ -233,7 +233,7 @@ func TestDuplicateActionsHandled(t *testing.T) {
233233
return nil, nil
234234
},
235235
},
236-
nil, nil, nil, nil, nil, false, nil, acker)
236+
nil, nil, nil, nil, nil, false, nil, acker, nil)
237237
//nolint:errcheck // We don't need the termination state of the Coordinator
238238
go c.Run(ctx)
239239

@@ -327,7 +327,7 @@ func TestUpgradeHandlerNewVersion(t *testing.T) {
327327
return nil, nil
328328
},
329329
},
330-
nil, nil, nil, nil, nil, false, nil, nil)
330+
nil, nil, nil, nil, nil, false, nil, nil, nil)
331331
//nolint:errcheck // We don't need the termination state of the Coordinator
332332
go c.Run(ctx)
333333

internal/pkg/agent/application/application.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ import (
1616
"github.com/elastic/elastic-agent-libs/logp"
1717

1818
"github.com/elastic/elastic-agent/internal/pkg/agent/application/coordinator"
19+
"github.com/elastic/elastic-agent/internal/pkg/agent/application/dispatcher"
1920
"github.com/elastic/elastic-agent/internal/pkg/agent/application/info"
2021
"github.com/elastic/elastic-agent/internal/pkg/agent/application/monitoring"
2122
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
2223
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade"
24+
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/details"
2325
"github.com/elastic/elastic-agent/internal/pkg/agent/configuration"
2426
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
2527
"github.com/elastic/elastic-agent/internal/pkg/agent/storage"
@@ -34,6 +36,7 @@ import (
3436
"github.com/elastic/elastic-agent/internal/pkg/fleetapi/acker/retrier"
3537
fleetclient "github.com/elastic/elastic-agent/internal/pkg/fleetapi/client"
3638
otelmanager "github.com/elastic/elastic-agent/internal/pkg/otel/manager"
39+
"github.com/elastic/elastic-agent/internal/pkg/queue"
3740
"github.com/elastic/elastic-agent/internal/pkg/release"
3841
"github.com/elastic/elastic-agent/pkg/component"
3942
"github.com/elastic/elastic-agent/pkg/component/runtime"
@@ -59,6 +62,7 @@ func New(
5962
fleetInitTimeout time.Duration,
6063
disableMonitoring bool,
6164
override CfgOverrider,
65+
initialUpgradeDetails *details.Details,
6266
modifiers ...component.PlatformModifier,
6367
) (*coordinator.Coordinator, coordinator.ConfigManager, composable.Controller, error) {
6468

@@ -143,7 +147,6 @@ func New(
143147
var compModifiers = []coordinator.ComponentsModifier{InjectAPMConfig}
144148
var composableManaged bool
145149
var isManaged bool
146-
147150
var actionAcker acker.Acker
148151
if testingMode {
149152
log.Info("Elastic Agent has been started in testing mode and is managed through the control protocol")
@@ -212,8 +215,19 @@ func New(
212215
batchedAcker := lazy.NewAcker(fleetAcker, log, lazy.WithRetrier(retrier))
213216
actionAcker = stateStore.NewStateStoreActionAcker(batchedAcker, stateStorage)
214217

218+
actionQueue, err := queue.NewActionQueue(stateStorage.Queue(), stateStorage)
219+
if err != nil {
220+
return nil, nil, nil, fmt.Errorf("unable to initialize action queue: %w", err)
221+
}
222+
223+
if initialUpgradeDetails == nil {
224+
// initial upgrade details are nil (normally the caller supplies the ones from the marker file at this point),
225+
// hence, extract any scheduled upgrade details from the action queue.
226+
initialUpgradeDetails = dispatcher.GetScheduledUpgradeDetails(log, actionQueue.Actions(), time.Now())
227+
}
228+
215229
// TODO: stop using global state
216-
managed, err = newManagedConfigManager(ctx, log, agentInfo, cfg, store, runtime, fleetInitTimeout, paths.Top(), client, fleetAcker, actionAcker, retrier, stateStorage, upgrader)
230+
managed, err = newManagedConfigManager(ctx, log, agentInfo, cfg, store, runtime, fleetInitTimeout, paths.Top(), client, fleetAcker, actionAcker, retrier, stateStorage, actionQueue, upgrader)
217231
if err != nil {
218232
return nil, nil, nil, err
219233
}
@@ -230,7 +244,7 @@ func New(
230244
if err != nil {
231245
return nil, nil, nil, fmt.Errorf("failed to create otel manager: %w", err)
232246
}
233-
coord := coordinator.New(log, cfg, logLevel, agentInfo, specs, reexec, upgrader, runtime, configMgr, varsManager, caps, monitor, isManaged, otelManager, actionAcker, compModifiers...)
247+
coord := coordinator.New(log, cfg, logLevel, agentInfo, specs, reexec, upgrader, runtime, configMgr, varsManager, caps, monitor, isManaged, otelManager, actionAcker, initialUpgradeDetails, compModifiers...)
234248
if managed != nil {
235249
// the coordinator requires the config manager as well as in managed-mode the config manager requires the
236250
// coordinator, so it must be set here once the coordinator is created

internal/pkg/agent/application/application_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func TestLimitsLog(t *testing.T) {
6464
time.Millisecond, // fleetInitTimeout
6565
true, // disable monitoring
6666
nil, // no configuration overrides
67+
nil,
6768
)
6869
require.NoError(t, err)
6970

internal/pkg/agent/application/coordinator/coordinator.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ func New(
423423
isManaged bool,
424424
otelMgr OTelManager,
425425
fleetAcker acker.Acker,
426+
initialUpgradeDetails *details.Details,
426427
modifiers ...ComponentsModifier,
427428
) *Coordinator {
428429
var fleetState cproto.State
@@ -433,11 +434,12 @@ func New(
433434
fleetMessage = "Not enrolled into Fleet"
434435
}
435436
state := State{
436-
State: agentclient.Starting,
437-
Message: "Starting",
438-
FleetState: fleetState,
439-
FleetMessage: fleetMessage,
440-
LogLevel: logLevel,
437+
State: agentclient.Starting,
438+
Message: "Starting",
439+
FleetState: fleetState,
440+
FleetMessage: fleetMessage,
441+
LogLevel: logLevel,
442+
UpgradeDetails: initialUpgradeDetails,
441443
}
442444
c := &Coordinator{
443445
logger: logger,

internal/pkg/agent/application/coordinator/coordinator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ func createCoordinator(t testing.TB, ctx context.Context, opts ...CoordinatorOpt
10931093
acker = &fakeActionAcker{}
10941094
}
10951095

1096-
coord := New(l, nil, logp.DebugLevel, ai, specs, &fakeReExecManager{}, upgradeManager, rm, cfgMgr, varsMgr, caps, monitoringMgr, o.managed, otelMgr, acker)
1096+
coord := New(l, nil, logp.DebugLevel, ai, specs, &fakeReExecManager{}, upgradeManager, rm, cfgMgr, varsMgr, caps, monitoringMgr, o.managed, otelMgr, acker, nil)
10971097
return coord, cfgMgr, varsMgr
10981098
}
10991099

0 commit comments

Comments
 (0)