@@ -7,24 +7,170 @@ import (
77 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
88)
99
10+ // Condition types
1011const (
11- FunctionConditionDeployed = "Deployed"
12+ // TypeReady indicates overall readiness (summary condition)
13+ TypeReady = "Ready"
14+
15+ // TypeSourceReady indicates git source was cloned successfully
16+ TypeSourceReady = "SourceReady"
17+
18+ // TypeDeployed indicates function is deployed
19+ TypeDeployed = "Deployed"
20+
21+ // TypeMiddlewareUpToDate indicates middleware is current
22+ TypeMiddlewareUpToDate = "MiddlewareUpToDate"
1223)
1324
14- func (s * FunctionStatus ) MarkDeploySucceeded () bool {
15- return meta .SetStatusCondition (& s .Conditions , metav1.Condition {
16- Type : FunctionConditionDeployed ,
17- Status : metav1 .ConditionTrue ,
18- Reason : "Succeeded" ,
19- Message : "Function has been successfully deployed" ,
25+ var FunctionsConditions = []string {
26+ TypeSourceReady ,
27+ TypeDeployed ,
28+ TypeMiddlewareUpToDate ,
29+ }
30+
31+ // InitializeConditions resets all conditions to ensure a fresh start for each reconcile.
32+ // This prevents stale conditions from previous reconciles from persisting.
33+ func (f * Function ) InitializeConditions () {
34+ f .Status .Conditions = []metav1.Condition {}
35+ for _ , condition := range FunctionsConditions {
36+ meta .SetStatusCondition (& f .Status .Conditions , metav1.Condition {
37+ Type : condition ,
38+ Status : metav1 .ConditionUnknown ,
39+ Reason : "unknown" ,
40+ ObservedGeneration : f .Generation ,
41+ })
42+ }
43+
44+ meta .SetStatusCondition (& f .Status .Conditions , metav1.Condition {
45+ Type : TypeReady ,
46+ Status : metav1 .ConditionUnknown ,
47+ })
48+ }
49+
50+ func (f * Function ) CalculateReadyCondition () {
51+ allReady := true
52+ reason := ""
53+ message := ""
54+ for _ , condition := range f .Status .Conditions {
55+ if condition .Type != TypeReady && condition .Status == metav1 .ConditionFalse {
56+ allReady = false
57+ reason = condition .Reason
58+ message = condition .Message
59+ continue
60+ }
61+ }
62+
63+ if allReady {
64+ f .MarkReady ()
65+ } else {
66+ f .MarkNotReady (reason , "%s" , message )
67+ }
68+ }
69+
70+ // Ready condition helpers
71+
72+ func (f * Function ) MarkReady () bool {
73+ return meta .SetStatusCondition (& f .Status .Conditions , metav1.Condition {
74+ Type : TypeReady ,
75+ Status : metav1 .ConditionTrue ,
76+ Reason : "ReconcileSucceeded" ,
77+ Message : "Function is ready" ,
78+ ObservedGeneration : f .Generation ,
79+ })
80+ }
81+
82+ func (f * Function ) MarkNotReady (reason , messageFormat string , messageA ... interface {}) bool {
83+ return meta .SetStatusCondition (& f .Status .Conditions , metav1.Condition {
84+ Type : TypeReady ,
85+ Status : metav1 .ConditionFalse ,
86+ Reason : reason ,
87+ Message : fmt .Sprintf (messageFormat , messageA ... ),
88+ ObservedGeneration : f .Generation ,
89+ })
90+ }
91+
92+ func (f * Function ) MarkTerminating () bool {
93+ return meta .SetStatusCondition (& f .Status .Conditions , metav1.Condition {
94+ Type : TypeReady ,
95+ Status : metav1 .ConditionFalse ,
96+ Reason : "FinalizerOperations" ,
97+ Message : "Performing cleanup operations before deletion" ,
98+ ObservedGeneration : f .Generation ,
99+ })
100+ }
101+
102+ func (f * Function ) MarkFinalizeFailed (err error ) bool {
103+ return meta .SetStatusCondition (& f .Status .Conditions , metav1.Condition {
104+ Type : TypeReady ,
105+ Status : metav1 .ConditionFalse ,
106+ Reason : "FinalizeFailed" ,
107+ Message : fmt .Sprintf ("Failed to finalize: %s" , err .Error ()),
108+ ObservedGeneration : f .Generation ,
109+ })
110+ }
111+
112+ // Source condition helpers
113+
114+ func (f * Function ) MarkSourceReady () bool {
115+ return meta .SetStatusCondition (& f .Status .Conditions , metav1.Condition {
116+ Type : TypeSourceReady ,
117+ Status : metav1 .ConditionTrue ,
118+ Reason : "CloneSucceeded" ,
119+ Message : "Source code cloned and metadata read successfully" ,
120+ ObservedGeneration : f .Generation ,
121+ })
122+ }
123+
124+ func (f * Function ) MarkSourceNotReady (reason , messageFormat string , messageA ... interface {}) bool {
125+ return meta .SetStatusCondition (& f .Status .Conditions , metav1.Condition {
126+ Type : TypeSourceReady ,
127+ Status : metav1 .ConditionFalse ,
128+ Reason : reason ,
129+ Message : fmt .Sprintf (messageFormat , messageA ... ),
130+ ObservedGeneration : f .Generation ,
131+ })
132+ }
133+
134+ // Deployment condition helpers
135+
136+ func (f * Function ) MarkDeployReady () bool {
137+ return meta .SetStatusCondition (& f .Status .Conditions , metav1.Condition {
138+ Type : TypeDeployed ,
139+ Status : metav1 .ConditionTrue ,
140+ Reason : "DeploySucceeded" ,
141+ Message : "Function deployed successfully" ,
142+ ObservedGeneration : f .Generation ,
143+ })
144+ }
145+
146+ func (f * Function ) MarkDeployNotReady (reason , messageFormat string , messageA ... interface {}) bool {
147+ return meta .SetStatusCondition (& f .Status .Conditions , metav1.Condition {
148+ Type : TypeDeployed ,
149+ Status : metav1 .ConditionFalse ,
150+ Reason : reason ,
151+ Message : fmt .Sprintf (messageFormat , messageA ... ),
152+ ObservedGeneration : f .Generation ,
153+ })
154+ }
155+
156+ // Middleware condition helpers
157+
158+ func (f * Function ) MarkMiddlewareUpToDate () bool {
159+ return meta .SetStatusCondition (& f .Status .Conditions , metav1.Condition {
160+ Type : TypeMiddlewareUpToDate ,
161+ Status : metav1 .ConditionTrue ,
162+ Reason : "UpToDate" ,
163+ Message : "Middleware is up to date" ,
164+ ObservedGeneration : f .Generation ,
20165 })
21166}
22167
23- func (s * FunctionStatus ) MarkDeployFailed (reason , messageFormat string , messageA ... interface {}) bool {
24- return meta .SetStatusCondition (& s .Conditions , metav1.Condition {
25- Type : FunctionConditionDeployed ,
26- Status : metav1 .ConditionFalse ,
27- Reason : reason ,
28- Message : fmt .Sprintf (messageFormat , messageA ... ),
168+ func (f * Function ) MarkMiddlewareNotUpToDate (reason , messageFormat string , messageA ... interface {}) bool {
169+ return meta .SetStatusCondition (& f .Status .Conditions , metav1.Condition {
170+ Type : TypeMiddlewareUpToDate ,
171+ Status : metav1 .ConditionFalse ,
172+ Reason : reason ,
173+ Message : fmt .Sprintf (messageFormat , messageA ... ),
174+ ObservedGeneration : f .Generation ,
29175 })
30176}
0 commit comments