@@ -10,8 +10,92 @@ import (
1010 "k8s.io/utils/pointer"
1111)
1212
13+ // StatusReason is a MixedCaps string representing the reason for a
14+ // status condition change.
15+ type StatusReason string
16+
17+ // The default set of status change reasons.
18+ const (
19+ ReasonEmpty StatusReason = ""
20+ ReasonSyncing StatusReason = "SyncingResources"
21+ ReasonSyncFailed StatusReason = "SyncingFailed"
22+ )
23+
24+ // statusProgressing sets the Progressing condition to True, with the given
25+ // reason and message, and sets both the Available and Failing conditions to
26+ // False.
27+ func (optr * Operator ) statusProgressing (reason StatusReason , message string ) error {
28+ conds := []osconfigv1.ClusterOperatorStatusCondition {
29+ {
30+ Type : osconfigv1 .OperatorProgressing ,
31+ Status : osconfigv1 .ConditionTrue ,
32+ Reason : string (reason ),
33+ Message : message ,
34+ },
35+ {
36+ Type : osconfigv1 .OperatorAvailable ,
37+ Status : osconfigv1 .ConditionFalse ,
38+ },
39+ {
40+ Type : osconfigv1 .OperatorFailing ,
41+ Status : osconfigv1 .ConditionFalse ,
42+ },
43+ }
44+
45+ return optr .syncStatus (conds )
46+ }
47+
48+ // statusAvailable sets the Available condition to True, with the given reason
49+ // and message, and sets both the Progressing and Failing conditions to False.
50+ func (optr * Operator ) statusAvailable (reason StatusReason , message string ) error {
51+ conds := []osconfigv1.ClusterOperatorStatusCondition {
52+ {
53+ Type : osconfigv1 .OperatorAvailable ,
54+ Status : osconfigv1 .ConditionTrue ,
55+ Reason : string (reason ),
56+ Message : message ,
57+ },
58+ {
59+ Type : osconfigv1 .OperatorProgressing ,
60+ Status : osconfigv1 .ConditionFalse ,
61+ },
62+
63+ {
64+ Type : osconfigv1 .OperatorFailing ,
65+ Status : osconfigv1 .ConditionFalse ,
66+ },
67+ }
68+
69+ return optr .syncStatus (conds )
70+ }
71+
72+ // statusFailing sets the Failing condition to True, with the given reason and
73+ // message, and sets the Progressing condition to False, and the Available
74+ // condition to True. This indicates that the operator is present and may be
75+ // partially functioning, but is in a degraded or failing state.
76+ func (optr * Operator ) statusFailing (reason StatusReason , message string ) error {
77+ conds := []osconfigv1.ClusterOperatorStatusCondition {
78+ {
79+ Type : osconfigv1 .OperatorFailing ,
80+ Status : osconfigv1 .ConditionTrue ,
81+ Reason : string (reason ),
82+ Message : message ,
83+ },
84+ {
85+ Type : osconfigv1 .OperatorProgressing ,
86+ Status : osconfigv1 .ConditionFalse ,
87+ },
88+ {
89+ Type : osconfigv1 .OperatorAvailable ,
90+ Status : osconfigv1 .ConditionTrue ,
91+ },
92+ }
93+
94+ return optr .syncStatus (conds )
95+ }
96+
1397//syncStatus applies the new condition to the mao ClusterOperator object.
14- func (optr * Operator ) syncStatus (cond osconfigv1.ClusterOperatorStatusCondition ) error {
98+ func (optr * Operator ) syncStatus (conds [] osconfigv1.ClusterOperatorStatusCondition ) error {
1599 // to report the status of all the managed components.
16100 clusterOperator := & osconfigv1.ClusterOperator {
17101 ObjectMeta : metav1.ObjectMeta {
@@ -22,7 +106,11 @@ func (optr *Operator) syncStatus(cond osconfigv1.ClusterOperatorStatusCondition)
22106 Version : version .Raw ,
23107 },
24108 }
25- cvoresourcemerge .SetOperatorStatusCondition (& clusterOperator .Status .Conditions , cond )
109+
110+ for _ , c := range conds {
111+ cvoresourcemerge .SetOperatorStatusCondition (& clusterOperator .Status .Conditions , c )
112+ }
113+
26114 _ , _ , err := ApplyClusterOperator (optr .osClient .ConfigV1 (), clusterOperator )
27115 return err
28116}
0 commit comments