22//
33// SPDX-License-Identifier: MIT
44
5- use k8s_openapi:: apimachinery:: pkg:: apis:: meta:: v1:: { Condition , Time } ;
6- use k8s_openapi:: jiff:: Timestamp ;
7- use trusted_cluster_operator_lib:: { condition_status, conditions:: * } ;
5+ use k8s_openapi:: apimachinery:: pkg:: apis:: meta:: v1:: Condition ;
6+ use trusted_cluster_operator_lib:: {
7+ AttestationKeyStatus , TrustedExecutionClusterStatus , condition_status, conditions:: * , transition_time
8+ } ;
89
9- pub fn known_trustee_address_condition ( known : bool , generation : Option < i64 > ) -> Condition {
10+ pub fn known_trustee_address_condition (
11+ known : bool ,
12+ generation : Option < i64 > ,
13+ existing_status : & Option < TrustedExecutionClusterStatus > ,
14+ ) -> Condition {
1015 let err = "No publicTrusteeAddr specified. Components can deploy, \
1116 but register-server will not be able to point to Trustee until you add an address";
1217 let ( reason, message) = match known {
1318 true => ( KNOWN_TRUSTEE_ADDRESS_REASON , "" ) ,
1419 false => ( UNKNOWN_TRUSTEE_ADDRESS_REASON , err) ,
1520 } ;
21+ let type_ = KNOWN_TRUSTEE_ADDRESS_CONDITION ;
22+ let status = condition_status ( known) ;
1623 Condition {
17- type_ : KNOWN_TRUSTEE_ADDRESS_CONDITION . to_string ( ) ,
18- status : condition_status ( known) ,
24+ type_ : type_. to_string ( ) ,
1925 reason : reason. to_string ( ) ,
2026 message : message. to_string ( ) ,
21- last_transition_time : Time ( Timestamp :: now ( ) ) ,
27+ last_transition_time : transition_time ( existing_status, type_, & status) ,
28+ status,
2229 observed_generation : generation,
2330 }
2431}
2532
26- pub fn installed_condition ( reason : & str , generation : Option < i64 > ) -> Condition {
33+ pub fn installed_condition (
34+ reason : & str ,
35+ generation : Option < i64 > ,
36+ existing_status : & Option < TrustedExecutionClusterStatus > ,
37+ ) -> Condition {
38+ let status = condition_status ( reason == INSTALLED_REASON ) ;
39+ let type_ = INSTALLED_CONDITION ;
2740 Condition {
28- type_ : INSTALLED_CONDITION . to_string ( ) ,
29- status : condition_status ( reason == INSTALLED_REASON ) ,
41+ type_ : type_. to_string ( ) ,
3042 reason : reason. to_string ( ) ,
3143 message : match reason {
3244 NOT_INSTALLED_REASON_NON_UNIQUE => {
@@ -38,15 +50,21 @@ pub fn installed_condition(reason: &str, generation: Option<i64>) -> Condition {
3850 _ => "" ,
3951 }
4052 . to_string ( ) ,
41- last_transition_time : Time ( Timestamp :: now ( ) ) ,
53+ last_transition_time : transition_time ( existing_status, type_, & status) ,
54+ status,
4255 observed_generation : generation,
4356 }
4457}
4558
46- pub fn attestation_key_approved_condition ( reason : & str , generation : Option < i64 > ) -> Condition {
59+ pub fn attestation_key_approved_condition (
60+ reason : & str ,
61+ generation : Option < i64 > ,
62+ existing_status : & Option < AttestationKeyStatus > ,
63+ ) -> Condition {
64+ let status = condition_status ( reason == ATTESTATION_KEY_MACHINE_APPROVE ) ;
65+ let type_ = ATTESTATION_KEY_APPROVED_CONDITION ;
4766 Condition {
48- type_ : ATTESTATION_KEY_APPROVED_CONDITION . to_string ( ) ,
49- status : condition_status ( reason == ATTESTATION_KEY_MACHINE_APPROVE ) ,
67+ type_ : type_. to_string ( ) ,
5068 reason : reason. to_string ( ) ,
5169 message : match reason {
5270 ATTESTATION_KEY_MACHINE_APPROVE => {
@@ -55,7 +73,8 @@ pub fn attestation_key_approved_condition(reason: &str, generation: Option<i64>)
5573 _ => "" ,
5674 }
5775 . to_string ( ) ,
58- last_transition_time : Time ( Timestamp :: now ( ) ) ,
76+ last_transition_time : transition_time ( existing_status, type_, & status) ,
77+ status,
5978 observed_generation : generation,
6079 }
6180}
0 commit comments