-
Notifications
You must be signed in to change notification settings - Fork 2k
feat: add label selector to metrics call #3999
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?
Changes from 2 commits
f57f6e3
637cd9e
285c84a
d67c840
56628df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,8 +20,11 @@ | |
import io.kubernetes.client.openapi.ApiException; | ||
import io.kubernetes.client.openapi.Configuration; | ||
import io.kubernetes.client.util.generic.GenericKubernetesApi; | ||
import io.kubernetes.client.util.generic.options.ListOptions; | ||
|
||
public class Metrics { | ||
private static final String API_GROUP = "metrics.k8s.io"; | ||
private static final String API_VERSION = "v1beta1"; | ||
private ApiClient apiClient; | ||
|
||
/** Simple Metrics API constructor, uses default configuration */ | ||
|
@@ -61,17 +64,30 @@ public NodeMetricsList getNodeMetrics() throws ApiException { | |
new GenericKubernetesApi<>( | ||
NodeMetrics.class, | ||
NodeMetricsList.class, | ||
"metrics.k8s.io", | ||
"v1beta1", | ||
Metrics.API_GROUP, | ||
Metrics.API_VERSION, | ||
"nodes", | ||
apiClient); | ||
return metricsClient.list().throwsApiException().getObject(); | ||
} | ||
|
||
public PodMetricsList getPodMetrics(String namespace) throws ApiException { | ||
return getPodMetrics(namespace, null); | ||
} | ||
|
||
/** | ||
* Obtain Pod Metrics in the given Namespace with an optional label selector. | ||
* @param namespace The Namespace to look in. | ||
* @param labelSelector The label selector, optional. Use comma-delimited for multiple labels. | ||
* @return PodMetricList, never null. | ||
* @throws ApiException If the ApiClient cannot complete the request. | ||
*/ | ||
public PodMetricsList getPodMetrics(String namespace, String labelSelector) throws ApiException { | ||
GenericKubernetesApi<PodMetrics, PodMetricsList> metricsClient = | ||
new GenericKubernetesApi<>( | ||
PodMetrics.class, PodMetricsList.class, "metrics.k8s.io", "v1beta1", "pods", apiClient); | ||
return metricsClient.list(namespace).throwsApiException().getObject(); | ||
new GenericKubernetesApi<>( | ||
PodMetrics.class, PodMetricsList.class, Metrics.API_GROUP, Metrics.API_VERSION, "pods", apiClient); | ||
This comment was marked as resolved.
Sorry, something went wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I can make that happen. Maybe the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's okay. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, scratch that. Those strings are only ever used in |
||
final ListOptions listOptions = new ListOptions(); | ||
listOptions.setLabelSelector(labelSelector); | ||
return metricsClient.list(namespace, listOptions).throwsApiException().getObject(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getPodMetrics(String namespace, @nullable String labelSelector)
It is better to mark the nullable argument explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks.