-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathcluster_info.rs
More file actions
52 lines (43 loc) · 1.69 KB
/
cluster_info.rs
File metadata and controls
52 lines (43 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use kube::Client;
use snafu::{ResultExt, Snafu};
use crate::{commons::networking::DomainName, utils::kubelet};
#[derive(Debug, Snafu)]
pub enum Error {
#[snafu(display("unable to fetch kubelet config"))]
KubeletConfig { source: kubelet::Error },
}
#[derive(Debug, Clone)]
pub struct KubernetesClusterInfo {
/// The Kubernetes cluster domain, typically `cluster.local`.
pub cluster_domain: DomainName,
}
#[derive(clap::Parser, Debug, Default, PartialEq, Eq)]
pub struct KubernetesClusterInfoOpts {
/// Kubernetes cluster domain, usually this is `cluster.local`.
// We are not using a default value here, as operators will probably do an more advanced
// auto-detection of the cluster domain in case it is not specified in the future.
#[arg(long, env)]
pub kubernetes_cluster_domain: Option<DomainName>,
}
impl KubernetesClusterInfo {
pub async fn new(
client: &Client,
cluster_info_opts: &KubernetesClusterInfoOpts,
) -> Result<Self, Error> {
let cluster_domain = match &cluster_info_opts.kubernetes_cluster_domain {
Some(cluster_domain) => {
tracing::info!(%cluster_domain, "Using configured Kubernetes cluster domain");
cluster_domain.clone()
}
None => {
let kubelet_config = kubelet::KubeletConfig::fetch(client)
.await
.context(KubeletConfigSnafu)?;
let cluster_domain = kubelet_config.cluster_domain;
tracing::info!(%cluster_domain, "Using Kubernetes cluster domain from the kubelet config");
cluster_domain
}
};
Ok(Self { cluster_domain })
}
}