@@ -238,9 +238,6 @@ func RemoveOrphanWorks(ctx context.Context, c client.Client, works []workv1alpha
238
238
}
239
239
240
240
// FetchResourceTemplate fetches the resource template to be propagated.
241
- // Any updates to this resource template are not recommended as it may come from the informer cache.
242
- // We should abide by the principle of making a deep copy first and then modifying it.
243
- // See issue: https://github.com/karmada-io/karmada/issues/3878.
244
241
func FetchResourceTemplate (
245
242
ctx context.Context ,
246
243
dynamicClient dynamic.Interface ,
@@ -266,12 +263,13 @@ func FetchResourceTemplate(
266
263
// fall back to call api server in case the cache has not been synchronized yet
267
264
klog .Warningf ("Failed to get resource template (%s/%s/%s) from cache, Error: %v. Fall back to call api server." ,
268
265
resource .Kind , resource .Namespace , resource .Name , err )
269
- object , err = dynamicClient .Resource (gvr ).Namespace (resource .Namespace ).Get (ctx , resource .Name , metav1.GetOptions {})
266
+ objectFromAPIServer , err : = dynamicClient .Resource (gvr ).Namespace (resource .Namespace ).Get (ctx , resource .Name , metav1.GetOptions {})
270
267
if err != nil {
271
268
klog .Errorf ("Failed to get resource template (%s/%s/%s) from api server, Error: %v" ,
272
269
resource .Kind , resource .Namespace , resource .Name , err )
273
270
return nil , err
274
271
}
272
+ return objectFromAPIServer , nil
275
273
}
276
274
277
275
unstructuredObj , err := ToUnstructured (object )
@@ -280,7 +278,7 @@ func FetchResourceTemplate(
280
278
return nil , err
281
279
}
282
280
283
- return unstructuredObj , nil
281
+ return unstructuredObj . DeepCopy () , nil
284
282
}
285
283
286
284
// FetchResourceTemplatesByLabelSelector fetches the resource templates by label selector to be propagated.
0 commit comments