-
-
Notifications
You must be signed in to change notification settings - Fork 16
[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
Closed
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
30191c8
added status mod
razvan c0c36c9
wip
razvan 5a80e16
wip
razvan 46ac63d
reset cluster_resources.rs to main version
razvan 35fdb88
wip
maltesander e130737
fix yaml representation and some refactoring
maltesander 854a283
refactoring
maltesander 867f12c
refactor for simplification
razvan 0548543
sync sts with daemon sets.
razvan 8e0a1b0
Added clusterconditionset
razvan ccd7985
make ClusterConditionSet vector size depend on ClusterConditionType e…
maltesander cfea057
some refactoring
maltesander 26d6b44
added one test
razvan 8788e63
removed clones
maltesander 62268eb
Merge remote-tracking branch 'origin/feat/status' into feat/status
maltesander 3acce6f
Use vec! macro to initialize conditions.
razvan f20a05e
refactoring & comments
maltesander b2ba70a
move status condition definitions to correct mod definition
maltesander eda6d33
wip
maltesander a2ecfd2
merge/combine and fix tests.
razvan 94aec8d
Use callback instead of bool parameter.
razvan 9fdcd3c
Fix doctest
razvan 280d150
update changelog
razvan aa6d011
added another test case
maltesander f5c4528
update pr number
razvan 347f788
more tests
maltesander 097fe83
Merge remote-tracking branch 'origin/feat/status' into feat/status
maltesander 2796ee9
clippy
maltesander fb24f72
added tests for statefulset condition builder
maltesander f62bcd9
added tests for daemonset condition builder
maltesander 419cdb9
added comment for daemonset and statefulset condition builder that on…
maltesander b5ff959
Merge remote-tracking branch 'origin/main' into feat/status
maltesander cdaffc3
Rename Paused to ReconciliationPaused.
razvan ef52649
Update availability tests for daemonsets and statefulsets.
razvan 600837d
Merge remote-tracking branch 'origin/main' into feat/status
maltesander b151030
use ClusterConditionType as index
maltesander 063140a
added ClusterOperationsConditionBuilder
maltesander 842bec8
improved docs
maltesander 0b61613
added some more inline comments
maltesander ef2462b
implemented From<ClusterConditionType> for usize
maltesander File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
added ClusterOperationsConditionBuilder
- Loading branch information
commit 063140aae19d476167c13668211cfcd03ce124d3
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.