When to use object.DeepCopy in the reconcile loop #3711
Replies: 1 comment
-
Response: The manager does indeed have a cache, but this is generally not a concern unless you're specifically aiming for performance optimization and need to control what gets cached. In most typical scenarios, the cache management is handled internally and doesn't require active intervention.
Response: The need to copy objects, especially through deep copying, is primarily based on the scenario. For instance, you might want to deep copy objects when you're modifying them, such as updating their status or adding labels. Here’s an example: job := &kbatch.Job{
ObjectMeta: metav1.ObjectMeta{
Labels: make(map[string]string),
Annotations: make(map[string]string),
Name: name,
Namespace: cronJob.Namespace,
},
Spec: *cronJob.Spec.JobTemplate.Spec.DeepCopy(),
} The Since you're new to this, I also recommend checking out the Getting Started guide on Kubebuilder. I am closing this one as answered, |
Beta Was this translation helpful? Give feedback.
-
Hi all,
we are new to operator development. From the documentation we know that there are caches and we have to deal with eventual consistent objects.
After reading the documentation it is not 100 percent clear, when we have to copy objects. Is there a general rule e.g. deep copy an object anytime when you want to modify it e.g. updating the status, adding labels, etc.
Thx, Regards
Beta Was this translation helpful? Give feedback.
All reactions