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 :: { AttestationKeyStatus , TrustedExecutionClusterStatus } ;
7+ use trusted_cluster_operator_lib:: { condition_status, conditions:: * , transition_time } ;
88
9- pub fn known_trustee_address_condition ( known : bool , generation : Option < i64 > ) -> Condition {
9+ pub fn known_trustee_address_condition (
10+ known : bool ,
11+ generation : Option < i64 > ,
12+ existing_status : & Option < TrustedExecutionClusterStatus > ,
13+ ) -> Condition {
1014 let err = "No publicTrusteeAddr specified. Components can deploy, \
1115 but register-server will not be able to point to Trustee until you add an address";
1216 let ( reason, message) = match known {
1317 true => ( KNOWN_TRUSTEE_ADDRESS_REASON , "" ) ,
1418 false => ( UNKNOWN_TRUSTEE_ADDRESS_REASON , err) ,
1519 } ;
20+ let type_ = KNOWN_TRUSTEE_ADDRESS_CONDITION ;
21+ let status = condition_status ( known) ;
1622 Condition {
17- type_ : KNOWN_TRUSTEE_ADDRESS_CONDITION . to_string ( ) ,
18- status : condition_status ( known) ,
23+ type_ : type_. to_string ( ) ,
1924 reason : reason. to_string ( ) ,
2025 message : message. to_string ( ) ,
21- last_transition_time : Time ( Timestamp :: now ( ) ) ,
26+ last_transition_time : transition_time ( existing_status, type_, & status) ,
27+ status,
2228 observed_generation : generation,
2329 }
2430}
2531
26- pub fn installed_condition ( reason : & str , generation : Option < i64 > ) -> Condition {
32+ pub fn installed_condition (
33+ reason : & str ,
34+ generation : Option < i64 > ,
35+ existing_status : & Option < TrustedExecutionClusterStatus > ,
36+ ) -> Condition {
37+ let status = condition_status ( reason == INSTALLED_REASON ) ;
38+ let type_ = INSTALLED_CONDITION ;
2739 Condition {
28- type_ : INSTALLED_CONDITION . to_string ( ) ,
29- status : condition_status ( reason == INSTALLED_REASON ) ,
40+ type_ : type_. to_string ( ) ,
3041 reason : reason. to_string ( ) ,
3142 message : match reason {
3243 NOT_INSTALLED_REASON_NON_UNIQUE => {
@@ -38,15 +49,21 @@ pub fn installed_condition(reason: &str, generation: Option<i64>) -> Condition {
3849 _ => "" ,
3950 }
4051 . to_string ( ) ,
41- last_transition_time : Time ( Timestamp :: now ( ) ) ,
52+ last_transition_time : transition_time ( existing_status, type_, & status) ,
53+ status,
4254 observed_generation : generation,
4355 }
4456}
4557
46- pub fn attestation_key_approved_condition ( reason : & str , generation : Option < i64 > ) -> Condition {
58+ pub fn attestation_key_approved_condition (
59+ reason : & str ,
60+ generation : Option < i64 > ,
61+ existing_status : & Option < AttestationKeyStatus > ,
62+ ) -> Condition {
63+ let status = condition_status ( reason == ATTESTATION_KEY_MACHINE_APPROVE ) ;
64+ let type_ = ATTESTATION_KEY_APPROVED_CONDITION ;
4765 Condition {
48- type_ : ATTESTATION_KEY_APPROVED_CONDITION . to_string ( ) ,
49- status : condition_status ( reason == ATTESTATION_KEY_MACHINE_APPROVE ) ,
66+ type_ : type_. to_string ( ) ,
5067 reason : reason. to_string ( ) ,
5168 message : match reason {
5269 ATTESTATION_KEY_MACHINE_APPROVE => {
@@ -55,7 +72,8 @@ pub fn attestation_key_approved_condition(reason: &str, generation: Option<i64>)
5572 _ => "" ,
5673 }
5774 . to_string ( ) ,
58- last_transition_time : Time ( Timestamp :: now ( ) ) ,
75+ last_transition_time : transition_time ( existing_status, type_, & status) ,
76+ status,
5977 observed_generation : generation,
6078 }
6179}
0 commit comments