-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathevent.rs
More file actions
74 lines (68 loc) · 2.12 KB
/
event.rs
File metadata and controls
74 lines (68 loc) · 2.12 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use snafu::{ResultExt, Snafu};
use stackable_operator::{
k8s_openapi::api::core::v1::ObjectReference,
kube::runtime::events::{Event, EventType},
};
use strum::{EnumDiscriminants, IntoStaticStr};
use crate::{
crd::{HdfsNodeRole, v1alpha1},
hdfs_controller::Ctx,
};
#[derive(Snafu, Debug, EnumDiscriminants)]
#[strum_discriminants(derive(IntoStaticStr))]
pub enum Error {
#[snafu(display("failed to publish event"))]
PublishEvent {
source: stackable_operator::kube::Error,
},
}
/// Publish a Kubernetes warning event for the `hdfs` cluster resource.
pub async fn publish_warning_event(
ctx: &Ctx,
hdfs_object_ref: &ObjectReference,
action: String,
reason: String,
message: String,
) -> Result<(), Error> {
ctx.event_recorder
.publish(
&Event {
action,
reason,
note: Some(message),
type_: EventType::Warning,
secondary: None,
},
hdfs_object_ref,
)
.await
.context(PublishEventSnafu)
}
pub fn build_invalid_replica_message(
hdfs: &v1alpha1::HdfsCluster,
role: &HdfsNodeRole,
dfs_replication: u8,
) -> Option<String> {
let replicas: u16 = hdfs
.rolegroup_ref_and_replicas(role)
.iter()
.map(|tuple| tuple.1)
.sum();
let role_name = role.to_string();
let min_replicas = role.min_replicas();
if replicas < min_replicas {
Some(format!(
"{role_name}: only has {replicas} replicas configured, it is strongly recommended to use at least [{min_replicas}]"
))
} else if !role.replicas_can_be_even() && replicas.is_multiple_of(2) {
Some(format!(
"{role_name}: currently has an even number of replicas [{replicas}], but should always have an odd number to ensure quorum"
))
} else if !role.replicas_can_be_even() && replicas < dfs_replication as u16 {
Some(format!(
"{role_name}: HDFS replication factor [{dfs_replication}] is configured greater than data node replicas [{replicas}]"
))
} else {
None
}
}