-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Add Kubernetes Metrics API support to utils module #2512
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
base: master
Are you sure you want to change the base?
Conversation
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Copilot The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
|
@copilot please add an end to end test also. |
- Tests node metrics retrieval from cluster - Tests pod metrics retrieval with namespace filtering - Tests pod metrics with label selector filtering - Tests multi-namespace metrics aggregation - Includes proper error handling and skip logic if metrics-server unavailable - Creates test pod, waits for it to be running, then fetches metrics Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
Adds native support for querying pod and node resource metrics (CPU/memory) from the metrics.k8s.io API, enabling monitoring and autoscaling workflows without external dependencies.
Changes
New module
kubernetes/utils/metrics.pywith three functions:get_nodes_metrics(api_client)- cluster-wide node metricsget_pods_metrics(api_client, namespace, label_selector=None)- namespace-scoped pod metrics with optional label filteringget_pods_metrics_in_all_namespaces(api_client, namespaces, label_selector=None)- multi-namespace aggregation with per-namespace error isolationTesting:
kubernetes/test/test_metrics.pycovering success paths, validation, filtering, and error handlingkubernetes/e2e_test/test_utils.pythat validates metrics retrieval against a real cluster with metrics-serverDocumentation: API reference, usage patterns, and troubleshooting guide in
kubernetes/docs/metrics.mdExample: Working demonstration in
examples/metrics_example.pyUsage
Requirements
Requires metrics-server installed in target cluster. Uses existing
CustomObjectsApito access metrics.k8s.io/v1beta1 endpoints.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.