Skip to content

[Merged by Bors] - Add status field support #571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
30191c8
added status mod
razvan Mar 14, 2023
c0c36c9
wip
razvan Mar 15, 2023
5a80e16
wip
razvan Mar 20, 2023
46ac63d
reset cluster_resources.rs to main version
razvan Mar 21, 2023
35fdb88
wip
maltesander Mar 21, 2023
e130737
fix yaml representation and some refactoring
maltesander Mar 21, 2023
854a283
refactoring
maltesander Mar 21, 2023
867f12c
refactor for simplification
razvan Mar 22, 2023
0548543
sync sts with daemon sets.
razvan Mar 22, 2023
8e0a1b0
Added clusterconditionset
razvan Mar 22, 2023
ccd7985
make ClusterConditionSet vector size depend on ClusterConditionType e…
maltesander Mar 22, 2023
cfea057
some refactoring
maltesander Mar 22, 2023
26d6b44
added one test
razvan Mar 22, 2023
8788e63
removed clones
maltesander Mar 22, 2023
62268eb
Merge remote-tracking branch 'origin/feat/status' into feat/status
maltesander Mar 22, 2023
3acce6f
Use vec! macro to initialize conditions.
razvan Mar 23, 2023
f20a05e
refactoring & comments
maltesander Mar 23, 2023
b2ba70a
move status condition definitions to correct mod definition
maltesander Mar 23, 2023
eda6d33
wip
maltesander Mar 23, 2023
a2ecfd2
merge/combine and fix tests.
razvan Mar 23, 2023
94aec8d
Use callback instead of bool parameter.
razvan Mar 23, 2023
9fdcd3c
Fix doctest
razvan Mar 24, 2023
280d150
update changelog
razvan Mar 24, 2023
aa6d011
added another test case
maltesander Mar 24, 2023
f5c4528
update pr number
razvan Mar 24, 2023
347f788
more tests
maltesander Mar 24, 2023
097fe83
Merge remote-tracking branch 'origin/feat/status' into feat/status
maltesander Mar 24, 2023
2796ee9
clippy
maltesander Mar 24, 2023
fb24f72
added tests for statefulset condition builder
maltesander Mar 24, 2023
f62bcd9
added tests for daemonset condition builder
maltesander Mar 24, 2023
419cdb9
added comment for daemonset and statefulset condition builder that on…
maltesander Mar 24, 2023
b5ff959
Merge remote-tracking branch 'origin/main' into feat/status
maltesander Mar 24, 2023
cdaffc3
Rename Paused to ReconciliationPaused.
razvan Mar 27, 2023
ef52649
Update availability tests for daemonsets and statefulsets.
razvan Mar 29, 2023
600837d
Merge remote-tracking branch 'origin/main' into feat/status
maltesander Mar 30, 2023
b151030
use ClusterConditionType as index
maltesander Mar 30, 2023
063140a
added ClusterOperationsConditionBuilder
maltesander Mar 30, 2023
842bec8
improved docs
maltesander Mar 30, 2023
0b61613
added some more inline comments
maltesander Mar 31, 2023
ef2462b
implemented From<ClusterConditionType> for usize
maltesander Mar 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added ClusterOperationsConditionBuilder
  • Loading branch information
maltesander committed Mar 30, 2023
commit 063140aae19d476167c13668211cfcd03ce124d3
1 change: 1 addition & 0 deletions src/status/condition/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod daemonset;
pub mod operations;
pub mod statefulset;

use chrono::Utc;
Expand Down
146 changes: 146 additions & 0 deletions src/status/condition/operations.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
use crate::commons::cluster_operation::ClusterOperation;
use crate::status::condition::{
ClusterCondition, ClusterConditionSet, ClusterConditionStatus, ClusterConditionType,
ConditionBuilder,
};

#[derive(Debug, Clone)]
pub struct ClusterOperationsConditionBuilder<'a> {
cluster_operation: &'a ClusterOperation,
}

impl<'a> ConditionBuilder for ClusterOperationsConditionBuilder<'a> {
fn build_conditions(&self) -> ClusterConditionSet {
vec![self.reconciliation_paused(), self.cluster_stopped()].into()
}
}

impl<'a> ClusterOperationsConditionBuilder<'a> {
pub fn new(cluster_operation: &'a ClusterOperation) -> Self {
Self { cluster_operation }
}

fn reconciliation_paused(&self) -> ClusterCondition {
let status = if self.cluster_operation.reconciliation_paused {
ClusterConditionStatus::True
} else {
ClusterConditionStatus::False
};

let message = match status {
ClusterConditionStatus::True => {
"The cluster reconciliation is paused. Only the cluster status is reconciled."
.to_string()
}
ClusterConditionStatus::False => "The cluster is reconciled normally.".to_string(),
ClusterConditionStatus::Unknown => {
"The cluster reconciliation status could not be determined.".to_string()
}
};

ClusterCondition {
reason: None,
message: Some(message),
status,
type_: ClusterConditionType::ReconciliationPaused,
last_transition_time: None,
last_update_time: None,
}
}

fn cluster_stopped(&self) -> ClusterCondition {
let status =
if self.cluster_operation.stopped && self.cluster_operation.reconciliation_paused {
ClusterConditionStatus::Unknown
} else if self.cluster_operation.stopped {
ClusterConditionStatus::True
} else {
ClusterConditionStatus::False
};

let message = match status {
ClusterConditionStatus::True => {
"The cluster is stopped.".to_string()
}
ClusterConditionStatus::False => {
"The cluster is running.".to_string()
}
ClusterConditionStatus::Unknown => {
"The cluster stopped status could not be determined. This might be due to the cluster reconciliation being paused.".to_string()
}
};

ClusterCondition {
reason: None,
message: Some(message),
status,
type_: ClusterConditionType::Stopped,
last_transition_time: None,
last_update_time: None,
}
}
}

#[cfg(test)]
mod test {
use super::*;
use rstest::*;

#[rstest]
#[case::not_paused_not_stopped(
false,
false,
ClusterConditionStatus::False,
ClusterConditionStatus::False
)]
#[case::paused_not_stopped(
true,
false,
ClusterConditionStatus::True,
ClusterConditionStatus::False
)]
#[case::not_paused_stopped(
false,
true,
ClusterConditionStatus::False,
ClusterConditionStatus::True
)]
#[case::paused_stopped(
true,
true,
ClusterConditionStatus::True,
ClusterConditionStatus::Unknown
)]
fn test_cluster_operation_condition(
#[case] reconciliation_paused: bool,
#[case] stopped: bool,
#[case] expected_paused_status: ClusterConditionStatus,
#[case] expected_stopped_status: ClusterConditionStatus,
) {
let cluster_operation = ClusterOperation {
reconciliation_paused,
stopped,
};

let op_condition_builder = ClusterOperationsConditionBuilder::new(&cluster_operation);
let conditions = op_condition_builder.build_conditions();

let got = conditions
.conditions
.get(ClusterConditionType::ReconciliationPaused as usize)
.cloned()
.unwrap()
.unwrap();

assert_eq!(got.status, expected_paused_status);

let got = conditions
.conditions
.get(ClusterConditionType::Stopped as usize)
.cloned()
.unwrap()
.unwrap();

assert_eq!(got.status, expected_stopped_status);
}
}