Skip to content

Commit 2463b1c

Browse files
committed
Move ComponentsModifies to the component package
1 parent 2b2dff7 commit 2463b1c

File tree

6 files changed

+12
-14
lines changed

6 files changed

+12
-14
lines changed

internal/pkg/agent/application/application.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func New(
171171

172172
var configMgr coordinator.ConfigManager
173173
var managed *managedConfigManager
174-
var compModifiers = []coordinator.ComponentsModifier{InjectAPMConfig}
174+
var compModifiers = []component.ComponentsModifier{InjectAPMConfig}
175175
var composableManaged bool
176176
var isManaged bool
177177
var actionAcker acker.Acker

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,6 @@ type VarsManager interface {
224224
Watch() <-chan []*transpiler.Vars
225225
}
226226

227-
// ComponentsModifier is a function that takes the computed components model and modifies it before
228-
// passing it into the components runtime manager.
229-
type ComponentsModifier func(comps []component.Component, cfg map[string]interface{}) ([]component.Component, error)
230-
231227
// managerShutdownTimeout is how long the coordinator will wait during shutdown
232228
// to receive termination states from its managers.
233229
// Note: The current timeout (5s) is shorter than the default stop timeout for
@@ -267,7 +263,7 @@ type Coordinator struct {
267263
otelCfg *confmap.Conf
268264

269265
caps capabilities.Capabilities
270-
modifiers []ComponentsModifier
266+
modifiers []component.ComponentsModifier
271267

272268
// The current state of the Coordinator. This value and its subfields are
273269
// safe to read directly from within the main Coordinator goroutine.
@@ -439,7 +435,7 @@ func New(
439435
otelMgr OTelManager,
440436
fleetAcker acker.Acker,
441437
initialUpgradeDetails *details.Details,
442-
modifiers ...ComponentsModifier,
438+
modifiers ...component.ComponentsModifier,
443439
) *Coordinator {
444440
var fleetState cproto.State
445441
var fleetMessage string

internal/pkg/agent/application/endpoint_component_modifier.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313

1414
"github.com/elastic/elastic-agent-client/v7/pkg/client"
1515
"github.com/elastic/elastic-agent-libs/transport/tlscommon"
16-
"github.com/elastic/elastic-agent/internal/pkg/agent/application/coordinator"
1716
"github.com/elastic/elastic-agent/pkg/component"
1817
"github.com/elastic/elastic-agent/pkg/core/logger"
1918
)
@@ -50,7 +49,7 @@ func (tlsCache) MakeKey(keyPassPath, certPath, keyPath string) string {
5049
// "revision": 1,
5150
// "type": "endpoint"
5251
// }
53-
func EndpointSignedComponentModifier() coordinator.ComponentsModifier {
52+
func EndpointSignedComponentModifier() component.ComponentsModifier {
5453
return func(comps []component.Component, cfg map[string]interface{}) ([]component.Component, error) {
5554
const signedKey = "signed"
5655

@@ -83,7 +82,7 @@ func EndpointSignedComponentModifier() coordinator.ComponentsModifier {
8382
// 'key_passphrase_path'.
8483
// It does so, ONLY for the client TLS configuration for mTLS used with
8584
// fleet-server.
86-
func EndpointTLSComponentModifier(log *logger.Logger) coordinator.ComponentsModifier {
85+
func EndpointTLSComponentModifier(log *logger.Logger) component.ComponentsModifier {
8786
return newEndpointTLSComponentModifier(log, &tlsCache{mu: &sync.Mutex{}})
8887
}
8988

internal/pkg/agent/application/fleet_server_bootstrap.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ var injectFleetServerInput = config.MustNewConfigFrom(map[string]interface{}{
5050

5151
// FleetServerComponentModifier modifies the comps to inject extra information from the policy into
5252
// the Fleet Server component and units needed to run Fleet Server correctly.
53-
func FleetServerComponentModifier(serverCfg *configuration.FleetServerConfig) coordinator.ComponentsModifier {
53+
func FleetServerComponentModifier(serverCfg *configuration.FleetServerConfig) component.ComponentsModifier {
5454
return func(comps []component.Component, _ map[string]interface{}) ([]component.Component, error) {
5555
for i, comp := range comps {
5656
if comp.InputSpec != nil && comp.InputSpec.InputType == fleetServer && comp.Err == nil {
@@ -118,7 +118,7 @@ func addBootstrapCfg(dst map[string]interface{}, es *configuration.Elasticsearch
118118

119119
// InjectFleetConfigComponentModifier The modifier that injects the fleet configuration for the components
120120
// that need to be able to connect to fleet server.
121-
func InjectFleetConfigComponentModifier(fleetCfg *configuration.FleetAgentConfig, agentInfo info.Agent) coordinator.ComponentsModifier {
121+
func InjectFleetConfigComponentModifier(fleetCfg *configuration.FleetAgentConfig, agentInfo info.Agent) component.ComponentsModifier {
122122
return func(comps []component.Component, cfg map[string]interface{}) ([]component.Component, error) {
123123
hostsStr := fleetCfg.Client.GetHosts()
124124
fleetHosts := make([]interface{}, 0, len(hostsStr))

internal/pkg/agent/application/inject_proxy_component_modifier.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"golang.org/x/net/http/httpproxy"
1111

1212
"github.com/elastic/elastic-agent-client/v7/pkg/client"
13-
"github.com/elastic/elastic-agent/internal/pkg/agent/application/coordinator"
1413
"github.com/elastic/elastic-agent/pkg/component"
1514
)
1615

@@ -20,7 +19,7 @@ import (
2019
// The URL used is the HTTPS_PROXY env var. If that's not set the HTTP_PROXY env var is used.
2120
// If there are no env vars set, or the unit's config has `proxy_disable: true`, nothing is injected
2221
// If the output config has `proxy_url: ""`, it will not be overwritten.
23-
func InjectProxyEndpointModifier() coordinator.ComponentsModifier {
22+
func InjectProxyEndpointModifier() component.ComponentsModifier {
2423
return func(comps []component.Component, _ map[string]interface{}) ([]component.Component, error) {
2524
for i, comp := range comps {
2625
if comp.InputSpec != nil && comp.InputSpec.InputType == endpoint {

pkg/component/component.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ func (c *Component) RemoveWorkDir(parentDirPath string) error {
286286
return os.RemoveAll(c.WorkDirPath(parentDirPath))
287287
}
288288

289+
// ComponentsModifier is a function that takes the computed components model and modifies it before
290+
// passing it into the components runtime manager.
291+
type ComponentsModifier func(comps []Component, cfg map[string]interface{}) ([]Component, error)
292+
289293
// Model is the components model with signed policy data
290294
// This replaces former top level []Components with the top Model that captures signed policy data.
291295
// The signed data is a part of the policy since 8.8.0 release and contains the signed policy fragments and the signature that can be validated.

0 commit comments

Comments
 (0)