Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick #17656 to 7.x: Run kubernetes integration tests inside of a pod and use kind to setup a kubernetes cluster #18111

Merged
merged 2 commits into from
Apr 30, 2020
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
13 changes: 13 additions & 0 deletions .ci/scripts/install-kind.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -exuo pipefail

MSG="parameter missing."
DEFAULT_HOME="/usr/local"
KIND_VERSION=${KIND_VERSION:?$MSG}
HOME=${HOME:?$DEFAULT_HOME}
KIND_CMD="${HOME}/bin/kind"

mkdir -p "${HOME}/bin"

curl -sSLo "${KIND_CMD}" "https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-linux-amd64"
chmod +x "${KIND_CMD}"
14 changes: 14 additions & 0 deletions .ci/scripts/install-kubectl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -exuo pipefail

MSG="parameter missing."
DEFAULT_HOME="/usr/local"
K8S_VERSION=${K8S_VERSION:?$MSG}
HOME=${HOME:?$DEFAULT_HOME}
KUBECTL_CMD="${HOME}/bin/kubectl"

mkdir -p "${HOME}/bin"

curl -sSLo "${KUBECTL_CMD}" "https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl"
chmod +x "${KUBECTL_CMD}"

13 changes: 0 additions & 13 deletions .ci/scripts/kind-setup.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
#!/usr/bin/env bash
set -exuo pipefail

MSG="parameter missing."
K8S_VERSION=${K8S_VERSION:?$MSG}
HOME=${HOME:?$MSG}
KBC_CMD="${HOME}/bin/kubectl"

mkdir -p "${HOME}/bin"

curl -sSLo "${KBC_CMD}" "https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl"
chmod +x "${KBC_CMD}"

GO111MODULE="on" go get sigs.k8s.io/[email protected]
kind create cluster --image kindest/node:${K8S_VERSION}

export KUBECONFIG="$(kind get kubeconfig-path)"
kubectl cluster-info
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,14 @@ jobs:
go: $TRAVIS_GO_VERSION
stage: test
- os: linux
env: TARGETS="-C metricbeat integration-tests"
before_install: .ci/scripts/travis_has_changes.sh metricbeat libbeat || travis_terminate 0
install:
- .ci/scripts/install-kind.sh
- .ci/scripts/install-kubectl.sh
env:
- TARGETS="-C metricbeat integration-tests"
- K8S_VERSION=v1.17.2
- KIND_VERSION=v0.7.0
go: $TRAVIS_GO_VERSION
stage: test
- os: linux
Expand Down
14 changes: 7 additions & 7 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ pipeline {
}
}
steps {
k8sTest(["v1.16.2","v1.15.3","v1.14.6","v1.13.10","v1.12.10","v1.11.10"])
k8sTest(["v1.18.2","v1.17.2","v1.16.4","v1.15.7","v1.14.10"])
}
}
}
Expand Down Expand Up @@ -806,14 +806,14 @@ def dumpFilteredEnvironment(){
def k8sTest(versions){
versions.each{ v ->
stage("k8s ${v}"){
withEnv(["K8S_VERSION=${v}"]){
withEnv(["K8S_VERSION=${v}", "KIND_VERSION=v0.7.0", "KUBECONFIG=${env.WORKSPACE}/kubecfg"]){
withGithubNotify(context: "K8s ${v}") {
withBeatsEnv(false) {
sh(label: "Install k8s", script: """
eval "\$(gvm use ${GO_VERSION} --format=bash)"
.ci/scripts/kind-setup.sh
""")
sh(label: "Kubernetes Kind",script: "make KUBECONFIG=\"\$(kind get kubeconfig-path)\" -C deploy/kubernetes test")
sh(label: "Install kind", script: ".ci/scripts/install-kind.sh")
sh(label: "Install kubectl", script: ".ci/scripts/install-kubectl.sh")
sh(label: "Integration tests", script: "MODULE=kubernetes make -C metricbeat integration-tests")
sh(label: "Setup kind", script: ".ci/scripts/kind-setup.sh")
sh(label: "Deploy to kubernetes",script: "make -C deploy/kubernetes test")
sh(label: 'Delete cluster', script: 'kind delete cluster')
}
}
Expand Down
9 changes: 9 additions & 0 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,15 @@ License type (autodetected): Apache-2.0
Apache License 2.0


--------------------------------------------------------------------
Dependency: github.com/docker/spdystream
Revision: 449fdfce4d96
License type (autodetected): Apache-2.0
./vendor/github.com/docker/spdystream/LICENSE:
--------------------------------------------------------------------
Apache License 2.0


--------------------------------------------------------------------
Dependency: github.com/dop251/goja
Overwrite: github.com/andrewkroh/goja
Expand Down
14 changes: 13 additions & 1 deletion dev-tools/mage/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,19 @@ func dockerInfo() (*DockerInfo, error) {
// PATH.
func HaveDockerCompose() error {
_, err := exec.LookPath("docker-compose")
return errors.Wrap(err, "docker-compose was not found on the PATH")
if err != nil {
return fmt.Errorf("docker-compose is not available")
}
return nil
}

// HaveKubectl returns an error if kind is not found on the PATH.
func HaveKubectl() error {
_, err := exec.LookPath("kubectl")
if err != nil {
return fmt.Errorf("kubectl is not available")
}
return nil
}

// FindReplace reads a file, performs a find/replace operation, then writes the
Expand Down
53 changes: 34 additions & 19 deletions dev-tools/mage/gotest.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"log"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
"sort"
Expand Down Expand Up @@ -137,33 +138,47 @@ func DefaultTestBinaryArgs() TestBinaryArgs {
// Use RACE_DETECTOR=true to enable the race detector.
// Use MODULE=module to run only tests for `module`.
func GoTestIntegrationForModule(ctx context.Context) error {
return RunIntegTest("goIntegTest", func() error {
module := EnvOr("MODULE", "")
if module != "" {
err := GoTest(ctx, GoTestIntegrationArgsForModule(module))
return errors.Wrapf(err, "integration tests failed for module %s", module)
module := EnvOr("MODULE", "")
modulesFileInfo, err := ioutil.ReadDir("./module")
if err != nil {
return err
}

foundModule := false
failedModules := []string{}
for _, fi := range modulesFileInfo {
if !fi.IsDir() {
continue
}
if module != "" && module != fi.Name() {
continue
}
foundModule = true

modulesFileInfo, err := ioutil.ReadDir("./module")
// Set MODULE because only want that modules tests to run inside the testing environment.
runners, err := NewIntegrationRunners(path.Join("./module", fi.Name()), map[string]string{"MODULE": fi.Name()})
if err != nil {
return err
return errors.Wrapf(err, "test setup failed for module %s", fi.Name())
}

var failed bool
for _, fi := range modulesFileInfo {
if !fi.IsDir() {
continue
}
err = runners.Test("goIntegTest", func() error {
err := GoTest(ctx, GoTestIntegrationArgsForModule(fi.Name()))
if err != nil {
failed = true
return err
}
return nil
})
if err != nil {
// err will already be report to stdout, collect failed module to report at end
failedModules = append(failedModules, fi.Name())
}
if failed {
return errors.New("integration tests failed")
}
return nil
})
}
if module != "" && !foundModule {
return fmt.Errorf("no module %s", module)
}
if len(failedModules) > 0 {
return fmt.Errorf("failed modules: %s", strings.Join(failedModules, ", "))
}
return nil
}

// GoTest invokes "go test" and reports the results to stdout. It returns an
Expand Down
Loading