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

[e2e-tests] feat: add k8s integration tests #5013

Merged
merged 12 commits into from
Jul 12, 2024

Conversation

pkoutsovasilis
Copy link
Contributor

@pkoutsovasilis pkoutsovasilis commented Jun 27, 2024

What does this PR do?

Introduces mage integration:kubernetes target that performs integration testing of elastic-agent on Kubernetes. Currently it supports provisioning k8s cluster only through kind.

Inside the integration:kubernetes the following sequence happens:

  1. Provision of the corresponding stack and k8s clusters based on the defined K8S_VERSION (this can specify a single or multiple k8s versions separated with a , character)
  2. Invocation of the Kubernetes-related tests that require the following Group and OS
     info := define.Require(t, define.Requirements{
     Stack: &define.Stack{},
     Local: false,
     Sudo:  false,
     OS: []define.OS{
         {Type: define.Kubernetes},
       },
       Group: define.Kubernetes,
     })
    

Following the above paradigm, this PR also includes a k8s integration test that renders the corresponding kustomize template of a standalone elastic-agent and checks that respective pods are getting deployed successfully and waits until the get to a Ready state with all containers Running.

PS: check the K8s integration tests step in the buildkite CI

Why is it important?

Because it will allow properly testing elastic-agent, including the several deployment manifests atm, on Kubernetes

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/fragments using the changelog tool
  • I have added an integration test or an E2E test

Disruptive User Impact

N/A

How to test this PR locally

Prerequisites:

  • kind installed
  • docker installed
  • authenticated in GCP and ESS by mage integration:auth

Steps:

  • mage integration:auth
  • DEV=true SNAPSHOT=true EXTERNAL=true PACKAGES=docker mage -v package
  • K8S_VERSION="v1.30.2,v1.29.4,v1.28.9" INSTANCE_PROVISIONER=kind STACK_PROVISIONER=stateful SNAPSHOT=true mage integration:kubernetes

Related issues

@pkoutsovasilis pkoutsovasilis changed the title feat: wip k8s integration tests [don't merge] feat: wip k8s integration tests Jun 27, 2024
@pkoutsovasilis pkoutsovasilis force-pushed the pkoutsovasilis/k8s_tests branch 4 times, most recently from 5a1a4ae to cd52448 Compare June 27, 2024 20:24
@pkoutsovasilis
Copy link
Contributor Author

@cmacknz @blakerouse this is a PR that follows the proposed design details in the comments of this issue. Could you take a quick look around and see if you spot anything that is way-off?

PS1: The logic of dynamically provisioning stacks and instances through the framework from inside a CI runner, even after coding it, still feels kinda awkward to me. Maybe this is because in my prior-experience so far this provisioning was the responsibility of an buildkite equivalent layer and the internal testing framework was just checking that the required resources were actually provisioned and then it was invoking the respective tests. Either way, here we go 🙂

PS2: thanks @alexsapran for showing me the whereabouts of buildkite and helping me understand how to introduce these new kubernetes integration steps

@elastic elastic deleted a comment from mergify bot Jun 28, 2024
@alexsapran
Copy link
Contributor

PS1: The logic of dynamically provisioning stacks and instances through the framework from inside a CI runner, even after coding it, still feels kinda awkward to me. Maybe this is because in my prior-experience so far this provisioning was the responsibility of an buildkite equivalent layer and the internal testing framework was just checking that the required resources were actually provisioned and then it was invoking the respective tests. Either way, here we go 🙂

From my Point of View, it should be decoupled steps. The testing framework should only trigger the tests, and the provisioning and setup of the prerequisites should live in dedicated targets; then, CI should pull together all of those into an execution step. Now, for developer simplicity, we could have a dedicated target that could wrap around those steps, but within CI, there should be distinct targets.

Copy link
Contributor

@blakerouse blakerouse left a comment

Choose a reason for hiding this comment

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

I think this is an excellent start and I really like how this is shaping up. I really only have one major comment about the additions in pkg/component, other than that this is exactly what I was wanting for extending the framework to support kubernetes.

magefile.go Outdated Show resolved Hide resolved
magefile.go Show resolved Hide resolved
pkg/component/platforms.go Outdated Show resolved Hide resolved
pkg/component/platforms.go Outdated Show resolved Hide resolved
pkg/testing/define/requirements.go Outdated Show resolved Hide resolved
pkg/testing/kubernetes/kind/provisioner.go Outdated Show resolved Hide resolved
pkg/testing/runner/provisioner.go Show resolved Hide resolved
@elastic elastic deleted a comment from mergify bot Jul 10, 2024
Copy link
Contributor

@blakerouse blakerouse left a comment

Choose a reason for hiding this comment

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

Changes look good, so far.

I guess an actual real test is next?

@pkoutsovasilis
Copy link
Contributor Author

Changes look good, so far.

I guess an actual real test is next?

yep it is this time!!! an actual k8s deployment test that waits at least for all agent pods to become Running and Ready

@pkoutsovasilis pkoutsovasilis changed the title [don't merge] feat: wip k8s integration tests [e2e-tests] feat: add k8s integration tests Jul 10, 2024
@elastic elastic deleted a comment from mergify bot Jul 10, 2024
Copy link

@pkoutsovasilis pkoutsovasilis marked this pull request as ready for review July 10, 2024 22:32
@pkoutsovasilis pkoutsovasilis requested a review from a team as a code owner July 10, 2024 22:32
@pierrehilbert pierrehilbert added the Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team label Jul 11, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane)

Copy link
Contributor

@blakerouse blakerouse left a comment

Choose a reason for hiding this comment

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

This is fantastic!

It even tests multiple versions of the kind cluster. Such a great starting point for testing on k8s.


const agentK8SKustomize = "../../deploy/kubernetes/elastic-agent-kustomize/default/elastic-agent-standalone"

func TestKubernetesAgentStandalone(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think as more tests are written some of the code in this test could be split out into helpers that other tests will use. Helpers would really help with reading this code as well.

Not a blocker, would like to see this merged. I see changes like helpers evolving over more tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for the proposal @blakerouse , I was thinking something similar; defining a custom "k8sclient" struct with the helper functions attached so within a test you can get them from info.KubeClient(). However this felt like another PR to follow 🙂

@cmacknz
Copy link
Member

cmacknz commented Jul 12, 2024

@elastic/ingest-eng-prod FYI

@pkoutsovasilis pkoutsovasilis merged commit 79547df into main Jul 12, 2024
15 checks passed
@pkoutsovasilis pkoutsovasilis deleted the pkoutsovasilis/k8s_tests branch July 12, 2024 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Kubernetes e2e tests
6 participants