-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpdb.rs
More file actions
78 lines (70 loc) · 2.28 KB
/
pdb.rs
File metadata and controls
78 lines (70 loc) · 2.28 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
75
76
77
78
use snafu::{ResultExt, Snafu};
use stackable_operator::{
builder::pdb::PodDisruptionBudgetBuilder, client::Client, cluster_resources::ClusterResources,
commons::pdb::PdbConfig, kube::ResourceExt,
};
use crate::{
OPERATOR_NAME,
crd::{APP_NAME, HbaseRole, v1alpha1},
hbase_controller::HBASE_CONTROLLER_NAME,
};
#[derive(Snafu, Debug)]
pub enum Error {
#[snafu(display("Cannot create PodDisruptionBudget for role [{role}]"))]
CreatePdb {
source: stackable_operator::builder::pdb::Error,
role: String,
},
#[snafu(display("Cannot apply PodDisruptionBudget [{name}]"))]
ApplyPdb {
source: stackable_operator::cluster_resources::Error,
name: String,
},
}
pub async fn add_pdbs(
pdb: &PdbConfig,
hbase: &v1alpha1::HbaseCluster,
role: &HbaseRole,
client: &Client,
cluster_resources: &mut ClusterResources,
) -> Result<(), Error> {
if !pdb.enabled {
return Ok(());
}
let max_unavailable = pdb.max_unavailable.unwrap_or(match role {
HbaseRole::Master => max_unavailable_masters(),
HbaseRole::RegionServer => max_unavailable_region_servers(),
HbaseRole::RestServer => max_unavailable_rest_servers(),
});
let pdb = PodDisruptionBudgetBuilder::new_with_role(
hbase,
APP_NAME,
&role.to_string(),
OPERATOR_NAME,
HBASE_CONTROLLER_NAME,
)
.with_context(|_| CreatePdbSnafu {
role: role.to_string(),
})?
.with_max_unavailable(max_unavailable)
.build();
let pdb_name = pdb.name_any();
cluster_resources
.add(client, pdb)
.await
.with_context(|_| ApplyPdbSnafu { name: pdb_name })?;
Ok(())
}
fn max_unavailable_masters() -> u16 {
1
}
fn max_unavailable_region_servers() -> u16 {
1
}
fn max_unavailable_rest_servers() -> u16 {
// RestServers are stateless, we only need to make sure we have two available, so we don't have a single point of failure.
// However, users probably deploy multiple rest servers for both - availability and performance. As there is the use-case
// of having multiple RestServers for availability reasons, we need to be restrictive and stick to our `maxUnavailable: 1`
// for `Multiple replicas to increase availability` rolegroups guideline.
1
}