Skip to content

Commit 756ecf1

Browse files
authored
Remove definitionsDir from k8s in agentdeployer (#1769)
1 parent 1f977e2 commit 756ecf1

File tree

2 files changed

+38
-47
lines changed

2 files changed

+38
-47
lines changed

internal/agentdeployer/factory.go

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type FactoryOptions struct {
4141
// Factory chooses the appropriate service runner for the given data stream, depending
4242
// on service configuration files defined in the package or data stream.
4343
func Factory(options FactoryOptions) (AgentDeployer, error) {
44-
agentDeployerName, agentDeployerPath, err := selectAgentDeployerType(options)
44+
agentDeployerName, err := selectAgentDeployerType(options)
4545
if err != nil {
4646
return nil, fmt.Errorf("failed to select agent deployer type: %w", err)
4747
}
@@ -68,51 +68,48 @@ func Factory(options FactoryOptions) (AgentDeployer, error) {
6868
return nil, nil
6969
case "k8s":
7070
opts := KubernetesAgentDeployerOptions{
71-
Profile: options.Profile,
72-
DefinitionsDir: agentDeployerPath,
73-
StackVersion: options.StackVersion,
74-
PolicyName: options.PolicyName,
75-
DataStream: options.DataStream,
76-
RunSetup: options.RunSetup,
77-
RunTestsOnly: options.RunTestsOnly,
78-
RunTearDown: options.RunTearDown,
71+
Profile: options.Profile,
72+
StackVersion: options.StackVersion,
73+
PolicyName: options.PolicyName,
74+
DataStream: options.DataStream,
75+
RunSetup: options.RunSetup,
76+
RunTestsOnly: options.RunTestsOnly,
77+
RunTearDown: options.RunTearDown,
7978
}
8079
return NewKubernetesAgentDeployer(opts)
8180
}
8281
return nil, fmt.Errorf("unsupported agent deployer (name: %s)", agentDeployerName)
8382
}
8483

85-
func selectAgentDeployerType(options FactoryOptions) (string, string, error) {
84+
func selectAgentDeployerType(options FactoryOptions) (string, error) {
8685
devDeployPath, err := FindDevDeployPath(options)
8786
if errors.Is(err, os.ErrNotExist) {
88-
return "default", "", nil
87+
return "default", nil
8988
}
9089
if err != nil {
91-
return "", "", fmt.Errorf("can't find \"%s\" directory: %w", options.DevDeployDir, err)
90+
return "", fmt.Errorf("can't find \"%s\" directory: %w", options.DevDeployDir, err)
9291
}
9392

9493
agentDeployerNames, err := findAgentDeployers(devDeployPath)
9594
if errors.Is(err, os.ErrNotExist) || len(agentDeployerNames) == 0 {
9695
logger.Debugf("Not agent deployer found, using default one")
97-
return "default", "", nil
96+
return "default", nil
9897
}
9998
if err != nil {
100-
return "", "", fmt.Errorf("failed to find agent deployer: %w", err)
99+
return "", fmt.Errorf("failed to find agent deployer: %w", err)
101100
}
102101
if len(agentDeployerNames) != 1 {
103-
return "", "", fmt.Errorf("expected to find only one agent deployer in \"%s\"", devDeployPath)
102+
return "", fmt.Errorf("expected to find only one agent deployer in \"%s\"", devDeployPath)
104103
}
105104
agentDeployerName := agentDeployerNames[0]
106105

107-
// if package defines `_dev/deploy/docker` folder to start their services, it should be
108-
// using the default agent deployer`
106+
// if package defines `_dev/deploy/docker` or `_dev/deploy/tf` folder to start their services,
107+
// it should be using the default agent deployer`
109108
if agentDeployerName == "docker" || agentDeployerName == "tf" {
110-
return "default", "", nil
109+
return "default", nil
111110
}
112111

113-
// No need to check if this path exists because it comes from a directory list.
114-
agentDeployerPath := filepath.Join(devDeployPath, agentDeployerName)
115-
return agentDeployerName, agentDeployerPath, nil
112+
return agentDeployerName, nil
116113
}
117114

118115
// FindDevDeployPath function returns a path reference to the "_dev/deploy" directory.

internal/agentdeployer/kubernetes.go

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ import (
2525

2626
// KubernetesAgentDeployer is responsible for deploying resources in the Kubernetes cluster.
2727
type KubernetesAgentDeployer struct {
28-
profile *profile.Profile
29-
definitionsDir string
30-
stackVersion string
31-
policyName string
32-
dataStream string
28+
profile *profile.Profile
29+
stackVersion string
30+
policyName string
31+
dataStream string
3332

3433
agentRunID string
3534

@@ -39,11 +38,10 @@ type KubernetesAgentDeployer struct {
3938
}
4039

4140
type KubernetesAgentDeployerOptions struct {
42-
Profile *profile.Profile
43-
DefinitionsDir string
44-
StackVersion string
45-
PolicyName string
46-
DataStream string
41+
Profile *profile.Profile
42+
StackVersion string
43+
PolicyName string
44+
DataStream string
4745

4846
RunSetup bool
4947
RunTestsOnly bool
@@ -56,8 +54,6 @@ type kubernetesDeployedAgent struct {
5654
stackVersion string
5755

5856
agentName string
59-
60-
definitionsDir string
6157
}
6258

6359
func (s kubernetesDeployedAgent) TearDown(ctx context.Context) error {
@@ -67,7 +63,7 @@ func (s kubernetesDeployedAgent) TearDown(ctx context.Context) error {
6763
}
6864
err = kubectl.DeleteStdin(ctx, elasticAgentManagedYaml)
6965
if err != nil {
70-
return fmt.Errorf("can't uninstall Kubernetes resources (path: %s): %w", s.definitionsDir, err)
66+
return fmt.Errorf("can't uninstall Kubernetes Elastic Agent resources: %w", err)
7167
}
7268
return nil
7369
}
@@ -94,14 +90,13 @@ var _ DeployedAgent = new(kubernetesDeployedAgent)
9490
// NewKubernetesAgentDeployer function creates a new instance of KubernetesAgentDeployer.
9591
func NewKubernetesAgentDeployer(opts KubernetesAgentDeployerOptions) (*KubernetesAgentDeployer, error) {
9692
return &KubernetesAgentDeployer{
97-
profile: opts.Profile,
98-
definitionsDir: opts.DefinitionsDir,
99-
stackVersion: opts.StackVersion,
100-
policyName: opts.PolicyName,
101-
dataStream: opts.DataStream,
102-
runSetup: opts.RunSetup,
103-
runTestsOnly: opts.RunTestsOnly,
104-
runTearDown: opts.RunTearDown,
93+
profile: opts.Profile,
94+
stackVersion: opts.StackVersion,
95+
policyName: opts.PolicyName,
96+
dataStream: opts.DataStream,
97+
runSetup: opts.RunSetup,
98+
runTestsOnly: opts.RunTestsOnly,
99+
runTearDown: opts.RunTearDown,
105100
}, nil
106101
}
107102

@@ -140,11 +135,10 @@ func (ksd *KubernetesAgentDeployer) SetUp(ctx context.Context, agentInfo AgentIn
140135
// to deploy Agent Pod. Because of this, hostname inside pod will be equal to the name of the k8s host.
141136
agentInfo.Agent.Host.NamePrefix = "kind-control-plane"
142137
return &kubernetesDeployedAgent{
143-
agentInfo: agentInfo,
144-
definitionsDir: ksd.definitionsDir,
145-
profile: ksd.profile,
146-
stackVersion: ksd.stackVersion,
147-
agentName: agentName,
138+
agentInfo: agentInfo,
139+
profile: ksd.profile,
140+
stackVersion: ksd.stackVersion,
141+
agentName: agentName,
148142
}, nil
149143
}
150144

0 commit comments

Comments
 (0)