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

[k8s]: restructure kubernetes integration tests #6260

Merged

Conversation

pkoutsovasilis
Copy link
Contributor

@pkoutsovasilis pkoutsovasilis commented Dec 10, 2024

What does this PR do?

This PR lays the groundwork for Kubernetes hints integration tests. The related commits of the former will be included in a follow-up PR (6fa8ffb, 9a48d02) as I want to keep this PR around 500 lines (excluding go.mod and NOTICE files). These changes address the need to avoid duplicating code logic, as hints tests require deploying plain Kubernetes YAML files and checking the agent status independently. Key updates include:

  • Centralized Context: Introduced k8sContext to standardize Kubernetes test setup.
  • Refactored Helpers: Streamlined functions for Kubernetes operations (e.g., k8sCreateObjects, k8sDeleteObjects, k8sWaitForReady) with better error handling.
  • Agent Health Validation: Enhanced agent status checks with k8sCheckAgentStatus.
  • Readiness Checker: Leveraged Helm's ReadyChecker to validate readiness of Kubernetes objects (e.g., pods, deployments, daemonSets, statefulSets, etc.).

These updates improve code readability, modularity, and reusability, reducing the need for duplicate logic in k8s tests.

Why is it important?

  • Avoiding Duplication: Eliminates the need for repeated logic in k8s tests.
  • Improved Modularity: Encapsulates reusable functionality for easier maintenance and test extension.
  • Readiness Assurance: Ensures Kubernetes objects are fully ready before test execution, reducing test flakiness.

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 changes 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

No disruptive changes. Enhancements are internal to Kubernetes integration tests.

How to test this PR locally

mage integration:auth
PLATFORMS=linux/arm64 EXTERNAL=true SNAPSHOT=true PACKAGES=docker mage -v package 
INSTANCE_PROVISIONER=kind STACK_PROVISIONER=stateful K8S_VERSION=v1.31.1 SNAPSHOT=true mage integration:kubernetes

Related issues

@pkoutsovasilis pkoutsovasilis added Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team skip-changelog Testing backport-8.x Automated backport to the 8.x branch with mergify backport-8.16 Automated backport with mergify backport-8.17 Automated backport with mergify labels Dec 10, 2024
@pkoutsovasilis pkoutsovasilis self-assigned this Dec 10, 2024
@pkoutsovasilis pkoutsovasilis force-pushed the pkoutsovasilis/k8s_hints_tests_pt1 branch 3 times, most recently from b9d00b0 to 684ef9a Compare December 10, 2024 07:06
@pkoutsovasilis pkoutsovasilis marked this pull request as ready for review December 10, 2024 11:47
@pkoutsovasilis pkoutsovasilis requested a review from a team as a code owner December 10, 2024 11:47
@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.

Way cleaner, nice job!

@pkoutsovasilis
Copy link
Contributor Author

I realised that if I merge this PR before this one I am gonna cause conflict to it. This is something I would like to avoid and I would rather update this one to include the former 🙂

Copy link
Member

@pchila pchila left a comment

Choose a reason for hiding this comment

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

LGTM

@pkoutsovasilis pkoutsovasilis force-pushed the pkoutsovasilis/k8s_hints_tests_pt1 branch from 684ef9a to 8722836 Compare December 10, 2024 15:06
Copy link
Contributor

@swiatekm swiatekm left a comment

Choose a reason for hiding this comment

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

Nice!

Copy link

@pkoutsovasilis pkoutsovasilis merged commit 79caf55 into elastic:main Dec 10, 2024
14 checks passed
@pkoutsovasilis pkoutsovasilis deleted the pkoutsovasilis/k8s_hints_tests_pt1 branch December 10, 2024 17:38
mergify bot pushed a commit that referenced this pull request Dec 10, 2024
* feat: restructure k8s integration tests

* feat: update helm edot test

(cherry picked from commit 79caf55)

# Conflicts:
#	go.mod
#	testing/integration/otel_helm_test.go
mergify bot pushed a commit that referenced this pull request Dec 10, 2024
* feat: restructure k8s integration tests

* feat: update helm edot test

(cherry picked from commit 79caf55)

# Conflicts:
#	go.mod
#	testing/integration/otel_helm_test.go
mergify bot pushed a commit that referenced this pull request Dec 10, 2024
* feat: restructure k8s integration tests

* feat: update helm edot test

(cherry picked from commit 79caf55)

# Conflicts:
#	go.mod
#	testing/integration/otel_helm_test.go
ycombinator pushed a commit that referenced this pull request Dec 12, 2024
* feat: restructure k8s integration tests

* feat: update helm edot test

(cherry picked from commit 79caf55)

# Conflicts:
#	go.mod
#	testing/integration/otel_helm_test.go
pkoutsovasilis added a commit that referenced this pull request Dec 12, 2024
* feat: restructure k8s integration tests

* feat: update helm edot test

(cherry picked from commit 79caf55)

# Conflicts:
#	go.mod
#	testing/integration/otel_helm_test.go
pkoutsovasilis added a commit that referenced this pull request Dec 12, 2024
* feat: restructure k8s integration tests

* feat: update helm edot test

(cherry picked from commit 79caf55)

# Conflicts:
#	go.mod
#	testing/integration/otel_helm_test.go
pkoutsovasilis added a commit that referenced this pull request Dec 12, 2024
* feat: restructure k8s integration tests

* feat: update helm edot test

(cherry picked from commit 79caf55)

# Conflicts:
#	go.mod
#	testing/integration/otel_helm_test.go
pkoutsovasilis added a commit that referenced this pull request Dec 12, 2024
* feat: restructure k8s integration tests

* feat: update helm edot test

(cherry picked from commit 79caf55)

# Conflicts:
#	go.mod
#	testing/integration/otel_helm_test.go

Co-authored-by: Panos Koutsovasilis <panos.koutsovasilis@elastic.co>
pkoutsovasilis added a commit that referenced this pull request Dec 12, 2024
* feat: restructure k8s integration tests

* feat: update helm edot test

(cherry picked from commit 79caf55)

# Conflicts:
#	go.mod
#	testing/integration/otel_helm_test.go

Co-authored-by: Panos Koutsovasilis <panos.koutsovasilis@elastic.co>
pkoutsovasilis added a commit that referenced this pull request Dec 12, 2024
#6268)

* [k8s]: restructure kubernetes integration tests (#6260)

* feat: restructure k8s integration tests

* feat: update helm edot test

(cherry picked from commit 79caf55)

# Conflicts:
#	go.mod
#	testing/integration/otel_helm_test.go

* fix: more conflicts

* fix: go mod tidy

* fix: update NOTICE.txt

---------

Co-authored-by: Panos Koutsovasilis <panos.koutsovasilis@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-8.x Automated backport to the 8.x branch with mergify backport-8.16 Automated backport with mergify backport-8.17 Automated backport with mergify skip-changelog Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team Testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants