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

Create local kind cluster install #647

Merged
merged 22 commits into from May 13, 2024
Merged

Create local kind cluster install #647

merged 22 commits into from May 13, 2024

Conversation

KevinFairise2
Copy link
Contributor

@KevinFairise2 KevinFairise2 commented Feb 26, 2024

What does this PR do?

This PR add two new components:

  • A component to install a local kind cluster, assuming that Kind is installed locally
  • A component to deploy a Fakeintake in a local kind cluster, The port mapping is made to have the fakeintake accessible from the port 30080 of the local host

The following PR will create a local kind provider on datadog-agent: DataDog/datadog-agent#23153

The PR also creates another API to be able to set the environment variables of all the Agents deployed with helm. Otherwise this is impossible since the env variables used to configure the fakeintake override the ones provided with WithHelmValues

Which scenarios this will impact?

Motivation

The main goal of this PR is to provide things for developers to iterate faster on their e2e tests.
Running Kubernetes tests on a remote host can be long and hard to debug, even when using kind

Additional Notes

@KevinFairise2 KevinFairise2 marked this pull request as ready for review April 4, 2024 08:59
@KevinFairise2 KevinFairise2 requested a review from a team as a code owner April 4, 2024 08:59
@@ -2,10 +2,15 @@ kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 30080
hostPort: 30080
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we could benefit from having it configurable. But for now it uses a port that should not be already bound on the host. And I could not see why we'd want to change it

Copy link
Collaborator

@vboulineau vboulineau left a comment

Choose a reason for hiding this comment

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

Code overall LGTM, small comments.

However sharing concern about the use case. This helper assumes host machine is ~Unix + docker (or podman) + kind installed.

For manual tests, I am not sure doing all this to wrap kind create cluster is worth it, however it could argued that re-using manifests defined here to install some apps can be useful. In that case I'd then favor a solution that allows to re-use current in-context cluster instead (gives a lot of flexibility in the manual testing).

For E2E tests, it requires a slightly different provisioning code (hopefully environment and components are designed to have minimal changes) and it breaks the original promise: whether you run it from your laptop or from the CI, the result will be exactly the same.

I also have doubt on the iterate faster. Iterating on Kubernetes E2E usually mean provisioning once with then a lot of updates (but you're not going to update the cluster), the added provisioning time is quite short.

Once provisioned, the difference to the kubectl user is expected to be ~0, so it'd be interesting to have a better understanding of the issues faced.

components/datadog/agent/kubernetes_helm.go Outdated Show resolved Hide resolved
components/datadog/fakeintake/component.go Outdated Show resolved Hide resolved
components/datadog/fakeintake/kubernetes.go Outdated Show resolved Hide resolved
components/datadog/fakeintake/kubernetes.go Outdated Show resolved Hide resolved
components/kubernetes/kind.go Outdated Show resolved Hide resolved
components/kubernetes/kind.go Outdated Show resolved Hide resolved
components/kubernetes/kind.go Outdated Show resolved Hide resolved
@KevinFairise2
Copy link
Contributor Author

KevinFairise2 commented Apr 9, 2024

For manual tests, I am not sure doing all this to wrap kind create cluster is worth it, however it could argued that re-using manifests defined here to install some apps can be useful. In that case I'd then favor a solution that allows to re-use current in-context cluster instead (gives a lot of flexibility in the manual testing).

Manual testing is not the first goal of this PR, the idea was more to create a provider that provision local resources that can be used when running e2e tests locally.

it breaks the original promise: whether you run it from your laptop or from the CI, the result will be exactly the same.

Yes indeed the environment is not exactly the same as in the CI, that's one of the drawback but I tried to make the local environment as close as the remote one as possible.

I also have doubt on the iterate faster. Iterating on Kubernetes E2E usually mean provisioning once with then a lot of updates (but you're not going to update the cluster), the added provisioning time is quite short.

It's a feedback we often have from users creating tests. Remote resources can be long to create, it often leaks some resources and running the test again can be painful (need to delete resources on AWS) and DevMode is not really helpful because the infra is not cleaned up properly between test runs

This helper assumes host machine is ~Unix + docker (or podman) + kind installed.
Yep we assume kind and docker is installed which should be the case if you want to run e2e with local resources. I could not test but it should also work on Windows since kind create cluster command should work also on windows

@KevinFairise2
Copy link
Contributor Author

KevinFairise2 commented Apr 10, 2024

Updated the PR to take into account the suggestions. I also no longer deploy the fakeintake in Kubernetes, but rather deploy it locally in Docker. As discussed with @pducolin it should make things easier to use it with other local providers

components/datadog/fakeintake/docker.go Outdated Show resolved Hide resolved
components/datadog/fakeintake/docker.go Outdated Show resolved Hide resolved
Co-authored-by: pducolin <45568537+pducolin@users.noreply.github.com>
// The URL does not need to exist
conn, err := net.Dial("udp", "8.8.8.8:80")
if err != nil {
log.Fatal(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ question
Should you rather return the error, instead of panicking?

@KevinFairise2
Copy link
Contributor Author

/merge

@dd-devflow
Copy link

dd-devflow bot commented May 13, 2024

🚂 MergeQueue

Pull request added to the queue.

This build is going to start soon! (estimated merge in less than 24m)

Use /merge -c to cancel this operation!

@dd-mergequeue dd-mergequeue bot merged commit aac31c9 into main May 13, 2024
8 checks passed
@dd-mergequeue dd-mergequeue bot deleted the kfairise/local-kind branch May 13, 2024 13:11
carlosroman pushed a commit that referenced this pull request May 21, 2024
* Create local kind cluster install

* Add API on Kubernetes Agent to be able to set environment variables

* Update fakeintake env vars to be able to not use ssl

* Local Fakeintake in Kubernetes

* Use const for localPort

* Fix lint

* Do not install the fakeintake in Kubernetes, rather use a docker version that can be used with other local provider

* Remove runner interface try

* Remove not needed env var configuration

* Remove unneeded kubeconfig modif

* Remove configureEnvVars

* Make linter happy

* Remove AMI

* Update components/datadog/fakeintake/docker.go

Co-authored-by: pducolin <45568537+pducolin@users.noreply.github.com>

* Update components/datadog/fakeintake/docker.go

* gofmt

* gomodtidy

* Handle error

* Use new Env interface

---------

Co-authored-by: pducolin <45568537+pducolin@users.noreply.github.com>
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.

None yet

3 participants