Add Kubernetes Metrics API support to utils module#2512
Add Kubernetes Metrics API support to utils module#2512
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>
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: 8 unit tests covering success paths, validation, filtering, and error handling
Documentation: 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.