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

[8.x](backport #6495) [helm] add kube-state-metric subchart dependency #6534

Merged
merged 2 commits into from
Jan 17, 2025

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Jan 17, 2025

What does this PR do?

This PR refactors the Elastic Agent Helm chart to include the kube-state-metrics (KSM) chart as a subchart dependency. The changes enable users to seamlessly deploy KSM alongside the Elastic Agent for all different deployment options, improving the out-of-the-box experience for Kubernetes monitoring.

Key changes include:

  • Addition of the KSM Helm chart as a subchart dependency.
  • Introduction of values that allow enabling or disabling KSM deployment (kube-state-metrics.enabled) and deploying Elastic Agent as a sidecar container to the former (kubernetes.state.agentAsSidecar.enabled)
    • PS: now that kube-state-metrics derive from another subchart deploying elastic-agent through ECK as a sidecar is not feasible. values.schema.json has been updated to prevent such configuration
  • Refactoring of the Helm chart structure to incorporate KSM configurations and clean-up unused code.
    • The templates that regard the input of kube-state-metrics in kubernetes integration got significantly reduced resulting in an easier to follow code
    • The templates that regard the k8s tuning of each preset based on the Helm values got migrated to a separate folder to promote segregation from input-related templates, thus resulting in an easier to follow code

This PR consists of 3 commits:

  • 546ec26 just introduce the kube-state-metric subchart dependency
  • 27748fa the actual changes of this PR
  • a019dbf examples showcasing the new functionality

since a019dbf, which is the main change of this PR, is +529 additions -1268 deletions I deem that this PR complies with the team PR policies but happy to try to split it up in smaller chunks if it doesn't 🙂

Why is it important?

This PR is important because it enhances the Elastic Agent Helm chart to simplify the deployment and management of Kubernetes monitoring. By including kube-state-metrics as a subchart dependency, the PR significantly reduces user friction and ensures better alignment with Kubernetes integration requirements.

The refactoring also:

  • Improves maintainability by reducing template complexity and segregating logic for better readability.
  • Provides flexibility for users to enable or disable KSM and enable or disable embedding elastic-agent as a sidecar to the former, catering to diverse use cases.

Checklist

  • I have read and understood the pull request guidelines of this project.
  • 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

This PR introduces a new default behavior that includes the kube-state-metrics chart as a dependency. By default:

  • kube-state-metrics is deployed. Users must explicitly disable it by setting kube-state-metrics.enabled=false to opt out of deploying
  • all kube-state-metrics related metrics are now captured by the cluster-wide agent preset. Users opting to deploy elastic-agent as a sidecar to kube-state-metrics must explicitly enable it in the values file by setting kubernetes.state.agentAsSidecar.enabled=true.
  • Unsupported configurations, such as deploying Elastic Agent as a sidecar to KSM managed by ECK, are now restricted.

For users upgrading existing installations, ksmSharded preset is gonna be uninstalled and their kube-state-metrics related flow will follow the logic above

How to test this PR locally

  • Follow one of the newly introduced examples
  • Run k8s integration tests
    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


This is an automatic backport of pull request #6495 done by [Mergify](https://mergify.com).

* feat: add ksm subchart dependency

* feat: refactor elastic-agent chart to utilise ksm subchart

* feat: add new ksm examples

* fix: typos

* feat: remove charts directory

* fix: reintroduce Chart.lock

(cherry picked from commit edd342a)

# Conflicts:
#	deploy/helm/elastic-agent/Chart.yaml
#	deploy/helm/elastic-agent/examples/eck/rendered/manifest.yaml
#	deploy/helm/elastic-agent/examples/kubernetes-default/rendered/manifest.yaml
#	deploy/helm/elastic-agent/examples/kubernetes-hints-autodiscover/rendered/manifest.yaml
#	deploy/helm/elastic-agent/examples/multiple-integrations/rendered/manifest.yaml
#	deploy/helm/elastic-agent/examples/user-service-account/rendered/manifest.yaml
@mergify mergify bot requested a review from a team as a code owner January 17, 2025 01:08
@mergify mergify bot requested review from michalpristas and swiatekm and removed request for a team January 17, 2025 01:08
@mergify mergify bot added backport conflicts There is a conflict in the backported pull request labels Jan 17, 2025
Copy link
Contributor Author

mergify bot commented Jan 17, 2025

Cherry-pick of edd342a has failed:

On branch mergify/bp/8.x/pr-6495
Your branch is up to date with 'origin/8.x'.

You are currently cherry-picking commit edd342afa.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	new file:   deploy/helm/elastic-agent/.gitignore
	new file:   deploy/helm/elastic-agent/Chart.lock
	modified:   deploy/helm/elastic-agent/README.md
	modified:   deploy/helm/elastic-agent/examples/README.md
	modified:   deploy/helm/elastic-agent/examples/eck/README.md
	modified:   deploy/helm/elastic-agent/examples/eck/agent-kubernetes-values.yaml
	new file:   deploy/helm/elastic-agent/examples/fleet-managed-ksm-sharding/README.md
	new file:   deploy/helm/elastic-agent/examples/fleet-managed-ksm-sharding/fleet-values.yaml
	new file:   deploy/helm/elastic-agent/examples/fleet-managed-ksm-sharding/rendered/manifest.yaml
	modified:   deploy/helm/elastic-agent/examples/fleet-managed/README.md
	modified:   deploy/helm/elastic-agent/examples/fleet-managed/rendered/manifest.yaml
	modified:   deploy/helm/elastic-agent/examples/kubernetes-default/README.md
	modified:   deploy/helm/elastic-agent/examples/kubernetes-hints-autodiscover/README.md
	new file:   deploy/helm/elastic-agent/examples/kubernetes-ksm-sharding/README.md
	new file:   deploy/helm/elastic-agent/examples/kubernetes-ksm-sharding/agent-kubernetes-values.yaml
	new file:   deploy/helm/elastic-agent/examples/kubernetes-ksm-sharding/rendered/manifest.yaml
	modified:   deploy/helm/elastic-agent/examples/kubernetes-only-logs/README.md
	modified:   deploy/helm/elastic-agent/examples/kubernetes-only-logs/agent-kubernetes-values.yaml
	modified:   deploy/helm/elastic-agent/examples/kubernetes-only-logs/rendered/manifest.yaml
	modified:   deploy/helm/elastic-agent/examples/multiple-integrations/README.md
	modified:   deploy/helm/elastic-agent/examples/netflow-service/README.md
	modified:   deploy/helm/elastic-agent/examples/netflow-service/agent-netflow-values.yaml
	modified:   deploy/helm/elastic-agent/examples/nginx-custom-integration/README.md
	modified:   deploy/helm/elastic-agent/examples/nginx-custom-integration/agent-nginx-values.yaml
	modified:   deploy/helm/elastic-agent/examples/system-custom-auth-paths/README.md
	modified:   deploy/helm/elastic-agent/examples/system-custom-auth-paths/agent-system-values.yaml
	modified:   deploy/helm/elastic-agent/examples/system-custom-auth-paths/rendered/manifest.yaml
	modified:   deploy/helm/elastic-agent/examples/user-cluster-role/README.md
	modified:   deploy/helm/elastic-agent/examples/user-cluster-role/agent-nginx-values.yaml
	modified:   deploy/helm/elastic-agent/examples/user-service-account/README.md
	modified:   deploy/helm/elastic-agent/examples/user-service-account/agent-kubernetes-values.yaml
	modified:   deploy/helm/elastic-agent/templates/NOTES.txt
	modified:   deploy/helm/elastic-agent/templates/agent/_helpers.tpl
	modified:   deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes.tpl
	modified:   deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_apiserver.tpl
	modified:   deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_controller_manager.tpl
	deleted:    deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_hints.tpl
	modified:   deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_kubelet_containers.tpl
	modified:   deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_kubelet_nodes.tpl
	modified:   deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_kubelet_pods.tpl
	modified:   deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_kubelet_system.tpl
	modified:   deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_kubelet_volumes.tpl
	modified:   deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_logs_audit.tpl
	modified:   deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_logs_containers.tpl
	modified:   deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_proxy.tpl
	modified:   deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_scheduler.tpl
	new file:   deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_state.tpl
	deleted:    deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_state_containers.tpl
	deleted:    deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_state_cronjobs.tpl
	deleted:    deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_state_daemonsets.tpl
	deleted:    deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_state_deployments.tpl
	deleted:    deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_state_jobs.tpl
	deleted:    deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_state_namespaces.tpl
	deleted:    deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_state_nodes.tpl
	deleted:    deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_state_persistentvolumeclaims.tpl
	deleted:    deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_state_persistentvolumes.tpl
	deleted:    deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_state_pods.tpl
	deleted:    deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_state_replicasets.tpl
	deleted:    deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_state_resourcequotas.tpl
	deleted:    deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_state_services.tpl
	deleted:    deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_state_statefulsets.tpl
	deleted:    deploy/helm/elastic-agent/templates/integrations/_kubernetes/_kubernetes_state_storageclasses.tpl
	deleted:    deploy/helm/elastic-agent/templates/integrations/_kubernetes/_preset_clusterwide.tpl
	deleted:    deploy/helm/elastic-agent/templates/integrations/_kubernetes/_preset_ksmsharded.tpl
	deleted:    deploy/helm/elastic-agent/templates/integrations/_kubernetes/_preset_pernode.tpl
	new file:   deploy/helm/elastic-agent/templates/integrations/_presets/_ksm_sidecar.tpl
	new file:   deploy/helm/elastic-agent/templates/integrations/_presets/_pernode.tpl
	modified:   deploy/helm/elastic-agent/templates/integrations/_system/_system_logs.tpl
	modified:   deploy/helm/elastic-agent/templates/integrations/_system/_system_metrics.tpl
	modified:   deploy/helm/elastic-agent/values.schema.json
	modified:   deploy/helm/elastic-agent/values.yaml
	modified:   magefile.go
	new file:   pkg/testing/helm/helm.go
	modified:   testing/integration/kubernetes_agent_standalone_test.go

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   deploy/helm/elastic-agent/Chart.yaml
	both modified:   deploy/helm/elastic-agent/examples/eck/rendered/manifest.yaml
	both modified:   deploy/helm/elastic-agent/examples/kubernetes-default/rendered/manifest.yaml
	both modified:   deploy/helm/elastic-agent/examples/kubernetes-hints-autodiscover/rendered/manifest.yaml
	both modified:   deploy/helm/elastic-agent/examples/multiple-integrations/rendered/manifest.yaml
	both modified:   deploy/helm/elastic-agent/examples/user-service-account/rendered/manifest.yaml

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@github-actions github-actions bot added Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team skip-changelog labels Jan 17, 2025
@elasticmachine
Copy link
Contributor

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

@pkoutsovasilis pkoutsovasilis enabled auto-merge (squash) January 17, 2025 01:25
Copy link

@pkoutsovasilis pkoutsovasilis merged commit 949bf59 into 8.x Jan 17, 2025
13 checks passed
@pkoutsovasilis pkoutsovasilis deleted the mergify/bp/8.x/pr-6495 branch January 17, 2025 04:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport conflicts There is a conflict in the backported pull request skip-changelog Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants