@@ -248,17 +248,9 @@ func (r *AgentRuntimeReconciler) Reconcile(ctx context.Context, req ctrl.Request
248248
249249 // 6.5. Discover linked skills from workload annotation (set by kagenti backend or user)
250250 fg := r .getFeatureGates ()
251+ var linkedSkills []string
251252 if fg .SkillDiscovery {
252- rt .Status .LinkedSkills = r .readLinkedSkills (ctx , rt )
253- if len (rt .Status .LinkedSkills ) > 0 {
254- r .setCondition (rt , ConditionTypeSkillsDiscovered , metav1 .ConditionTrue , "SkillsFound" ,
255- fmt .Sprintf ("%d linked skill(s) discovered from workload annotation" , len (rt .Status .LinkedSkills )))
256- } else {
257- meta .RemoveStatusCondition (& rt .Status .Conditions , ConditionTypeSkillsDiscovered )
258- }
259- } else {
260- rt .Status .LinkedSkills = nil
261- meta .RemoveStatusCondition (& rt .Status .Conditions , ConditionTypeSkillsDiscovered )
253+ linkedSkills = r .readLinkedSkills (ctx , rt )
262254 }
263255
264256 // 7. Count configured pods
@@ -267,12 +259,31 @@ func (r *AgentRuntimeReconciler) Reconcile(ctx context.Context, req ctrl.Request
267259 logger .V (1 ).Info ("Failed to count configured pods" , "error" , err )
268260 }
269261
270- // 8. Update status
262+ // 8. Update status (retry on conflict to preserve all conditions computed above)
271263 rt .Status .ConfiguredPods = configuredPods
272264 r .setPhase (rt , agentv1alpha1 .RuntimePhaseActive )
273265 r .setCondition (rt , ConditionTypeReady , metav1 .ConditionTrue , "Configured" ,
274266 fmt .Sprintf ("Workload %s configured with config-hash %s" , rt .Spec .TargetRef .Name , configResult .Hash [:12 ]))
275- if err := r .Status ().Update (ctx , rt ); err != nil {
267+ if fg .SkillDiscovery {
268+ rt .Status .LinkedSkills = linkedSkills
269+ if len (linkedSkills ) > 0 {
270+ r .setCondition (rt , ConditionTypeSkillsDiscovered , metav1 .ConditionTrue , "SkillsFound" ,
271+ fmt .Sprintf ("%d linked skill(s) discovered from workload annotation" , len (linkedSkills )))
272+ } else {
273+ meta .RemoveStatusCondition (& rt .Status .Conditions , ConditionTypeSkillsDiscovered )
274+ }
275+ } else {
276+ rt .Status .LinkedSkills = nil
277+ meta .RemoveStatusCondition (& rt .Status .Conditions , ConditionTypeSkillsDiscovered )
278+ }
279+ desired := rt .Status .DeepCopy ()
280+ if err := retry .RetryOnConflict (retry .DefaultRetry , func () error {
281+ if err := r .Get (ctx , req .NamespacedName , rt ); err != nil {
282+ return err
283+ }
284+ rt .Status = * desired // safe: this controller is the sole status owner
285+ return r .Status ().Update (ctx , rt )
286+ }); err != nil {
276287 logger .Error (err , "Failed to update status" )
277288 return ctrl.Result {}, err
278289 }
@@ -708,10 +719,6 @@ func (r *AgentRuntimeReconciler) handleDeletion(ctx context.Context, rt *agentv1
708719 delete (workloadLabels , LabelManagedBy )
709720 acc .obj .SetLabels (workloadLabels )
710721
711- // Remove skills annotation from workload metadata.
712- workloadAnnotations := acc .obj .GetAnnotations ()
713- delete (workloadAnnotations , AnnotationSkills )
714- acc .obj .SetAnnotations (workloadAnnotations )
715722
716723 // Remove kagenti.io/type from PodTemplateSpec pod labels so future pods
717724 // are not presented to the webhook with the type label.
0 commit comments