Skip to content

Commit

Permalink
Rename Pdb -> PdbConfig, PdbBuilder -> PodDisruptionBudgetBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernauer committed Sep 22, 2023
1 parent 166210e commit 73b838c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 29 deletions.
52 changes: 29 additions & 23 deletions src/builder/pdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use k8s_openapi::{
use kube::{Resource, ResourceExt};

#[derive(Debug, Default)]
pub struct PdbBuilder<ObjectMeta, LabelSelector, Constraints> {
pub struct PodDisruptionBudgetBuilder<ObjectMeta, LabelSelector, Constraints> {
metadata: ObjectMeta,
selector: LabelSelector,
/// We intentionally only support fixed numbers, no percentage, see ADR 30 on Pod disruptions for details.
Expand All @@ -27,9 +27,9 @@ pub struct PdbBuilder<ObjectMeta, LabelSelector, Constraints> {
_constraints: Constraints,
}

impl PdbBuilder<(), (), ()> {
impl PodDisruptionBudgetBuilder<(), (), ()> {
pub fn new() -> Self {
PdbBuilder::default()
PodDisruptionBudgetBuilder::default()
}

pub fn new_with_role<T: Resource<DynamicType = ()>>(
Expand All @@ -38,7 +38,7 @@ impl PdbBuilder<(), (), ()> {
role: &str,
operator_name: &str,
controller_name: &str,
) -> OperatorResult<PdbBuilder<ObjectMeta, LabelSelector, ()>> {
) -> OperatorResult<PodDisruptionBudgetBuilder<ObjectMeta, LabelSelector, ()>> {
let role_selector_labels = role_selector_labels(owner, app_name, role);
let metadata = ObjectMetaBuilder::new()
.namespace_opt(owner.namespace())
Expand All @@ -51,21 +51,21 @@ impl PdbBuilder<(), (), ()> {
)
.build();

Ok(PdbBuilder {
Ok(PodDisruptionBudgetBuilder {
metadata,
selector: LabelSelector {
match_expressions: None,
match_labels: Some(role_selector_labels),
},
..PdbBuilder::default()
..PodDisruptionBudgetBuilder::default()
})
}

pub fn new_with_metadata(
self,
metadata: impl Into<ObjectMeta>,
) -> PdbBuilder<ObjectMeta, (), ()> {
PdbBuilder {
) -> PodDisruptionBudgetBuilder<ObjectMeta, (), ()> {
PodDisruptionBudgetBuilder {
metadata: metadata.into(),
selector: self.selector,
max_unavailable: self.max_unavailable,
Expand All @@ -75,12 +75,12 @@ impl PdbBuilder<(), (), ()> {
}
}

impl PdbBuilder<ObjectMeta, (), ()> {
impl PodDisruptionBudgetBuilder<ObjectMeta, (), ()> {
pub fn with_selector(
self,
selector: LabelSelector,
) -> PdbBuilder<ObjectMeta, LabelSelector, ()> {
PdbBuilder {
) -> PodDisruptionBudgetBuilder<ObjectMeta, LabelSelector, ()> {
PodDisruptionBudgetBuilder {
metadata: self.metadata,
selector,
max_unavailable: self.max_unavailable,
Expand All @@ -90,12 +90,12 @@ impl PdbBuilder<ObjectMeta, (), ()> {
}
}

impl PdbBuilder<ObjectMeta, LabelSelector, ()> {
impl PodDisruptionBudgetBuilder<ObjectMeta, LabelSelector, ()> {
pub fn with_max_unavailable(
self,
max_unavailable: u16,
) -> PdbBuilder<ObjectMeta, LabelSelector, bool> {
PdbBuilder {
) -> PodDisruptionBudgetBuilder<ObjectMeta, LabelSelector, bool> {
PodDisruptionBudgetBuilder {
metadata: self.metadata,
selector: self.selector,
max_unavailable: Some(max_unavailable),
Expand All @@ -111,8 +111,8 @@ impl PdbBuilder<ObjectMeta, LabelSelector, ()> {
pub fn with_min_available(
self,
min_available: u16,
) -> PdbBuilder<ObjectMeta, LabelSelector, bool> {
PdbBuilder {
) -> PodDisruptionBudgetBuilder<ObjectMeta, LabelSelector, bool> {
PodDisruptionBudgetBuilder {
metadata: self.metadata,
selector: self.selector,
max_unavailable: self.max_unavailable,
Expand All @@ -122,7 +122,7 @@ impl PdbBuilder<ObjectMeta, LabelSelector, ()> {
}
}

impl PdbBuilder<ObjectMeta, LabelSelector, bool> {
impl PodDisruptionBudgetBuilder<ObjectMeta, LabelSelector, bool> {
pub fn build(self) -> PodDisruptionBudget {
PodDisruptionBudget {
metadata: self.metadata,
Expand Down Expand Up @@ -152,12 +152,12 @@ mod test {

use crate::builder::{ObjectMetaBuilder, OwnerReferenceBuilder};

use super::PdbBuilder;
use super::PodDisruptionBudgetBuilder;

#[test]
pub fn test_normal_build() {
#[allow(deprecated)]
let pdb = PdbBuilder::new()
let pdb = PodDisruptionBudgetBuilder::new()
.new_with_metadata(
ObjectMetaBuilder::new()
.namespace("default")
Expand Down Expand Up @@ -218,10 +218,16 @@ mod test {
let role = "worker";
let operator_name = "trino.stackable.tech";
let controller_name = "trino-operator-trino-controller";
let pdb = PdbBuilder::new_with_role(&trino, app_name, role, operator_name, controller_name)
.unwrap()
.with_max_unavailable(2)
.build();
let pdb = PodDisruptionBudgetBuilder::new_with_role(
&trino,
app_name,
role,
operator_name,
controller_name,
)
.unwrap()
.with_max_unavailable(2)
.build();

assert_eq!(
pdb,
Expand Down
4 changes: 2 additions & 2 deletions src/commons/pdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Pdb {
pub struct PdbConfig {
/// Wether a PodDisruptionBudget should be written out for this role.
/// Disabling this enables you to specify you own - custom - one.
/// Defaults to true.
Expand All @@ -20,7 +20,7 @@ fn default_pdb_enabled() -> bool {
true
}

impl Default for Pdb {
impl Default for PdbConfig {
fn default() -> Self {
Self {
enabled: true,
Expand Down
8 changes: 4 additions & 4 deletions src/role_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ use std::{
};

use crate::{
commons::pdb::Pdb,
commons::pdb::PdbConfig,
config::{
fragment::{self, FromFragment},
merge::Merge,
Expand Down Expand Up @@ -173,10 +173,10 @@ fn config_schema_default() -> serde_json::Value {
pub struct Role<T> {
#[serde(flatten)]
pub config: CommonConfiguration<T>,

#[serde(default)]
pub role_config: RoleConfig,

pub role_groups: HashMap<String, RoleGroup<T>>,
}

Expand Down Expand Up @@ -226,7 +226,7 @@ impl<T: Configuration + 'static> Role<T> {
#[serde(rename_all = "camelCase")]
pub struct RoleConfig {
#[serde(default)]
pub pod_disruption_budget: Pdb,
pub pod_disruption_budget: PdbConfig,
}

#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Serialize)]
Expand Down

0 comments on commit 73b838c

Please sign in to comment.