Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .buildkite/scripts/buildkite-k8s-integration-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,14 @@ EOF
pod_logs_base="${PWD}/build/${fully_qualified_group_name}.pod_logs_dump"

set +e
K8S_TESTS_POD_LOGS_BASE="${pod_logs_base}" AGENT_IMAGE="${image}" DOCKER_VARIANT="${variant}" gotestsum --hide-summary=skipped --format testname --no-color -f standard-quiet --junitfile-hide-skipped-tests --junitfile "${outputXML}" --jsonfile "${outputJSON}" -- -tags kubernetes,integration -test.shuffle on -test.timeout 2h0m0s github.com/elastic/elastic-agent/testing/integration -v -args -integration.groups="${group_name}" -integration.sudo="false"
K8S_TESTS_POD_LOGS_BASE="${pod_logs_base}" AGENT_IMAGE="${image}" DOCKER_VARIANT="${variant}" gotestsum --hide-summary=skipped --format testname --no-color -f standard-quiet --junitfile-hide-skipped-tests --junitfile "${outputXML}" --jsonfile "${outputJSON}" -- -tags kubernetes,integration -test.shuffle on -test.timeout 2h0m0s github.com/elastic/elastic-agent/testing/integration/k8s -v -args -integration.groups="${group_name}" -integration.sudo="false"
exit_status=$?
set -e

if [[ $exit_status -ne 0 ]]; then
echo "^^^ +++"
fi

if [[ $TESTS_EXIT_STATUS -eq 0 && $exit_status -ne 0 ]]; then
TESTS_EXIT_STATUS=$exit_status
fi
Expand Down
2 changes: 1 addition & 1 deletion .buildkite/scripts/steps/k8s-extended-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ else
fi

SNAPSHOT=true EXTERNAL=true PACKAGES=docker mage -v package
TEST_INTEG_CLEAN_ON_EXIT=true INSTANCE_PROVISIONER=kind STACK_PROVISIONER=stateful SNAPSHOT=true mage integration:kubernetesMatrix
TEST_INTEG_CLEAN_ON_EXIT=true INSTANCE_PROVISIONER=kind STACK_PROVISIONER=stateful SNAPSHOT=true mage integration:testKubernetesMatrix
TESTS_EXIT_STATUS=$?
set -e

Expand Down
4 changes: 2 additions & 2 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83258,11 +83258,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

--------------------------------------------------------------------------------
Dependency : sigs.k8s.io/structured-merge-diff/v4
Version: v4.4.2
Version: v4.4.3
Licence type (autodetected): Apache-2.0
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/sigs.k8s.io/structured-merge-diff/[email protected].2/LICENSE:
Contents of probable licence file $GOMODCACHE/sigs.k8s.io/structured-merge-diff/[email protected].3/LICENSE:

Apache License
Version 2.0, January 2004
Expand Down
8 changes: 4 additions & 4 deletions docs/test-framework-dev-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ The test are run with mage using the `integration` namespace:

- `mage integration:matrix` to run all tests on the complete matrix of supported operating systems and architectures of the Elastic Agent.

- `mage integration:kubernetes` to run kubernetes tests for the default image on the default version of kubernetes (all previous commands will not run any kubernetes tests).
- `mage integration:testKubernetes` to run kubernetes tests for the default image on the default version of kubernetes (all previous commands will not run any kubernetes tests).

- `mage integration:kubernetesMatrix` to run a matrix of kubernetes tests for all image types and supported versions of kubernetes.
- `mage integration:testKubernetesMatrix` to run a matrix of kubernetes tests for all image types and supported versions of kubernetes.

#### Selecting specific platform

Expand All @@ -94,7 +94,7 @@ between, and it can be very specific or not very specific.
- `TEST_PLATFORMS="linux/amd64/ubuntu/20.04 mage integration:test` to execute tests only on Ubuntu 20.04 ARM64.
- `TEST_PLATFORMS="windows/amd64/2022 mage integration:test` to execute tests only on Windows Server 2022.
- `TEST_PLATFORMS="linux/amd64 windows/amd64/2022 mage integration:test` to execute tests on Linux AMD64 and Windows Server 2022.
- `TEST_PLATFORMS="kubernetes/arm64/1.31.0/wolfi" mage integration:kubernetes` to execute kubernetes tests on Kubernetes version 1.31.0 with wolfi docker variant.
- `INSTANCE_PROVISIONER="kind" TEST_PLATFORMS="kubernetes/arm64/1.33.0/wolfi" mage integration:testKubernetes` to execute kubernetes tests on Kubernetes version 1.33.0 with wolfi docker variant under kind cluster.

> **_NOTE:_** This only filters down the tests based on the platform. It will not execute a tests on a platform unless
> the test defines as supporting it.
Expand Down Expand Up @@ -417,7 +417,7 @@ not cause already provisioned resources to be replaced with an instance created
### Kind Instance Provisioner
Use only when running Kubernetes tests. Uses local installed kind to create Kubernetes clusters on the fly.

- `INSTANCE_PROVISIONER="kind" mage integration:kubernetes`
- `INSTANCE_PROVISIONER="kind" mage integration:testKubernetes`

## Troubleshooting Tips

Expand Down
8 changes: 3 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ require (
k8s.io/client-go v0.32.3
kernel.org/pub/linux/libs/security/libcap/cap v1.2.70
sigs.k8s.io/e2e-framework v0.4.0
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3
sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3
sigs.k8s.io/kustomize/api v0.18.0
)

require (
Expand Down Expand Up @@ -384,7 +383,6 @@ require (
github.com/huandu/xstrings v1.5.0 // indirect
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/icholy/digest v0.1.22 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/ionos-cloud/sdk-go/v6 v6.2.1 // indirect
github.com/jaegertracing/jaeger v1.66.0 // indirect
Expand Down Expand Up @@ -621,7 +619,6 @@ require (
go.opentelemetry.io/otel/sdk/metric v1.34.0 // indirect
go.opentelemetry.io/otel/trace v1.34.0 // indirect
go.opentelemetry.io/proto/otlp v1.5.0 // indirect
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/oauth2 v0.27.0 // indirect
Expand All @@ -646,7 +643,8 @@ require (
oras.land/oras-go v1.2.5 // indirect
sigs.k8s.io/controller-runtime v0.20.4 // indirect
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
sigs.k8s.io/kustomize/kyaml v0.18.1 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.3 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)

Expand Down
17 changes: 6 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -879,8 +879,6 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:
github.com/icholy/digest v0.1.22 h1:dRIwCjtAcXch57ei+F0HSb5hmprL873+q7PoVojdMzM=
github.com/icholy/digest v0.1.22/go.mod h1:uLAeDdWKIWNFMH0wqbwchbTQOmJWhzSnL7zmqSPqEEc=
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/ionos-cloud/sdk-go/v6 v6.2.1 h1:mxxN+frNVmbFrmmFfXnBC3g2USYJrl6mc1LW2iNYbFY=
Expand Down Expand Up @@ -1791,8 +1789,6 @@ go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC
go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE=
go.opentelemetry.io/proto/otlp v1.5.0 h1:xJvq7gMzB31/d406fB8U5CBdyQGw4P399D1aQWU/3i4=
go.opentelemetry.io/proto/otlp v1.5.0/go.mod h1:keN8WnHxOy8PG0rQZjJJ5A2ebUoafqWp0eVQ4yIXvJ4=
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca h1:VdD38733bfYv5tUZwEIskMM93VanwNIi5bIKnDrJdEY=
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca/go.mod h1:jxU+3+j+71eXOW14274+SmmuW82qJzl6iZSeqEtTGds=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
Expand Down Expand Up @@ -2039,7 +2035,6 @@ golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXR
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
Expand Down Expand Up @@ -2330,14 +2325,14 @@ sigs.k8s.io/e2e-framework v0.4.0 h1:4yYmFDNNoTnazqmZJXQ6dlQF1vrnDbutmxlyvBpC5rY=
sigs.k8s.io/e2e-framework v0.4.0/go.mod h1:JilFQPF1OL1728ABhMlf9huse7h+uBJDXl9YeTs49A8=
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 h1:/Rv+M11QRah1itp8VhT6HoVx1Ray9eB4DBr+K+/sCJ8=
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3/go.mod h1:18nIHnGi6636UCz6m8i4DhaJ65T6EruyzmoQqI2BVDo=
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3 h1:XX3Ajgzov2RKUdc5jW3t5jwY7Bo7dcRm+tFxT+NfgY0=
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3/go.mod h1:9n16EZKMhXBNSiUC5kSdFQJkdH3zbxS/JoO619G1VAY=
sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3 h1:W6cLQc5pnqM7vh3b7HvGNfXrJ/xL6BDMS0v1V/HHg5U=
sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3/go.mod h1:JWP1Fj0VWGHyw3YUPjXSQnRnrwezrZSrApfX5S0nIag=
sigs.k8s.io/kustomize/api v0.18.0 h1:hTzp67k+3NEVInwz5BHyzc9rGxIauoXferXyjv5lWPo=
sigs.k8s.io/kustomize/api v0.18.0/go.mod h1:f8isXnX+8b+SGLHQ6yO4JG1rdkZlvhaCf/uZbLVMb0U=
sigs.k8s.io/kustomize/kyaml v0.18.1 h1:WvBo56Wzw3fjS+7vBjN6TeivvpbW9GmRaWZ9CIVmt4E=
sigs.k8s.io/kustomize/kyaml v0.18.1/go.mod h1:C3L2BFVU1jgcddNBE1TxuVLgS46TjObMwW5FT9FcjYo=
sigs.k8s.io/structured-merge-diff/v4 v4.0.2/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw=
sigs.k8s.io/structured-merge-diff/v4 v4.1.0/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw=
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 h1:MdmvkGuXi/8io6ixD5wud3vOLwc1rj0aNqRlpuvjmwA=
sigs.k8s.io/structured-merge-diff/v4 v4.4.2/go.mod h1:N8f93tFZh9U6vpxwRArLiikrE5/2tiu1w1AGfACIGE4=
sigs.k8s.io/structured-merge-diff/v4 v4.4.3 h1:sCP7Vv3xx/CWIuTPVN38lUPx0uw0lcLfzaiDa8Ja01A=
sigs.k8s.io/structured-merge-diff/v4 v4.4.3/go.mod h1:N8f93tFZh9U6vpxwRArLiikrE5/2tiu1w1AGfACIGE4=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
19 changes: 10 additions & 9 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -1993,6 +1993,7 @@ func (Integration) Check() error {
define.ValidateDir("testing/integration"),
define.ValidateDir("testing/integration/serverless"),
define.ValidateDir("testing/integration/leak"),
define.ValidateDir("testing/integration/k8s"),
)
}

Expand Down Expand Up @@ -2073,34 +2074,34 @@ func (Integration) TestServerless(ctx context.Context) error {
return integRunner(ctx, "testing/integration/serverless", false, "")
}

// Kubernetes runs kubernetes integration tests
func (Integration) Kubernetes(ctx context.Context) error {
// TestKubernetes runs kubernetes integration tests
func (Integration) TestKubernetes(ctx context.Context) error {
// invoke integration tests
if err := os.Setenv("TEST_GROUPS", "kubernetes"); err != nil {
return err
}

return integRunner(ctx, "testing/integration", false, "")
return integRunner(ctx, "testing/integration/k8s", false, "")
}

// KubernetesSingle runs a single Kubernetes integration test
func (Integration) KubernetesSingle(ctx context.Context, testName string) error {
// TestKubernetesSingle runs single k8s integration test
func (Integration) TestKubernetesSingle(ctx context.Context, testName string) error {
// invoke integration tests
if err := os.Setenv("TEST_GROUPS", "kubernetes"); err != nil {
return err
}

return integRunner(ctx, "testing/integration", false, testName)
return integRunner(ctx, "testing/integration/k8s", false, testName)
}

// KubernetesMatrix runs a matrix of kubernetes integration tests
func (Integration) KubernetesMatrix(ctx context.Context) error {
// TestKubernetesMatrix runs a matrix of kubernetes integration tests
func (Integration) TestKubernetesMatrix(ctx context.Context) error {
// invoke integration tests
if err := os.Setenv("TEST_GROUPS", "kubernetes"); err != nil {
return err
}

return integRunner(ctx, "testing/integration", true, "")
return integRunner(ctx, "testing/integration/k8s", true, "")
}

// UpdateVersions runs an update on the `.agent-versions.yml` fetching
Expand Down
11 changes: 9 additions & 2 deletions pkg/testing/define/define.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var osInfo *types.OSInfo
var osInfoErr error
var osInfoOnce sync.Once
var noSpecialCharsRegexp = regexp.MustCompile("[^a-zA-Z0-9]+")
var kubernetesSupported = false

// Require defines what this test requires for it to be run by the test runner.
//
Expand All @@ -46,6 +47,12 @@ func Require(t *testing.T, req Requirements) *Info {
return defineAction(t, req)
}

// SetKubernetesSupported sets the kubernetesSupported flag to true
// to allow kubernetes tests to be run.
func SetKubernetesSupported() {
kubernetesSupported = true
}

type Info struct {
// ESClient is the elasticsearch client to communicate with elasticsearch.
// This is only present if you say a cloud is required in the `define.Require`.
Expand Down Expand Up @@ -139,7 +146,7 @@ func findProjectRoot() (string, error) {
}
}

func runOrSkip(t *testing.T, req Requirements, local bool, kubernetes bool) *Info {
func runOrSkip(t *testing.T, req Requirements, local bool) *Info {
// always validate requirement is valid
if err := req.Validate(); err != nil {
panic(fmt.Sprintf("test %s has invalid requirements: %s", t.Name(), err))
Expand All @@ -165,7 +172,7 @@ func runOrSkip(t *testing.T, req Requirements, local bool, kubernetes bool) *Inf
return nil
}
for _, o := range req.OS {
if o.Type == Kubernetes && !kubernetes {
if o.Type == Kubernetes && !kubernetesSupported {
t.Skip("test requires kubernetes")
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/testing/define/define_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// or more contributor license agreements. Licensed under the Elastic License 2.0;
// you may not use this file except in compliance with the Elastic License 2.0.

//go:build !define && !local && !kubernetes
//go:build !define && !local

package define

Expand All @@ -11,5 +11,5 @@ import (
)

func defineAction(t *testing.T, req Requirements) *Info {
return runOrSkip(t, req, false, false)
return runOrSkip(t, req, false)
}
15 changes: 0 additions & 15 deletions pkg/testing/define/define_kubernetes.go

This file was deleted.

4 changes: 2 additions & 2 deletions pkg/testing/define/define_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// or more contributor license agreements. Licensed under the Elastic License 2.0;
// you may not use this file except in compliance with the Elastic License 2.0.

//go:build local && !define && !kubernetes
//go:build local && !define

package define

Expand All @@ -11,5 +11,5 @@ import (
)

func defineAction(t *testing.T, req Requirements) *Info {
return runOrSkip(t, req, true, false)
return runOrSkip(t, req, true)
}
53 changes: 53 additions & 0 deletions testing/integration/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License 2.0;
// you may not use this file except in compliance with the Elastic License 2.0.

//go:build integration

package integration

import (
"fmt"
"net/url"
"os"
"testing"
"time"

"github.com/stretchr/testify/require"

"github.com/elastic/elastic-agent-libs/testing/estools"
)

func GetESHost() (string, error) {
fixedESHost := os.Getenv("ELASTICSEARCH_HOST")
parsedES, err := url.Parse(fixedESHost)
if err != nil {
return "", err
}
if parsedES.Port() == "" {
fixedESHost = fmt.Sprintf("%s:443", fixedESHost)
}
return fixedESHost, nil
}

// FindESDocs runs `findFn` until at least one document is returned and there is no error
func FindESDocs(t *testing.T, findFn func() (estools.Documents, error)) estools.Documents {
var docs estools.Documents
require.Eventually(
t,
func() bool {
var err error
docs, err = findFn()
if err != nil {
t.Logf("got an error querying ES, retrying. Error: %s", err)
return false
}

return docs.Hits.Total.Value != 0
},
3*time.Minute,
15*time.Second,
)

return docs
}
Loading