* all net5 * var * SA1310 * SA1310 * allow 1031 * SA1805 * fix SA1642 * remove unused code * allow sa1405 * isempty * fix CA1714 * fix CA1806 * remove always false if * fix format * fix CA1062 * allow SA0001 * fix CA1062 * allow ca1034 and temp allow ca1835 * fix 16XX doc related warnings * elm SA16XX * elm SA16XX * fix CA2213 * revert to pass all test * move unclear rule to ruleset * follow up of moving ruleset * remove this * fix test flaky
47 lines
2.1 KiB
C#
47 lines
2.1 KiB
C#
using k8s.Models;
|
|
using Newtonsoft.Json.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace k8s
|
|
{
|
|
/// <summary>
|
|
/// Extension methods for Kubernetes metrics.
|
|
/// </summary>
|
|
public static class KubernetesMetricsExtensions
|
|
{
|
|
/// <summary>
|
|
/// Get nodes metrics pull from metrics server API.
|
|
/// </summary>
|
|
/// <param name="kubernetes">kubernetes client object</param>
|
|
/// <returns>the metrics <see cref="PodMetricsList"/></returns>
|
|
public static async Task<NodeMetricsList> GetKubernetesNodesMetricsAsync(this IKubernetes kubernetes)
|
|
{
|
|
var customObject = (JObject)await kubernetes.GetClusterCustomObjectAsync("metrics.k8s.io", "v1beta1", "nodes", string.Empty).ConfigureAwait(false);
|
|
return customObject.ToObject<NodeMetricsList>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get pods metrics pull from metrics server API.
|
|
/// </summary>
|
|
/// <param name="kubernetes">kubernetes client object</param>
|
|
/// <returns>the metrics <see cref="PodMetricsList"/></returns>
|
|
public static async Task<PodMetricsList> GetKubernetesPodsMetricsAsync(this IKubernetes kubernetes)
|
|
{
|
|
var customObject = (JObject)await kubernetes.GetClusterCustomObjectAsync("metrics.k8s.io", "v1beta1", "pods", string.Empty).ConfigureAwait(false);
|
|
return customObject.ToObject<PodMetricsList>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get pods metrics by namespace pull from metrics server API.
|
|
/// </summary>
|
|
/// <param name="kubernetes">kubernetes client object</param>
|
|
/// <param name="namespaceParameter">the querying namespace</param>
|
|
/// <returns>the metrics <see cref="PodMetricsList"/></returns>
|
|
public static async Task<PodMetricsList> GetKubernetesPodsMetricsByNamespaceAsync(this IKubernetes kubernetes, string namespaceParameter)
|
|
{
|
|
var customObject = (JObject)await kubernetes.GetNamespacedCustomObjectAsync("metrics.k8s.io", "v1beta1", namespaceParameter, "pods", string.Empty).ConfigureAwait(false);
|
|
return customObject.ToObject<PodMetricsList>();
|
|
}
|
|
}
|
|
}
|