kubectl_view_allocations/
metrics.rs

1use serde::{Deserialize, Serialize};
2// kubectl get --raw /apis/metrics.k8s.io/v1beta1/pods | jq .
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct Usage {
6    pub cpu: String,
7    pub memory: String,
8}
9
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct Container {
12    pub name: String,
13    pub usage: Usage,
14}
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
17pub struct PodMetrics {
18    pub metadata: kube::api::ObjectMeta,
19    pub containers: Vec<Container>,
20    pub timestamp: String,
21    pub window: String,
22}
23
24// custom impl since metrics API doesn't exist on kube-rs
25impl k8s_openapi::Resource for PodMetrics {
26    const GROUP: &'static str = "metrics.k8s.io";
27    const KIND: &'static str = "pod";
28    const VERSION: &'static str = "v1beta1";
29    const API_VERSION: &'static str = "metrics.k8s.io/v1beta1";
30    const URL_PATH_SEGMENT: &'static str = "pods";
31    type Scope = k8s_openapi::NamespaceResourceScope;
32}
33
34impl k8s_openapi::Metadata for PodMetrics {
35    type Ty = kube::api::ObjectMeta;
36
37    fn metadata(&self) -> &Self::Ty {
38        &self.metadata
39    }
40
41    fn metadata_mut(&mut self) -> &mut Self::Ty {
42        &mut self.metadata
43    }
44}
45
46// #[derive(Debug, Clone, Serialize, Deserialize)]
47// struct PodMetricsList {
48//     metadata: kube::api::ObjectMeta,
49//     api_version: String,
50//     kind: String,
51//     items: Vec<PodMetrics>,
52// }