Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Commit 5ba4dca

Browse files
jsorianomdelapenyaadam-stokes
authored andcommitted
Kubernetes autodiscover suite (#1064)
Adds a new suite to test Kubernetes autodiscover features. Reproduces some issues with short-living containers affecting Beats before 7.13 and for what we didn't have tests coverage. It allows to define the scenarios using the gherkin language for feature files. Scenarios use templates that are mostly kubernetes manifests. A simple system of options is included to allow to select configuration blocks in these templates. It uses kubectl to interact with a kubernetes cluster. If no cluster is available, it starts one with kind. Each scenario is executed in a different namespace, namespace is destroyed after the scenario is run to clean all created resources. It currently works only with loads in a single namespace, in a single node, this is enough to test many autodiscover cases, but it could be extended in the future to cover multi-node or multi-namespace scenarios. Co-authored-by: Manuel de la Peña <mdelapenya@gmail.com> Co-authored-by: Adam Stokes <51892+adam-stokes@users.noreply.github.com> (cherry picked from commit c52395d)
1 parent 98c3d81 commit 5ba4dca

26 files changed

+1528
-19
lines changed

.ci/.e2e-tests.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,13 @@ SUITES:
6262
tags: "integrations && redisenterprise"
6363
- name: "vSphere"
6464
tags: "integrations && vsphere"
65+
- suite: "kubernetes-autodiscover"
66+
platforms:
67+
- "ubuntu-18.04"
68+
scenarios:
69+
- name: "kubernetes autodiscover with filebeat"
70+
tags: "kubernetes-autodiscover && filebeat"
71+
- name: "kubernetes autodiscover with heartbeat"
72+
tags: "kubernetes-autodiscover && heartbeat"
73+
- name: "kubernetes autodiscover with metricbeat"
74+
tags: "kubernetes-autodiscover && metricbeat"

.ci/Jenkinsfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ pipeline {
5050
string(name: 'STACK_VERSION', defaultValue: '7.x-SNAPSHOT', description: 'SemVer version of the stack to be used for the tests.')
5151
string(name: 'HELM_CHART_VERSION', defaultValue: '7.11.2', description: 'SemVer version of Helm chart to be used.')
5252
string(name: 'HELM_VERSION', defaultValue: '3.5.2', description: 'SemVer version of Helm to be used.')
53-
string(name: 'HELM_KIND_VERSION', defaultValue: '0.10.0', description: 'SemVer version of Kind to be used.')
54-
string(name: 'HELM_KUBERNETES_VERSION', defaultValue: '1.18.2', description: 'SemVer version of Kubernetes to be used.')
53+
string(name: 'KIND_VERSION', defaultValue: '0.10.0', description: 'SemVer version of Kind to be used.')
54+
string(name: 'KUBERNETES_VERSION', defaultValue: '1.18.2', description: 'SemVer version of Kubernetes to be used.')
5555
string(name: 'GITHUB_CHECK_NAME', defaultValue: '', description: 'Name of the GitHub check to be updated. Only if this build is triggered from another parent stream.')
5656
string(name: 'GITHUB_CHECK_REPO', defaultValue: '', description: 'Name of the GitHub repo to be updated. Only if this build is triggered from another parent stream.')
5757
string(name: 'GITHUB_CHECK_SHA1', defaultValue: '', description: 'Git SHA for the Beats upstream project (branch or PR)')
@@ -76,8 +76,8 @@ pipeline {
7676
FORCE_SKIP_PRESUBMIT = "${params.forceSkipPresubmit}"
7777
HELM_CHART_VERSION = "${params.HELM_CHART_VERSION.trim()}"
7878
HELM_VERSION = "${params.HELM_VERSION.trim()}"
79-
HELM_KIND_VERSION = "${params.HELM_KIND_VERSION.trim()}"
80-
HELM_KUBERNETES_VERSION = "${params.HELM_KUBERNETES_VERSION.trim()}"
79+
KIND_VERSION = "${params.KIND_VERSION.trim()}"
80+
KUBERNETES_VERSION = "${params.KUBERNETES_VERSION.trim()}"
8181
LOG_LEVEL = "${params.LOG_LEVEL.trim()}"
8282
TIMEOUT_FACTOR = "${params.TIMEOUT_FACTOR.trim()}"
8383
}

.ci/scripts/install-helm-test-dependencies.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,29 @@ set -euxo pipefail
1010
#
1111
# Parameters:
1212
# - HELM_VERSION - that's the Helm version which will be installed and enabled.
13-
# - HELM_KIND_VERSION - that's the Kind version which will be installed and enabled.
14-
# - HELM_KUBERNETES_VERSION - that's the Kubernetes version which will be installed and enabled.
13+
# - KIND_VERSION - that's the Kind version which will be installed and enabled.
14+
# - KUBERNETES_VERSION - that's the Kubernetes version which will be installed and enabled.
1515
#
1616

1717
MSG="parameter missing."
1818
HOME=${HOME:?$MSG}
1919

2020
HELM_VERSION="${HELM_VERSION:-"3.5.2"}"
2121
HELM_TAR_GZ_FILE="helm-v${HELM_VERSION}-linux-amd64.tar.gz"
22-
HELM_KIND_VERSION="v${HELM_KIND_VERSION:-"0.10.0"}"
23-
HELM_KUBERNETES_VERSION="${HELM_KUBERNETES_VERSION:-"1.18.2"}"
22+
KIND_VERSION="v${KIND_VERSION:-"0.10.0"}"
23+
KUBERNETES_VERSION="${KUBERNETES_VERSION:-"1.18.2"}"
2424

2525
HELM_CMD="${HOME}/bin/helm"
2626
KBC_CMD="${HOME}/bin/kubectl"
2727

2828
# Install kind as a Go binary
29-
GO111MODULE="on" go get sigs.k8s.io/kind@${HELM_KIND_VERSION}
29+
GO111MODULE="on" go get sigs.k8s.io/kind@${KIND_VERSION}
3030

3131
mkdir -p "${HOME}/bin" "${HOME}/.kube"
3232
touch "${HOME}/.kube/config"
3333

3434
# Install kubectl
35-
curl -sSLo "${KBC_CMD}" "https://storage.googleapis.com/kubernetes-release/release/v${HELM_KUBERNETES_VERSION}/bin/linux/amd64/kubectl"
35+
curl -sSLo "${KBC_CMD}" "https://storage.googleapis.com/kubernetes-release/release/v${KUBERNETES_VERSION}/bin/linux/amd64/kubectl"
3636
chmod +x "${KBC_CMD}"
3737
${KBC_CMD} version --client
3838

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
## Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4+
## or more contributor license agreements. Licensed under the Elastic License;
5+
## you may not use this file except in compliance with the Elastic License.
6+
7+
set -euxo pipefail
8+
#
9+
# Install the dependencies using the install and test make goals.
10+
#
11+
# Parameters:
12+
# - KIND_VERSION - that's the Kind version which will be installed and enabled.
13+
# - KUBERNETES_VERSION - that's the Kubernetes version which will be installed and enabled.
14+
#
15+
16+
MSG="parameter missing."
17+
HOME=${HOME:?$MSG}
18+
19+
KIND_VERSION="v${KIND_VERSION:-"0.10.0"}"
20+
KUBERNETES_VERSION="${KUBERNETES_VERSION:-"1.18.2"}"
21+
22+
KUBECTL_CMD="${HOME}/bin/kubectl"
23+
24+
# Install kind as a Go binary
25+
GO111MODULE="on" go get sigs.k8s.io/kind@${KIND_VERSION}
26+
27+
mkdir -p "${HOME}/bin"
28+
29+
# Install kubectl
30+
curl -sSLo "${KUBECTL_CMD}" "https://storage.googleapis.com/kubernetes-release/release/v${KUBERNETES_VERSION}/bin/linux/amd64/kubectl"
31+
chmod +x "${KUBECTL_CMD}"
32+
${KUBECTL_CMD} version --client

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ repos:
4545
- id: check-jjbb
4646
- id: check-gherkin-lint
4747
args: [
48-
"--disable", "AvoidOutlineForSingleExample,TooClumsy,TooLongStep,TooManyDifferentTags,TooManySteps",
48+
"--disable", "AvoidOutlineForSingleExample,TooClumsy,TooLongStep,TooManyDifferentTags,TooManySteps,UseBackground",
4949
"e2e/_suites/**/*.feature",
5050
]

cli/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func Init() {
128128
"docker",
129129
"docker-compose",
130130
}
131-
shell.CheckInstalledSoftware(binaries)
131+
shell.CheckInstalledSoftware(binaries...)
132132

133133
InitConfig()
134134
}

e2e/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ functional-test: install-godog
8585

8686
.PHONY: lint
8787
lint:
88-
@docker run -t --rm -v $(PWD):/src -w /src gherkin/lint **/*.feature --disable AvoidOutlineForSingleExample,TooClumsy,TooManySteps,TooManyDifferentTags,TooLongStep
88+
@docker run -t --rm -v $(PWD):/src -w /src gherkin/lint **/*.feature --disable AvoidOutlineForSingleExample,TooClumsy,TooManySteps,TooManyDifferentTags,TooLongStep,UseBackground
8989

9090
## Test examples
9191

e2e/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,13 @@ We are going to enumerate the variables that will affect the product versions us
128128
#### Helm charts
129129
- `HELM_CHART_VERSION`. Set this environment variable to the proper version of the Helm charts to be used in the current execution. Default: See https://github.com/elastic/e2e-testing/blob/0446248bae1ff604219735998841a21a7576bfdd/.ci/Jenkinsfile#L43
130130
- `HELM_VERSION`. Set this environment variable to the proper version of Helm to be used in the current execution. Default: See https://github.com/elastic/e2e-testing/blob/0446248bae1ff604219735998841a21a7576bfdd/.ci/Jenkinsfile#L44
131-
- `HELM_KIND_VERSION`. Set this environment variable to the proper version of Kind (Kubernetes in Docker) to be used in the current execution. Default: See https://github.com/elastic/e2e-testing/blob/0446248bae1ff604219735998841a21a7576bfdd/.ci/Jenkinsfile#L45
132-
- `HELM_KUBERNETES_VERSION`. Set this environment variable to the proper version of Kubernetes to be used in the current execution. Default: See https://github.com/elastic/e2e-testing/blob/0446248bae1ff604219735998841a21a7576bfdd/.ci/Jenkinsfile#L46
131+
- `KIND_VERSION`. Set this environment variable to the proper version of Kind (Kubernetes in Docker) to be used in the current execution. Default: See https://github.com/elastic/e2e-testing/blob/0446248bae1ff604219735998841a21a7576bfdd/.ci/Jenkinsfile#L45
132+
- `KUBERNETES_VERSION`. Set this environment variable to the proper version of Kubernetes to be used in the current execution. Default: See https://github.com/elastic/e2e-testing/blob/0446248bae1ff604219735998841a21a7576bfdd/.ci/Jenkinsfile#L46
133+
134+
#### Kubernetes autodiscover charts
135+
- `BEAT_VERSION`. Set this environment variable to the proper version of the Metricbeat to be used in the current execution. Default: See https://github.com/elastic/e2e-testing/blob/70b1d3ddaf39567aeb4c322054b93ad7ce53e825/.ci/Jenkinsfile#L44
136+
- `KIND_VERSION`. Set this environment variable to the proper version of Kind (Kubernetes in Docker) to be used in the current execution. Default: See https://github.com/elastic/e2e-testing/blob/0446248bae1ff604219735998841a21a7576bfdd/.ci/Jenkinsfile#L45
137+
- `KUBERNETES_VERSION`. Set this environment variable to the proper version of Kubernetes to be used in the current execution. Default: See https://github.com/elastic/e2e-testing/blob/0446248bae1ff604219735998841a21a7576bfdd/.ci/Jenkinsfile#L46
133138

134139
#### Metricbeat
135140
- `BEAT_VERSION`. Set this environment variable to the proper version of the Metricbeat to be used in the current execution. Default: See https://github.com/elastic/e2e-testing/blob/70b1d3ddaf39567aeb4c322054b93ad7ce53e825/.ci/Jenkinsfile#L44

e2e/_suites/helm/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ This is an example of the optional configuration:
3535
# Depending on the versions used,
3636
export HELM_VERSION="3.5.2" # Helm version: for Helm v2.x.x we have to initialise Tiller right after the k8s cluster
3737
export HELM_CHART_VERSION="7.11.2" # version of the Elastic's Observability Helm charts
38-
export HELM_KUBERNETES_VERSION="1.18.2" # version of the cluster to be passed to kind
38+
export KUBERNETES_VERSION="1.18.2" # version of the cluster to be passed to kind
3939
```
4040

4141
3. Install dependencies.

e2e/_suites/helm/helm_charts_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func setupSuite() {
7979

8080
helmVersion = shell.GetEnv("HELM_VERSION", helmVersion)
8181
helmChartVersion = shell.GetEnv("HELM_CHART_VERSION", helmChartVersion)
82-
kubernetesVersion = shell.GetEnv("HELM_KUBERNETES_VERSION", kubernetesVersion)
82+
kubernetesVersion = shell.GetEnv("KUBERNETES_VERSION", kubernetesVersion)
8383
timeoutFactor = shell.GetEnvInteger("TIMEOUT_FACTOR", timeoutFactor)
8484

8585
stackVersion = shell.GetEnv("STACK_VERSION", stackVersion)
@@ -751,5 +751,5 @@ func toolsAreInstalled() {
751751
"helm",
752752
}
753753

754-
shell.CheckInstalledSoftware(binaries)
754+
shell.CheckInstalledSoftware(binaries...)
755755
}

0 commit comments

Comments
 (0)