@@ -343,13 +343,26 @@ func (d *ResourceDetector) OnUpdate(oldObj, newObj interface{}) {
343
343
return
344
344
}
345
345
346
- resourceChangeByKarmada := eventfilter .ResourceChangeByKarmada (unstructuredOldObj , unstructuredNewObj )
346
+ isLazyActivation , err := d .isClaimedByLazyPolicy (unstructuredNewObj )
347
+ if err != nil {
348
+ // should never come here
349
+ klog .Errorf ("Failed to check if the object (kind=%s, %s/%s) is bound by lazy policy. err: %v" , unstructuredNewObj .GetKind (), unstructuredNewObj .GetNamespace (), unstructuredNewObj .GetName (), err )
350
+ }
347
351
348
- resourceItem := ResourceItem {
349
- Obj : newRuntimeObj ,
350
- ResourceChangeByKarmada : resourceChangeByKarmada ,
352
+ if isLazyActivation {
353
+ resourceItem := ResourceItem {
354
+ Obj : newRuntimeObj ,
355
+ ResourceChangeByKarmada : eventfilter .ResourceChangeByKarmada (unstructuredOldObj , unstructuredNewObj ),
356
+ }
357
+
358
+ d .Processor .Enqueue (resourceItem )
359
+ return
351
360
}
352
361
362
+ // For non-lazy policies, it is no need to distinguish whether the change is from Karmada or not.
363
+ resourceItem := ResourceItem {
364
+ Obj : newRuntimeObj ,
365
+ }
353
366
d .Processor .Enqueue (resourceItem )
354
367
}
355
368
@@ -1158,7 +1171,7 @@ func (d *ResourceDetector) HandlePropagationPolicyCreationOrUpdate(policy *polic
1158
1171
if err != nil {
1159
1172
return err
1160
1173
}
1161
- d .Processor . Add (keys. ClusterWideKeyWithConfig { ClusterWideKey : resourceKey , ResourceChangeByKarmada : true } )
1174
+ d .enqueueResourceTemplateForPolicyChange ( resourceKey , policy . Spec . ActivationPreference )
1162
1175
}
1163
1176
1164
1177
// check whether there are matched RT in waiting list, is so, add it to processor
@@ -1176,7 +1189,7 @@ func (d *ResourceDetector) HandlePropagationPolicyCreationOrUpdate(policy *polic
1176
1189
1177
1190
for _ , key := range matchedKeys {
1178
1191
d .RemoveWaiting (key )
1179
- d .Processor . Add (keys. ClusterWideKeyWithConfig { ClusterWideKey : key , ResourceChangeByKarmada : true } )
1192
+ d .enqueueResourceTemplateForPolicyChange ( key , policy . Spec . ActivationPreference )
1180
1193
}
1181
1194
1182
1195
// If preemption is enabled, handle the preemption process.
@@ -1225,14 +1238,14 @@ func (d *ResourceDetector) HandleClusterPropagationPolicyCreationOrUpdate(policy
1225
1238
if err != nil {
1226
1239
return err
1227
1240
}
1228
- d .Processor . Add (keys. ClusterWideKeyWithConfig { ClusterWideKey : resourceKey , ResourceChangeByKarmada : true } )
1241
+ d .enqueueResourceTemplateForPolicyChange ( resourceKey , policy . Spec . ActivationPreference )
1229
1242
}
1230
1243
for _ , crb := range clusterResourceBindings .Items {
1231
1244
resourceKey , err := helper .ConstructClusterWideKey (crb .Spec .Resource )
1232
1245
if err != nil {
1233
1246
return err
1234
1247
}
1235
- d .Processor . Add (keys. ClusterWideKeyWithConfig { ClusterWideKey : resourceKey , ResourceChangeByKarmada : true } )
1248
+ d .enqueueResourceTemplateForPolicyChange ( resourceKey , policy . Spec . ActivationPreference )
1236
1249
}
1237
1250
1238
1251
matchedKeys := d .GetMatching (policy .Spec .ResourceSelectors )
@@ -1249,7 +1262,7 @@ func (d *ResourceDetector) HandleClusterPropagationPolicyCreationOrUpdate(policy
1249
1262
1250
1263
for _ , key := range matchedKeys {
1251
1264
d .RemoveWaiting (key )
1252
- d .Processor . Add (keys. ClusterWideKeyWithConfig { ClusterWideKey : key , ResourceChangeByKarmada : true } )
1265
+ d .enqueueResourceTemplateForPolicyChange ( key , policy . Spec . ActivationPreference )
1253
1266
}
1254
1267
1255
1268
// If preemption is enabled, handle the preemption process.
@@ -1373,3 +1386,21 @@ func (d *ResourceDetector) applyReplicaInterpretation(object *unstructured.Unstr
1373
1386
1374
1387
return nil
1375
1388
}
1389
+
1390
+ // enqueueResourceTemplateForPolicyChange enqueues a resource template key for reconciliation in response to a
1391
+ // PropagationPolicy or ClusterPropagationPolicy change. If the policy's ActivationPreference is set to Lazy,
1392
+ // the ResourceChangeByKarmada flag is set to true, indicating that the resource template is being enqueued
1393
+ // due to a policy change and should not be propagated to member clusters. For non-lazy policies, this flag
1394
+ // is omitted as the distinction is unnecessary.
1395
+ //
1396
+ // Note: Setting ResourceChangeByKarmada changes the effective queue key. Mixing both true/false for the same
1397
+ // resource may result in two different queue keys being processed concurrently, which can cause race conditions.
1398
+ // Therefore, only set ResourceChangeByKarmada in lazy activation mode.
1399
+ // For more details, see: https://github.com/karmada-io/karmada/issues/5996.
1400
+ func (d * ResourceDetector ) enqueueResourceTemplateForPolicyChange (key keys.ClusterWideKey , pref policyv1alpha1.ActivationPreference ) {
1401
+ if util .IsLazyActivationEnabled (pref ) {
1402
+ d .Processor .Add (keys.ClusterWideKeyWithConfig {ClusterWideKey : key , ResourceChangeByKarmada : true })
1403
+ return
1404
+ }
1405
+ d .Processor .Add (keys.ClusterWideKeyWithConfig {ClusterWideKey : key })
1406
+ }
0 commit comments