Skip to content

Commit

Permalink
chore: renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
smrz2001 committed Apr 24, 2024
1 parent 1505ffd commit 01fa239
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
42 changes: 20 additions & 22 deletions operator/src/network/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use crate::{
ipfs_rpc::{HttpRpcClient, IpfsRpcClient},
node_affinity::NodeAffinityConfig,
peers, CasSpec, MonitoringSpec, Network, NetworkStatus, NetworkType,
PodMetricsEndpointSpec, PodMonitor, PodMonitorSpec, SelectorSpec,
PodMetricsEndpointSpec, PodMonitor, PodMonitorCrd, SelectorSpec,
},
utils::{
apply_config_map, apply_job, apply_service, apply_service_with_labels, apply_stateful_set,
Expand Down Expand Up @@ -162,11 +162,11 @@ const MAX_CERAMICS: usize = 10;
#[derive(Default)]
struct MonitoringConfig {
namespaced: bool,
pod_monitoring: PodMonitoringConfig,
pod_monitor: PodMonitorConfig,
}

#[derive(Default)]
struct PodMonitoringConfig {
struct PodMonitorConfig {
enabled: bool,
pod_target_labels: Vec<String>,
}
Expand All @@ -175,24 +175,22 @@ impl From<&Option<MonitoringSpec>> for MonitoringConfig {
fn from(spec: &Option<MonitoringSpec>) -> Self {
let default = MonitoringConfig::default();
if let Some(spec) = spec {
if let Some(pod_monitoring) = &spec.pod_monitoring {
if let Some(pod_monitor) = &spec.pod_monitor {
Self {
namespaced: spec.namespaced.unwrap_or(default.namespaced),
pod_monitoring: PodMonitoringConfig {
enabled: pod_monitoring
.enabled
.unwrap_or(default.pod_monitoring.enabled),
pod_target_labels: pod_monitoring
pod_monitor: PodMonitorConfig {
enabled: pod_monitor.enabled.unwrap_or(default.pod_monitor.enabled),
pod_target_labels: pod_monitor
.pod_target_labels
.as_ref()
.map(|labels| labels.clone())
.unwrap_or(default.pod_monitoring.pod_target_labels),
.cloned()
.unwrap_or(default.pod_monitor.pod_target_labels),
},
}
} else {
Self {
namespaced: spec.namespaced.unwrap_or(default.namespaced),
pod_monitoring: default.pod_monitoring,
pod_monitor: default.pod_monitor,
}
}
} else {
Expand Down Expand Up @@ -287,14 +285,14 @@ async fn reconcile_(
let node_affinity_config: NodeAffinityConfig = spec.into();

if monitoring_config.namespaced {
if monitoring_config.pod_monitoring.enabled {
if monitoring_config.pod_monitor.enabled {
apply_pod_monitor(
cx.clone(),
network.clone(),
"ceramic",
9464,
"ceramic",
monitoring_config.pod_monitoring.pod_target_labels.clone(),
monitoring_config.pod_monitor.pod_target_labels.clone(),
)
.await?;
apply_pod_monitor(
Expand All @@ -303,7 +301,7 @@ async fn reconcile_(
"ceramic-one",
9465,
"ceramic",
monitoring_config.pod_monitoring.pod_target_labels.clone(),
monitoring_config.pod_monitor.pod_target_labels.clone(),
)
.await?;
apply_pod_monitor(
Expand All @@ -312,7 +310,7 @@ async fn reconcile_(
"otel",
9464,
"otel",
monitoring_config.pod_monitoring.pod_target_labels,
monitoring_config.pod_monitor.pod_target_labels,
)
.await?;
}
Expand Down Expand Up @@ -1038,7 +1036,7 @@ async fn apply_pod_monitor(
if pod_monitor.is_none() {
let mut pod_monitor = PodMonitor::new(
monitor_name,
PodMonitorSpec {
PodMonitorCrd {
pod_metrics_endpoints: vec![PodMetricsEndpointSpec {
interval: Some("10s".to_owned()),
path: Some("/metrics".to_owned()),
Expand Down Expand Up @@ -1082,7 +1080,7 @@ mod tests {
ipfs_rpc::{tests::MockIpfsRpcClientTest, Peer},
stub::{CeramicStub, Stub},
BootstrapSpec, CasSpec, CeramicSpec, DataDogSpec, GoIpfsSpec, IpfsSpec, MonitoringSpec,
NetworkSpec, NetworkStatus, NetworkType, PodMonitoringSpec, ResourceLimitsSpec,
NetworkSpec, NetworkStatus, NetworkType, PodMonitorSpec, ResourceLimitsSpec,
RustIpfsSpec,
},
utils::{
Expand Down Expand Up @@ -3778,7 +3776,7 @@ mod tests {
let network = Network::test().with_spec(NetworkSpec {
monitoring: Some(MonitoringSpec {
namespaced: Some(true),
pod_monitoring: None,
pod_monitor: None,
}),
..Default::default()
});
Expand Down Expand Up @@ -3811,7 +3809,7 @@ mod tests {
let network = Network::test().with_spec(NetworkSpec {
monitoring: Some(MonitoringSpec {
namespaced: Some(true),
pod_monitoring: Some(PodMonitoringSpec {
pod_monitor: Some(PodMonitorSpec {
enabled: Some(true),
..Default::default()
}),
Expand Down Expand Up @@ -3864,7 +3862,7 @@ mod tests {
let network = Network::test().with_spec(NetworkSpec {
monitoring: Some(MonitoringSpec {
namespaced: Some(true),
pod_monitoring: Some(PodMonitoringSpec {
pod_monitor: Some(PodMonitorSpec {
enabled: Some(true),
pod_target_labels: Some(vec![
"affinity".to_owned(),
Expand Down Expand Up @@ -3924,7 +3922,7 @@ mod tests {
let network = Network::test().with_spec(NetworkSpec {
monitoring: Some(MonitoringSpec {
namespaced: Some(true),
pod_monitoring: Some(PodMonitoringSpec {
pod_monitor: Some(PodMonitorSpec {
enabled: Some(true),
..Default::default()
}),
Expand Down
6 changes: 3 additions & 3 deletions operator/src/network/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,13 @@ pub struct MonitoringSpec {
/// Deploy monitoring resources into the network namespace directly
pub namespaced: Option<bool>,
/// Deploy pod monitors
pub pod_monitoring: Option<PodMonitoringSpec>,
pub pod_monitor: Option<PodMonitorSpec>,
}

/// Describes the pod monitor configuration
#[derive(Serialize, Deserialize, Debug, Default, PartialEq, Clone, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct PodMonitoringSpec {
pub struct PodMonitorSpec {
/// Whether pod monitoring is enabled
pub enabled: Option<bool>,
/// Labels transferred from the pod onto the ingested metrics
Expand All @@ -290,7 +290,7 @@ pub struct PodMonitoringSpec {
derive = "PartialEq"
)]
#[serde(rename_all = "camelCase")]
pub struct PodMonitorSpec {
pub struct PodMonitorCrd {
/// List of endpoints that are part of this monitor
pub pod_metrics_endpoints: Vec<PodMetricsEndpointSpec>,
/// Labels transferred from the pod onto the ingested metrics
Expand Down
6 changes: 3 additions & 3 deletions operator/src/network/stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use kube::{

use crate::{
labels::managed_labels,
network::{Network, NetworkSpec, NetworkStatus, PodMonitor, PodMonitorSpec},
network::{Network, NetworkSpec, NetworkStatus, PodMonitor, PodMonitorCrd},
utils::test::{ApiServerVerifier, WithStatus},
};

Expand Down Expand Up @@ -238,7 +238,7 @@ impl Stub {
.expect("pod monitor crd should fetch");
if let Some((monitor_get, monitor_exists)) = monitor_get {
let monitor = if monitor_exists {
Some(PodMonitor::new("test", PodMonitorSpec::default()))
Some(PodMonitor::new("test", PodMonitorCrd::default()))
} else {
None
};
Expand All @@ -251,7 +251,7 @@ impl Stub {
fakeserver
.handle_request_response(
monitor_post,
Some(&PodMonitor::new("test", PodMonitorSpec::default())),
Some(&PodMonitor::new("test", PodMonitorCrd::default())),
)
.await
.expect("pod monitor should create");
Expand Down

0 comments on commit 01fa239

Please sign in to comment.