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

Conversation

blakerouse
Copy link
Contributor

Cherry-pick of PR #17656 to 7.x branch. Original message:

What does this PR do?

Refactors how mage goIntegTest run for metricbeat. Before each module was run inside of a docker container using docker-compose. Now depending on the module it will either run in docker or kubernetes. At the moment only the kubernetes module runs inside of kubernetes.

Each module is determined if it should run inside of docker or inside of kubernetes. If the module has a docker-compose.yml file then it will run in docker, if the module has a kubernetes.yml then it will run inside of kubernetes.

The docker runner stuff is the same so nothing really changes there, but the kubernetes runner is what is new. It works by executing the tests inside of a Pod running inside of the kubernetes.

If KUBECONFIG is defined in the environment then the runner just executes the tests against that defined kubernetes. If its not defined then kind will be used to setup a cluster and run the tests against that cluster.

Running the tests inside of kubernetes is handled by KubeRemote which uses the kubernetes client-go to setup all the requirements to get it running. Below breaks down the steps that are taken to get it running:

  1. Generate a SSH private/public key.
  2. Add public key as secret to kubernetes.
  3. Add service account, cluster role, cluster role binding to give full access to all of kubernetes.
  4. Deploy a Pod with an init container running sshd-rsync and the test executer container that starts once init container exits. The init container exits after the first SSH connection is made and disconnects.
  5. While the init container is running port-forwarding is used to forward the SSH port to the local system.
  6. rsync is ran locally to sync the beats repo to the init container sync directory which was mounted as an emptyDir and shared between the init container and exec container.
  7. Init container exits and the execute container starts the test for the specific module in this case kubernetes.
  8. Then the logs are tailed to the local terminal while the test runner is running.
  9. Once the test is done all the added resources are cleaned up.

Why is it important?

Currently all of the Kubernetes integration tests are skipped, this fixes them so they can actually be ran inside of a real Kubernetes cluster.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Author's Checklist

  • Ensure that Kubernetes integration tests are ran.

How to test this PR locally

MODULE="kubernetes" mage goIntegTest

Related issues

…p a kubernetes cluster (elastic#17656)

* Use kind to bring up a local kubernetes cluster and then run the integration tests against the kind cluster.

* Run mage update.

* Add more tests.

* Fix more tests, install kind in prepare-tests.

* Switch to running kubernetes integration tests inside of Kubernetes.

* Use golang 1.13.9.

* Fix for other beats.

* Run mage fmt.

* Don't run kubernetes integration tests if not inside kubernetes environment.

* Fix metricbeat to use mage and the makefile shim for mage.

* Improve the error message when kind or kubectl is not available.

* Refactor the integration tests into a more module system.

* Fix go vet.

* Setup travis to use kind.

* Run kubernetes integration tests in Jenkins.

* Fix filebeat magefile.

* Fix travis and Jenkins.

* Check requirements of the test runner before actually running the tests.

* Add return on parsebool error.

* Don't return err on missing requirements for tester.

* Run make update.

* Move the kubernetes items to its own module, import that module only by metricbeat.

(cherry picked from commit db29874)
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Apr 29, 2020
@blakerouse blakerouse added the Team:Platforms Label for the Integrations - Platforms team label Apr 29, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/integrations-platforms (Team:Platforms)

@blakerouse blakerouse removed the needs_team Indicates that the issue/PR needs a Team:* label label Apr 29, 2020
@elasticmachine
Copy link
Collaborator

💔 Build Failed

Pipeline View Test View Changes Artifacts preview stats

Expand to view the summary

Build stats

Test stats 🧪

Test Results
Failed 0
Passed 5591
Skipped 843
Total 6434

Steps errors

Expand to view the steps failures

  • Name: Make -C auditbeat testsuite

    • Description: make -C auditbeat testsuite

    • Result: FAILURE

    • Duration: 4 min 56 sec<

    • Start Time: 2020-04-29T21:35:22.473+0000

  • Name: Make -C generator/_templates/metricbeat test

    • Description: make -C generator/_templates/metricbeat test

    • Result: FAILURE

    • Duration: 1 min 50 sec<

    • Start Time: 2020-04-29T21:35:45.818+0000

Log output

Expand to view the last 100 lines of log output

[2020-04-29T22:15:55.256Z] make: Leaving directory '/var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18111/src/github.com/elastic/beats/libbeat'
[2020-04-29T22:15:55.575Z] + script/fix_permissions.sh /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18111
[2020-04-29T22:15:55.575Z] Client: Docker Engine - Community
[2020-04-29T22:15:55.575Z]  Version:           19.03.8
[2020-04-29T22:15:55.575Z]  API version:       1.40
[2020-04-29T22:15:55.575Z]  Go version:        go1.12.17
[2020-04-29T22:15:55.575Z]  Git commit:        afacb8b7f0
[2020-04-29T22:15:55.575Z]  Built:             Wed Mar 11 01:25:58 2020
[2020-04-29T22:15:55.575Z]  OS/Arch:           linux/amd64
[2020-04-29T22:15:55.575Z]  Experimental:      false
[2020-04-29T22:15:55.575Z] 
[2020-04-29T22:15:55.575Z] Server: Docker Engine - Community
[2020-04-29T22:15:55.575Z]  Engine:
[2020-04-29T22:15:55.575Z]   Version:          19.03.8
[2020-04-29T22:15:55.575Z]   API version:      1.40 (minimum version 1.12)
[2020-04-29T22:15:55.575Z]   Go version:       go1.12.17
[2020-04-29T22:15:55.575Z]   Git commit:       afacb8b7f0
[2020-04-29T22:15:55.575Z]   Built:            Wed Mar 11 01:24:30 2020
[2020-04-29T22:15:55.575Z]   OS/Arch:          linux/amd64
[2020-04-29T22:15:55.575Z]   Experimental:     false
[2020-04-29T22:15:55.575Z]  containerd:
[2020-04-29T22:15:55.575Z]   Version:          1.2.13
[2020-04-29T22:15:55.575Z]   GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
[2020-04-29T22:15:55.575Z]  runc:
[2020-04-29T22:15:55.575Z]   Version:          1.0.0-rc10
[2020-04-29T22:15:55.575Z]   GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
[2020-04-29T22:15:55.575Z]  docker-init:
[2020-04-29T22:15:55.575Z]   Version:          0.18.0
[2020-04-29T22:15:55.575Z]   GitCommit:        fec3683
[2020-04-29T22:16:00.929Z] Recording test results
[2020-04-29T22:16:01.595Z] None of the test reports contained any result
[2020-04-29T22:16:01.614Z] Archiving artifacts
[2020-04-29T22:16:01.906Z] java.lang.InterruptedException: no matches found within 10000
[2020-04-29T22:16:01.906Z] 	at hudson.FilePath$ValidateAntFileMask.hasMatch(FilePath.java:2826)
[2020-04-29T22:16:01.906Z] 	at hudson.FilePath$ValidateAntFileMask.invoke(FilePath.java:2705)
[2020-04-29T22:16:01.906Z] 	at hudson.FilePath$ValidateAntFileMask.invoke(FilePath.java:2686)
[2020-04-29T22:16:01.906Z] 	at hudson.FilePath$FileCallableWrapper.call(FilePath.java:3073)
[2020-04-29T22:16:01.906Z] Also:   hudson.remoting.Channel$CallSiteStackTrace: Remote call to JNLP4-connect connection from beats-ci-immutable-ubuntu-1604-1588195524173757336.c.elastic-ci-prod.internal/10.224.2.110:44242
[2020-04-29T22:16:01.906Z] 		at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1788)
[2020-04-29T22:16:01.906Z] 		at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:356)
[2020-04-29T22:16:01.906Z] 		at hudson.remoting.Channel.call(Channel.java:998)
[2020-04-29T22:16:01.906Z] 		at hudson.FilePath.act(FilePath.java:1069)
[2020-04-29T22:16:01.906Z] 		at hudson.FilePath.act(FilePath.java:1058)
[2020-04-29T22:16:01.906Z] 		at hudson.FilePath.validateAntFileMask(FilePath.java:2684)
[2020-04-29T22:16:01.906Z] 		at hudson.tasks.ArtifactArchiver.perform(ArtifactArchiver.java:265)
[2020-04-29T22:16:01.906Z] 		at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:80)
[2020-04-29T22:16:01.906Z] 		at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:67)
[2020-04-29T22:16:01.906Z] 		at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
[2020-04-29T22:16:01.906Z] 		at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[2020-04-29T22:16:01.906Z] 		at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[2020-04-29T22:16:01.906Z] 		at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[2020-04-29T22:16:01.906Z] 		at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[2020-04-29T22:16:01.906Z] Caused: hudson.FilePath$TunneledInterruptedException
[2020-04-29T22:16:01.906Z] 	at hudson.FilePath$FileCallableWrapper.call(FilePath.java:3075)
[2020-04-29T22:16:01.906Z] 	at hudson.remoting.UserRequest.perform(UserRequest.java:212)
[2020-04-29T22:16:01.906Z] 	at hudson.remoting.UserRequest.perform(UserRequest.java:54)
[2020-04-29T22:16:01.906Z] 	at hudson.remoting.Request$2.run(Request.java:369)
[2020-04-29T22:16:01.906Z] 	at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
[2020-04-29T22:16:01.906Z] 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[2020-04-29T22:16:01.906Z] 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[2020-04-29T22:16:01.906Z] 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[2020-04-29T22:16:01.906Z] 	at hudson.remoting.Engine$1.lambda$newThread$0(Engine.java:93)
[2020-04-29T22:16:01.906Z] Caused: java.lang.InterruptedException: java.lang.InterruptedException: no matches found within 10000
[2020-04-29T22:16:01.906Z] 	at hudson.FilePath.act(FilePath.java:1071)
[2020-04-29T22:16:01.906Z] 	at hudson.FilePath.act(FilePath.java:1058)
[2020-04-29T22:16:01.906Z] 	at hudson.FilePath.validateAntFileMask(FilePath.java:2684)
[2020-04-29T22:16:01.906Z] 	at hudson.tasks.ArtifactArchiver.perform(ArtifactArchiver.java:265)
[2020-04-29T22:16:01.906Z] 	at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:80)
[2020-04-29T22:16:01.906Z] 	at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:67)
[2020-04-29T22:16:01.906Z] 	at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
[2020-04-29T22:16:01.906Z] 	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[2020-04-29T22:16:01.906Z] 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[2020-04-29T22:16:01.906Z] 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[2020-04-29T22:16:01.906Z] 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[2020-04-29T22:16:01.906Z] 	at java.lang.Thread.run(Thread.java:748)
[2020-04-29T22:16:01.906Z] No artifacts found that match the file pattern "**/build/TEST*.out". Configuration error?
[2020-04-29T22:16:02.372Z] + curl -sSLo codecov https://codecov.io/bash
[2020-04-29T22:16:02.634Z] + FILE=auditbeat/build/coverage/full.cov
[2020-04-29T22:16:02.634Z] + [ -f auditbeat/build/coverage/full.cov ]
[2020-04-29T22:16:02.634Z] + FILE=filebeat/build/coverage/full.cov
[2020-04-29T22:16:02.634Z] + [ -f filebeat/build/coverage/full.cov ]
[2020-04-29T22:16:02.634Z] + FILE=heartbeat/build/coverage/full.cov
[2020-04-29T22:16:02.634Z] + [ -f heartbeat/build/coverage/full.cov ]
[2020-04-29T22:16:02.634Z] + FILE=libbeat/build/coverage/full.cov
[2020-04-29T22:16:02.634Z] + [ -f libbeat/build/coverage/full.cov ]
[2020-04-29T22:16:02.634Z] + FILE=metricbeat/build/coverage/full.cov
[2020-04-29T22:16:02.634Z] + [ -f metricbeat/build/coverage/full.cov ]
[2020-04-29T22:16:02.634Z] + FILE=packetbeat/build/coverage/full.cov
[2020-04-29T22:16:02.634Z] + [ -f packetbeat/build/coverage/full.cov ]
[2020-04-29T22:16:02.634Z] + FILE=winlogbeat/build/coverage/full.cov
[2020-04-29T22:16:02.634Z] + [ -f winlogbeat/build/coverage/full.cov ]
[2020-04-29T22:16:02.634Z] + FILE=journalbeat/build/coverage/full.cov
[2020-04-29T22:16:02.634Z] + [ -f journalbeat/build/coverage/full.cov ]
[2020-04-29T22:16:05.600Z] Running on Jenkins in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18111
[2020-04-29T22:16:05.999Z] [INFO] getVaultSecret: Getting secrets
[2020-04-29T22:16:06.088Z] Masking supported pattern matches of $VAULT_ADDR or $VAULT_ROLE_ID or $VAULT_SECRET_ID
[2020-04-29T22:16:07.216Z] + chmod 755 generate-build-data.sh
[2020-04-29T22:16:07.216Z] + ./generate-build-data.sh https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats-beats-mbp/PR-18111/ https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats-beats-mbp/PR-18111/runs/1 FAILURE 4429872
[2020-04-29T22:16:07.767Z] INFO: curl https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats-beats-mbp/PR-18111/runs/1/steps/?limit=10000 -o steps-info.json
[2020-04-29T22:16:08.018Z] INFO: curl https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats-beats-mbp/PR-18111/runs/1/tests/?status=FAILED -o tests-errors.json

Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a quick look it LGTM, once merged I will also backport #18125.

@blakerouse blakerouse merged commit 1abefff into elastic:7.x Apr 30, 2020
@blakerouse blakerouse deleted the backport_17656_7.x branch April 30, 2020 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport review Team:Platforms Label for the Integrations - Platforms team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants