platz_sdk/resources/
k8s_clusters.rs

1use crate::client::PlatzClient;
2use anyhow::Result;
3use chrono::prelude::*;
4use kv_derive::{prelude::*, IntoVec};
5use serde::{Deserialize, Serialize};
6use uuid::Uuid;
7
8#[derive(Debug, Deserialize, Serialize, Clone)]
9pub struct K8sCluster {
10    pub id: Uuid,
11    pub env_id: Option<Uuid>,
12    pub provider_id: String,
13    pub created_at: DateTime<Utc>,
14    pub last_seen_at: DateTime<Utc>,
15    pub name: String,
16    pub region_name: String,
17    pub is_ok: bool,
18    pub not_ok_reason: Option<String>,
19    pub ignore: bool,
20    pub ingress_domain: Option<String>,
21    pub ingress_class: Option<String>,
22    pub ingress_tls_secret_name: Option<String>,
23    pub grafana_url: Option<String>,
24    pub grafana_datasource_name: Option<String>,
25}
26
27#[derive(Default, IntoVec, Debug, Serialize)]
28pub struct K8sClusterFilters {
29    #[kv(optional)]
30    pub env_id: Option<Uuid>,
31    #[kv(optional)]
32    pub name: Option<String>,
33}
34
35#[derive(Debug, Serialize)]
36pub struct UpdateK8sCluster {
37    #[serde(default, with = "::serde_with::rust::double_option")]
38    pub env_id: Option<Option<Uuid>>,
39    pub ignore: Option<bool>,
40    #[serde(default, with = "::serde_with::rust::double_option")]
41    pub ingress_domain: Option<Option<String>>,
42    #[serde(default, with = "::serde_with::rust::double_option")]
43    pub ingress_class: Option<Option<String>>,
44    #[serde(default, with = "::serde_with::rust::double_option")]
45    pub ingress_tls_secret_name: Option<Option<String>>,
46    #[serde(default, with = "::serde_with::rust::double_option")]
47    pub grafana_url: Option<Option<String>>,
48    #[serde(default, with = "::serde_with::rust::double_option")]
49    pub grafana_datasource_name: Option<Option<String>>,
50}
51
52impl PlatzClient {
53    pub async fn k8s_clusters(&self, filters: K8sClusterFilters) -> Result<Vec<K8sCluster>> {
54        Ok(self
55            .request(reqwest::Method::GET, "/api/v2/k8s-clusters")
56            .add_to_query(filters.into_vec())
57            .paginated()
58            .await?)
59    }
60
61    pub async fn k8s_cluster(&self, k8s_cluster_id: Uuid) -> Result<K8sCluster> {
62        Ok(self
63            .request(
64                reqwest::Method::GET,
65                format!("/api/v2/k8s-clusters/{k8s_cluster_id}"),
66            )
67            .send()
68            .await?)
69    }
70
71    pub async fn update_k8s_cluster(
72        &self,
73        k8s_cluster_id: Uuid,
74        update_deployment: UpdateK8sCluster,
75    ) -> Result<K8sCluster> {
76        Ok(self
77            .request(
78                reqwest::Method::PUT,
79                format!("/api/v2/k8s-clusters/{k8s_cluster_id}"),
80            )
81            .send_with_body(update_deployment)
82            .await?)
83    }
84}