Skip to content

Commit 934e899

Browse files
committed
Merge remote-tracking branch 'upstream/main' into 1276-test-for-ignored-fields
2 parents f2d80a8 + c2ff98b commit 934e899

File tree

81 files changed

+58717
-446
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+58717
-446
lines changed

.buildkite/pipeline.trigger.integration.tests.sh

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ STACK_COMMAND_TESTS=(
2020
)
2121

2222
for test in "${STACK_COMMAND_TESTS[@]}"; do
23-
echo " - label: \":go: Integration test: ${test}\""
23+
test_name=${test#"test-"}
24+
echo " - label: \":go: Integration test: ${test_name}\""
2425
echo " command: ./.buildkite/scripts/integration_tests.sh -t ${test}"
2526
echo " agents:"
2627
echo " provider: \"gcp\""
@@ -39,7 +40,12 @@ CHECK_PACKAGES_TESTS=(
3940
)
4041
for independent_agent in false true ; do
4142
for test in "${CHECK_PACKAGES_TESTS[@]}"; do
42-
echo " - label: \":go: Integration test: ${test} - independent_agent ${independent_agent}\""
43+
label_suffix=""
44+
if [[ "$independent_agent" == "true" ]]; then
45+
label_suffix=" (independent agent)"
46+
fi
47+
test_name=${test#"test-check-packages-"}
48+
echo " - label: \":go: Integration test: ${test_name}${label_suffix}\""
4349
echo " command: ./.buildkite/scripts/integration_tests.sh -t ${test}"
4450
echo " agents:"
4551
echo " provider: \"gcp\""
@@ -76,8 +82,12 @@ done
7682
pushd test/packages/parallel > /dev/null
7783
for independent_agent in false true; do
7884
for package in $(find . -maxdepth 1 -mindepth 1 -type d) ; do
85+
label_suffix=""
86+
if [[ "$independent_agent" == "true" ]]; then
87+
label_suffix=" (independent agent)"
88+
fi
7989
package_name=$(basename "${package}")
80-
echo " - label: \":go: Integration test: ${package_name} - independent_agent ${independent_agent}\""
90+
echo " - label: \":go: Integration test: ${package_name}${label_suffix}\""
8191
echo " key: \"integration-parallel-${package_name}-agent-${independent_agent}\""
8292
echo " command: ./.buildkite/scripts/integration_tests.sh -t test-check-packages-parallel -p ${package_name}"
8393
echo " env:"
@@ -93,38 +103,42 @@ done
93103

94104
popd > /dev/null
95105

96-
echo " - label: \":go: Integration test: test-build-zip\""
106+
echo " - label: \":go: Integration test: build-zip\""
97107
echo " command: ./.buildkite/scripts/integration_tests.sh -t test-build-zip"
98108
echo " agents:"
99109
echo " provider: \"gcp\""
100110
echo " artifact_paths:"
101111
echo " - build/elastic-stack-dump/build-zip/logs/*.log"
102112
echo " - build/packages/*.sig"
103113

104-
echo " - label: \":go: Integration test: test-install-zip\""
114+
echo " - label: \":go: Integration test: install-zip\""
105115
echo " command: ./.buildkite/scripts/integration_tests.sh -t test-install-zip"
106116
echo " agents:"
107117
echo " provider: \"gcp\""
108118
echo " artifact_paths:"
109119
echo " - build/elastic-stack-dump/install-zip/logs/*.log"
110120

111-
echo " - label: \":go: Integration test: test-install-zip-shellinit\""
121+
echo " - label: \":go: Integration test: install-zip-shellinit\""
112122
echo " command: ./.buildkite/scripts/integration_tests.sh -t test-install-zip-shellinit"
113123
echo " agents:"
114124
echo " provider: \"gcp\""
115125
echo " artifact_paths:"
116126
echo " - build/elastic-stack-dump/install-zip-shellinit/logs/*.log"
117127

118128
for independent_agent in false true; do
119-
echo " - label: \":go: Integration test: test-system-test-flags - independent_agent ${independent_agent}\""
120-
echo " command: ./.buildkite/scripts/integration_tests.sh -t test-system-test-flags"
121-
echo " agents:"
122-
echo " provider: \"gcp\""
123-
echo " env:"
124-
echo " ELASTIC_PACKAGE_TEST_ENABLE_INDEPENDENT_AGENT: ${independent_agent}"
129+
label_suffix=""
130+
if [[ "$independent_agent" == "true" ]]; then
131+
label_suffix=" (independent agent)"
132+
fi
133+
echo " - label: \":go: Integration test: system-flags${label_suffix}\""
134+
echo " command: ./.buildkite/scripts/integration_tests.sh -t test-system-test-flags"
135+
echo " agents:"
136+
echo " provider: \"gcp\""
137+
echo " env:"
138+
echo " ELASTIC_PACKAGE_TEST_ENABLE_INDEPENDENT_AGENT: ${independent_agent}"
125139
done
126140

127-
echo " - label: \":go: Integration test: test-profiles-command\""
141+
echo " - label: \":go: Integration test: profiles-command\""
128142
echo " command: ./.buildkite/scripts/integration_tests.sh -t test-profiles-command"
129143
echo " env:"
130144
echo " DOCKER_COMPOSE_VERSION: \"false\""
@@ -134,7 +148,7 @@ echo " image: \"${LINUX_AGENT_IMAGE}\""
134148
echo " cpu: \"8\""
135149
echo " memory: \"4G\""
136150

137-
echo " - label: \":go: Integration test: test-check-update-version\""
151+
echo " - label: \":go: Integration test: check-update-version\""
138152
echo " command: ./.buildkite/scripts/integration_tests.sh -t test-check-update-version"
139153
echo " env:"
140154
echo " DEFAULT_VERSION_TAG: v0.80.0"

.github/dependabot.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ updates:
1010
reviewers:
1111
- "elastic/ecosystem"
1212
open-pull-requests-limit: 10
13+
groups:
14+
k8s:
15+
patterns:
16+
- "k8s.io/*"

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ test-stack-command-oldest:
5959
./scripts/test-stack-command.sh 7.14.2
6060

6161
test-stack-command-7x:
62-
./scripts/test-stack-command.sh 7.17.18
62+
./scripts/test-stack-command.sh 7.17.19
6363

6464
# Keeping a test for 8.6 because it has an specific configuration file.
6565
test-stack-command-86:
6666
./scripts/test-stack-command.sh 8.6.2
6767

6868
test-stack-command-8x:
69-
./scripts/test-stack-command.sh 8.13.0-SNAPSHOT
69+
./scripts/test-stack-command.sh 8.14.0-SNAPSHOT
7070

7171
test-stack-command-with-apm-server:
7272
APM_SERVER_ENABLED=true ./scripts/test-stack-command.sh

cmd/testrunner.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,14 @@ func testTypeCommandActionFactory(runner testrunner.TestRunner) cobraext.Command
366366
RunIndependentElasticAgent: runIndependentElasticAgent,
367367
})
368368

369+
// Results must be appended even if there is an error, since there could be
370+
// tests (e.g. system tests) that return both error and results.
369371
results = append(results, r...)
370372

371373
if err != nil {
372374
return fmt.Errorf("error running package %s tests: %w", testType, err)
373375
}
376+
374377
}
375378

376379
format := testrunner.TestReportFormat(reportFormat)

docs/howto/system_benchmarking.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ To use environment variables within the Terraform service deployer a `env.yml` f
156156
The file should be structured like this:
157157

158158
```yaml
159-
version: '2.3'
160159
services:
161160
terraform:
162161
environment:

docs/howto/system_testing.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ the log files from your package's integration service must be written to a volum
7676
the following definition in it's integration service's `docker-compose.yml` file.
7777

7878
```yaml
79-
version: '2.3'
8079
services:
8180
apache:
8281
# Other properties such as build, ports, etc.
@@ -95,7 +94,6 @@ For example docker images for MySQL include a volume for the data directory
9594
tests are executed, a volume can be added to the `docker-compose.yml`:
9695

9796
```yaml
98-
version: '2.3'
9997
services:
10098
mysql:
10199
# Other properties such as build, ports, etc.
@@ -118,7 +116,6 @@ This is useful if you need different capabilities than the provided by the
118116

119117
`custom-agent.yml`
120118
```yaml
121-
version: '2.3'
122119
services:
123120
docker-custom-agent:
124121
pid: host
@@ -131,7 +128,6 @@ services:
131128
This will result in an agent configuration such as:
132129

133130
```yaml
134-
version: '2.3'
135131
services:
136132
docker-custom-agent:
137133
hostname: docker-custom-agent
@@ -196,7 +192,6 @@ RUN apt-get update && apt-get -y install \
196192
```
197193
An example for `custom-agent.yml` in multi-service setup is as below
198194
```yaml
199-
version: '2.3'
200195
services:
201196
docker-custom-agent:
202197
build:
@@ -328,7 +323,6 @@ To use environment variables within the Terraform service deployer a `env.yml` f
328323
The file should be structured like this:
329324

330325
```yaml
331-
version: '2.3'
332326
services:
333327
terraform:
334328
environment:

go.mod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ require (
3939
gotest.tools/gotestsum v1.11.0
4040
helm.sh/helm/v3 v3.14.4
4141
honnef.co/go/tools v0.4.7
42-
k8s.io/apimachinery v0.29.3
43-
k8s.io/cli-runtime v0.29.3
44-
k8s.io/client-go v0.29.3
42+
k8s.io/apimachinery v0.30.0
43+
k8s.io/cli-runtime v0.30.0
44+
k8s.io/client-go v0.30.0
4545
)
4646

4747
require (
@@ -77,7 +77,7 @@ require (
7777
github.com/fsnotify/fsnotify v1.7.0 // indirect
7878
github.com/go-errors/errors v1.4.2 // indirect
7979
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
80-
github.com/go-logr/logr v1.3.0 // indirect
80+
github.com/go-logr/logr v1.4.1 // indirect
8181
github.com/go-ole/go-ole v1.2.6 // indirect
8282
github.com/go-openapi/errors v0.20.3 // indirect
8383
github.com/go-openapi/jsonpointer v0.19.6 // indirect
@@ -171,11 +171,11 @@ require (
171171
gopkg.in/inf.v0 v0.9.1 // indirect
172172
gopkg.in/warnings.v0 v0.1.2 // indirect
173173
gopkg.in/yaml.v2 v2.4.0 // indirect
174-
k8s.io/api v0.29.3 // indirect
174+
k8s.io/api v0.30.0 // indirect
175175
k8s.io/apiextensions-apiserver v0.29.0 // indirect
176176
k8s.io/component-base v0.29.0 // indirect
177-
k8s.io/klog/v2 v2.110.1 // indirect
178-
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
177+
k8s.io/klog/v2 v2.120.1 // indirect
178+
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
179179
k8s.io/kubectl v0.29.0 // indirect
180180
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
181181
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect

go.sum

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMj
139139
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII=
140140
github.com/go-git/go-git/v5 v5.12.0 h1:7Md+ndsjrzZxbddRDZjF14qK+NN56sy6wkqaVrjZtys=
141141
github.com/go-git/go-git/v5 v5.12.0/go.mod h1:FTM9VKtnI2m65hNI/TenDDDnUf2Q9FHnXYjuz9i5OEY=
142-
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
143-
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
142+
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
143+
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
144144
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
145145
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
146146
github.com/go-openapi/errors v0.20.2/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M=
@@ -334,10 +334,10 @@ github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4=
334334
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
335335
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
336336
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
337-
github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4=
338-
github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o=
339-
github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg=
340-
github.com/onsi/gomega v1.29.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
337+
github.com/onsi/ginkgo/v2 v2.15.0 h1:79HwNRBAZHOEwrczrgSOPy+eFTTlIGELKy5as+ClttY=
338+
github.com/onsi/ginkgo/v2 v2.15.0/go.mod h1:HlxMHtYF57y6Dpf+mc5529KKmSq9h2FpCF+/ZkwUxKM=
339+
github.com/onsi/gomega v1.31.0 h1:54UJxxj6cPInHS3a35wm6BK/F9nHYueZ1NVujHDrnXE=
340+
github.com/onsi/gomega v1.31.0/go.mod h1:DW9aCi7U6Yi40wNVAvT6kzFnEVEI5n3DloYBiKiT6zk=
341341
github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU=
342342
github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w=
343343
github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI=
@@ -636,22 +636,22 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh
636636
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
637637
honnef.co/go/tools v0.4.7 h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs=
638638
honnef.co/go/tools v0.4.7/go.mod h1:+rnGS1THNh8zMwnd2oVOTL9QF6vmfyG6ZXBULae2uc0=
639-
k8s.io/api v0.29.3 h1:2ORfZ7+bGC3YJqGpV0KSDDEVf8hdGQ6A03/50vj8pmw=
640-
k8s.io/api v0.29.3/go.mod h1:y2yg2NTyHUUkIoTC+phinTnEa3KFM6RZ3szxt014a80=
639+
k8s.io/api v0.30.0 h1:siWhRq7cNjy2iHssOB9SCGNCl2spiF1dO3dABqZ8niA=
640+
k8s.io/api v0.30.0/go.mod h1:OPlaYhoHs8EQ1ql0R/TsUgaRPhpKNxIMrKQfWUp8QSE=
641641
k8s.io/apiextensions-apiserver v0.29.0 h1:0VuspFG7Hj+SxyF/Z/2T0uFbI5gb5LRgEyUVE3Q4lV0=
642642
k8s.io/apiextensions-apiserver v0.29.0/go.mod h1:TKmpy3bTS0mr9pylH0nOt/QzQRrW7/h7yLdRForMZwc=
643-
k8s.io/apimachinery v0.29.3 h1:2tbx+5L7RNvqJjn7RIuIKu9XTsIZ9Z5wX2G22XAa5EU=
644-
k8s.io/apimachinery v0.29.3/go.mod h1:hx/S4V2PNW4OMg3WizRrHutyB5la0iCUbZym+W0EQIU=
645-
k8s.io/cli-runtime v0.29.3 h1:r68rephmmytoywkw2MyJ+CxjpasJDQY7AGc3XY2iv1k=
646-
k8s.io/cli-runtime v0.29.3/go.mod h1:aqVUsk86/RhaGJwDhHXH0jcdqBrgdF3bZWk4Z9D4mkM=
647-
k8s.io/client-go v0.29.3 h1:R/zaZbEAxqComZ9FHeQwOh3Y1ZUs7FaHKZdQtIc2WZg=
648-
k8s.io/client-go v0.29.3/go.mod h1:tkDisCvgPfiRpxGnOORfkljmS+UrW+WtXAy2fTvXJB0=
643+
k8s.io/apimachinery v0.30.0 h1:qxVPsyDM5XS96NIh9Oj6LavoVFYff/Pon9cZeDIkHHA=
644+
k8s.io/apimachinery v0.30.0/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc=
645+
k8s.io/cli-runtime v0.30.0 h1:0vn6/XhOvn1RJ2KJOC6IRR2CGqrpT6QQF4+8pYpWQ48=
646+
k8s.io/cli-runtime v0.30.0/go.mod h1:vATpDMATVTMA79sZ0YUCzlMelf6rUjoBzlp+RnoM+cg=
647+
k8s.io/client-go v0.30.0 h1:sB1AGGlhY/o7KCyCEQ0bPWzYDL0pwOZO4vAtTSh/gJQ=
648+
k8s.io/client-go v0.30.0/go.mod h1:g7li5O5256qe6TYdAMyX/otJqMhIiGgTapdLchhmOaY=
649649
k8s.io/component-base v0.29.0 h1:T7rjd5wvLnPBV1vC4zWd/iWRbV8Mdxs+nGaoaFzGw3s=
650650
k8s.io/component-base v0.29.0/go.mod h1:sADonFTQ9Zc9yFLghpDpmNXEdHyQmFIGbiuZbqAXQ1M=
651-
k8s.io/klog/v2 v2.110.1 h1:U/Af64HJf7FcwMcXyKm2RPM22WZzyR7OSpYj5tg3cL0=
652-
k8s.io/klog/v2 v2.110.1/go.mod h1:YGtd1984u+GgbuZ7e08/yBuAfKLSO0+uR1Fhi6ExXjo=
653-
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 h1:aVUu9fTY98ivBPKR9Y5w/AuzbMm96cd3YHRTU83I780=
654-
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA=
651+
k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw=
652+
k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
653+
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag=
654+
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340/go.mod h1:yD4MZYeKMBwQKVht279WycxKyM84kkAx2DPrTXaeb98=
655655
k8s.io/kubectl v0.29.0 h1:Oqi48gXjikDhrBF67AYuZRTcJV4lg2l42GmvsP7FmYI=
656656
k8s.io/kubectl v0.29.0/go.mod h1:0jMjGWIcMIQzmUaMgAzhSELv5WtHo2a8pq67DtviAJs=
657657
k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI=

internal/agentdeployer/_static/docker-agent-base.yml renamed to internal/agentdeployer/_static/docker-agent-base.yml.tmpl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: "2.3"
21
services:
32
elastic-agent:
43
hostname: ${AGENT_HOSTNAME}
@@ -7,6 +6,18 @@ services:
76
test: "elastic-agent status"
87
retries: 180
98
interval: 1s
9+
{{ if ne .pidMode "" }}
10+
pid: {{ .pidMode }}
11+
{{ end }}
12+
{{ if ne .user "" }}
13+
user: {{ .user }}
14+
{{ end }}
15+
{{ if .capabilities }}
16+
cap_add:
17+
{{- range .capabilities }}
18+
- {{ . }}
19+
{{- end }}
20+
{{ end }}
1021
environment:
1122
- FLEET_ENROLL=1
1223
- FLEET_URL=https://fleet-server:8220
@@ -15,4 +26,3 @@ services:
1526
volumes:
1627
- ${SERVICE_LOGS_DIR}:/tmp/service_logs/
1728
- ${LOCAL_CA_CERT}:/etc/ssl/certs/elastic-package.pem
18-

internal/agentdeployer/agent.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"fmt"
1111
"os"
1212
"path/filepath"
13+
"text/template"
1314
"time"
1415

1516
"github.com/elastic/elastic-package/internal/compose"
@@ -24,13 +25,12 @@ import (
2425

2526
const (
2627
dockerTestAgentNamePrefix = "elastic-agent"
27-
dockerTestgentDir = "docker_test_agent"
2828
dockerTestAgentDockerCompose = "docker-agent-base.yml"
2929
defaultAgentPolicyName = "Elastic-Agent (elastic-package)"
3030
)
3131

32-
//go:embed _static/docker-agent-base.yml
33-
var dockerAgentDockerComposeContent []byte
32+
//go:embed _static/docker-agent-base.yml.tmpl
33+
var dockerTestAgentDockerComposeTemplate string
3434

3535
// CustomAgentDeployer knows how to deploy a custom elastic-agent defined via
3636
// a Docker Compose file.
@@ -112,7 +112,7 @@ func (d *DockerComposeAgentDeployer) SetUp(ctx context.Context, agentInfo AgentI
112112
fmt.Sprintf("%s=%s", agentHostnameEnv, d.agentHostname()),
113113
)
114114

115-
configDir, err := d.installDockerfile()
115+
configDir, err := d.installDockerfile(agentInfo)
116116
if err != nil {
117117
return nil, fmt.Errorf("could not create resources for custom agent: %w", err)
118118
}
@@ -236,17 +236,29 @@ func (d *DockerComposeAgentDeployer) agentName() string {
236236

237237
// installDockerfile creates the files needed to run the custom elastic agent and returns
238238
// the directory with these files.
239-
func (d *DockerComposeAgentDeployer) installDockerfile() (string, error) {
239+
func (d *DockerComposeAgentDeployer) installDockerfile(agentInfo AgentInfo) (string, error) {
240240
customAgentDir := filepath.Join(d.profile.ProfilePath, fmt.Sprintf("agent-%s", d.agentName()))
241241
err := os.MkdirAll(customAgentDir, 0755)
242242
if err != nil {
243243
return "", fmt.Errorf("failed to create directory for custom agent files: %w", err)
244244
}
245245

246246
customAgentDockerfile := filepath.Join(customAgentDir, dockerTestAgentDockerCompose)
247-
err = os.WriteFile(customAgentDockerfile, dockerAgentDockerComposeContent, 0644)
247+
file, err := os.Create(customAgentDockerfile)
248248
if err != nil {
249-
return "", fmt.Errorf("failed to create docker compose file for custom agent: %w", err)
249+
return "", fmt.Errorf("failed to create file (name %s): %w", customAgentDockerfile, err)
250+
}
251+
defer file.Close()
252+
253+
tmpl := template.Must(template.New(dockerTestAgentDockerCompose).Parse(dockerTestAgentDockerComposeTemplate))
254+
err = tmpl.Execute(file, map[string]any{
255+
"user": agentInfo.Agent.User,
256+
"capabilities": agentInfo.Agent.LinuxCapabilities,
257+
"runtime": agentInfo.Agent.Runtime,
258+
"pidMode": agentInfo.Agent.PidMode,
259+
})
260+
if err != nil {
261+
return "", fmt.Errorf("failed to create contents of the docker-compose file %q: %w", customAgentDockerfile, err)
250262
}
251263

252264
return customAgentDir, nil

0 commit comments

Comments
 (0)