|
5 | 5 | "fmt"
|
6 | 6 | "sync"
|
7 | 7 |
|
| 8 | + "k8s.io/apimachinery/pkg/api/meta" |
8 | 9 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
9 | 10 |
|
10 | 11 | autogen_client "github.com/kagent-dev/kagent/go/autogen/client"
|
@@ -87,21 +88,22 @@ func (a *autogenReconciler) reconcileAgentStatus(ctx context.Context, agent *v1a
|
87 | 88 | status = metav1.ConditionTrue
|
88 | 89 | reason = "AgentReconciled"
|
89 | 90 | }
|
90 |
| - agent.Status = v1alpha1.AgentStatus{ |
91 |
| - ObservedGeneration: agent.Generation, |
92 |
| - Conditions: []metav1.Condition{{ |
93 |
| - Type: v1alpha1.AgentConditionTypeAccepted, |
94 |
| - Status: status, |
95 |
| - LastTransitionTime: metav1.Now(), |
96 |
| - Reason: reason, |
97 |
| - Message: message, |
98 |
| - }}, |
99 |
| - } |
100 | 91 |
|
101 |
| - if err := a.kube.Status().Update(ctx, agent); err != nil { |
102 |
| - return fmt.Errorf("failed to update agent status: %v", err) |
103 |
| - } |
| 92 | + conditionChanged := meta.SetStatusCondition(&agent.Status.Conditions, metav1.Condition{ |
| 93 | + Type: v1alpha1.AgentConditionTypeAccepted, |
| 94 | + Status: status, |
| 95 | + LastTransitionTime: metav1.Now(), |
| 96 | + Reason: reason, |
| 97 | + Message: message, |
| 98 | + }) |
104 | 99 |
|
| 100 | + // update the status if it has changed or the generation has changed |
| 101 | + if conditionChanged || agent.Status.ObservedGeneration != agent.Generation { |
| 102 | + agent.Status.ObservedGeneration = agent.Generation |
| 103 | + if err := a.kube.Status().Update(ctx, agent); err != nil { |
| 104 | + return fmt.Errorf("failed to update agent status: %v", err) |
| 105 | + } |
| 106 | + } |
105 | 107 | return nil
|
106 | 108 | }
|
107 | 109 |
|
@@ -147,21 +149,22 @@ func (a *autogenReconciler) reconcileModelConfigStatus(ctx context.Context, mode
|
147 | 149 | status = metav1.ConditionTrue
|
148 | 150 | reason = "ModelConfigReconciled"
|
149 | 151 | }
|
150 |
| - modelConfig.Status = v1alpha1.ModelConfigStatus{ |
151 |
| - ObservedGeneration: modelConfig.Generation, |
152 |
| - Conditions: []metav1.Condition{{ |
153 |
| - Type: v1alpha1.ModelConfigConditionTypeAccepted, |
154 |
| - Status: status, |
155 |
| - LastTransitionTime: metav1.Now(), |
156 |
| - Reason: reason, |
157 |
| - Message: message, |
158 |
| - }}, |
159 |
| - } |
160 | 152 |
|
161 |
| - if err := a.kube.Status().Update(ctx, modelConfig); err != nil { |
162 |
| - return fmt.Errorf("failed to update model config status: %v", err) |
163 |
| - } |
| 153 | + conditionChanged := meta.SetStatusCondition(&modelConfig.Status.Conditions, metav1.Condition{ |
| 154 | + Type: v1alpha1.ModelConfigConditionTypeAccepted, |
| 155 | + Status: status, |
| 156 | + LastTransitionTime: metav1.Now(), |
| 157 | + Reason: reason, |
| 158 | + Message: message, |
| 159 | + }) |
164 | 160 |
|
| 161 | + // update the status if it has changed or the generation has changed |
| 162 | + if conditionChanged || modelConfig.Status.ObservedGeneration != modelConfig.Generation { |
| 163 | + modelConfig.Status.ObservedGeneration = modelConfig.Generation |
| 164 | + if err := a.kube.Status().Update(ctx, modelConfig); err != nil { |
| 165 | + return fmt.Errorf("failed to update model config status: %v", err) |
| 166 | + } |
| 167 | + } |
165 | 168 | return nil
|
166 | 169 | }
|
167 | 170 |
|
@@ -189,19 +192,20 @@ func (a *autogenReconciler) reconcileTeamStatus(ctx context.Context, team *v1alp
|
189 | 192 | status = metav1.ConditionTrue
|
190 | 193 | reason = "TeamReconciled"
|
191 | 194 | }
|
192 |
| - team.Status = v1alpha1.TeamStatus{ |
193 |
| - ObservedGeneration: team.Generation, |
194 |
| - Conditions: []metav1.Condition{{ |
195 |
| - Type: v1alpha1.TeamConditionTypeAccepted, |
196 |
| - Status: status, |
197 |
| - LastTransitionTime: metav1.Now(), |
198 |
| - Reason: reason, |
199 |
| - Message: message, |
200 |
| - }}, |
201 |
| - } |
202 | 195 |
|
203 |
| - if err := a.kube.Status().Update(ctx, team); err != nil { |
204 |
| - return fmt.Errorf("failed to update team status: %v", err) |
| 196 | + conditionChanged := meta.SetStatusCondition(&team.Status.Conditions, metav1.Condition{ |
| 197 | + Type: v1alpha1.TeamConditionTypeAccepted, |
| 198 | + Status: status, |
| 199 | + LastTransitionTime: metav1.Now(), |
| 200 | + Reason: reason, |
| 201 | + Message: message, |
| 202 | + }) |
| 203 | + |
| 204 | + if conditionChanged || team.Status.ObservedGeneration != team.Generation { |
| 205 | + team.Status.ObservedGeneration = team.Generation |
| 206 | + if err := a.kube.Status().Update(ctx, team); err != nil { |
| 207 | + return fmt.Errorf("failed to update team status: %v", err) |
| 208 | + } |
205 | 209 | }
|
206 | 210 |
|
207 | 211 | return nil
|
|
0 commit comments