@@ -18,10 +18,12 @@ import (
18
18
"github.com/elastic/elastic-agent-libs/logp"
19
19
20
20
"github.com/elastic/elastic-agent/internal/pkg/agent/application/coordinator"
21
+ "github.com/elastic/elastic-agent/internal/pkg/agent/application/dispatcher"
21
22
"github.com/elastic/elastic-agent/internal/pkg/agent/application/info"
22
23
"github.com/elastic/elastic-agent/internal/pkg/agent/application/monitoring"
23
24
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
24
25
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade"
26
+ "github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/details"
25
27
"github.com/elastic/elastic-agent/internal/pkg/agent/configuration"
26
28
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
27
29
"github.com/elastic/elastic-agent/internal/pkg/agent/storage"
@@ -34,6 +36,7 @@ import (
34
36
"github.com/elastic/elastic-agent/internal/pkg/fleetapi/acker/lazy"
35
37
"github.com/elastic/elastic-agent/internal/pkg/fleetapi/acker/retrier"
36
38
fleetclient "github.com/elastic/elastic-agent/internal/pkg/fleetapi/client"
39
+ "github.com/elastic/elastic-agent/internal/pkg/queue"
37
40
"github.com/elastic/elastic-agent/internal/pkg/release"
38
41
"github.com/elastic/elastic-agent/pkg/component"
39
42
"github.com/elastic/elastic-agent/pkg/component/runtime"
@@ -52,6 +55,7 @@ func New(
52
55
testingMode bool ,
53
56
fleetInitTimeout time.Duration ,
54
57
disableMonitoring bool ,
58
+ initialUpgradeDetails * details.Details ,
55
59
modifiers ... component.PlatformModifier ,
56
60
) (* coordinator.Coordinator , coordinator.ConfigManager , composable.Controller , error ) {
57
61
@@ -131,7 +135,6 @@ func New(
131
135
var compModifiers = []coordinator.ComponentsModifier {InjectAPMConfig }
132
136
var composableManaged bool
133
137
var isManaged bool
134
-
135
138
var actionAcker acker.Acker
136
139
if testingMode {
137
140
log .Info ("Elastic Agent has been started in testing mode and is managed through the control protocol" )
@@ -195,8 +198,19 @@ func New(
195
198
batchedAcker := lazy .NewAcker (fleetAcker , log , lazy .WithRetrier (retrier ))
196
199
actionAcker = stateStore .NewStateStoreActionAcker (batchedAcker , stateStorage )
197
200
201
+ actionQueue , err := queue .NewActionQueue (stateStorage .Queue (), stateStorage )
202
+ if err != nil {
203
+ return nil , nil , nil , fmt .Errorf ("unable to initialize action queue: %w" , err )
204
+ }
205
+
206
+ if initialUpgradeDetails == nil {
207
+ // initial upgrade details are nil (normally the caller supplies the ones from the marker file at this point),
208
+ // hence, extract any scheduled upgrade details from the action queue.
209
+ initialUpgradeDetails = dispatcher .GetScheduledUpgradeDetails (log , actionQueue .Actions (), time .Now ())
210
+ }
211
+
198
212
// TODO: stop using global state
199
- managed , err = newManagedConfigManager (ctx , log , agentInfo , cfg , store , runtime , fleetInitTimeout , paths .Top (), client , fleetAcker , actionAcker , retrier , stateStorage , upgrader )
213
+ managed , err = newManagedConfigManager (ctx , log , agentInfo , cfg , store , runtime , fleetInitTimeout , paths .Top (), client , fleetAcker , actionAcker , retrier , stateStorage , actionQueue , upgrader )
200
214
if err != nil {
201
215
return nil , nil , nil , err
202
216
}
@@ -210,7 +224,7 @@ func New(
210
224
return nil , nil , nil , errors .New (err , "failed to initialize composable controller" )
211
225
}
212
226
213
- coord := coordinator .New (log , cfg , logLevel , agentInfo , specs , reexec , upgrader , runtime , configMgr , varsManager , caps , monitor , isManaged , actionAcker , compModifiers ... )
227
+ coord := coordinator .New (log , cfg , logLevel , agentInfo , specs , reexec , upgrader , runtime , configMgr , varsManager , caps , monitor , isManaged , actionAcker , initialUpgradeDetails , compModifiers ... )
214
228
if managed != nil {
215
229
// the coordinator requires the config manager as well as in managed-mode the config manager requires the
216
230
// coordinator, so it must be set here once the coordinator is created
0 commit comments