Skip to content

Commit

Permalink
[profiles] Use deepcopy for patch (#1320)
Browse files Browse the repository at this point in the history
* Use deepcopy obj for patch

* Consistent naming
  • Loading branch information
khewonc committed Jul 25, 2024
1 parent e8a7566 commit 08130ef
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
9 changes: 3 additions & 6 deletions controllers/datadogagent/controller_reconcile_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,10 @@ func (r *Reconciler) labelNodesWithProfiles(ctx context.Context, profilesByNode
return nil
}

patch := corev1.Node{
TypeMeta: node.TypeMeta,
ObjectMeta: node.ObjectMeta,
}
patch.Labels = newLabels
modifiedNode := node.DeepCopy()
modifiedNode.Labels = newLabels

err := r.client.Patch(ctx, &patch, client.MergeFrom(node))
err := r.client.Patch(ctx, modifiedNode, client.MergeFrom(node))
if err != nil && !errors.IsNotFound(err) {
return err
}
Expand Down
9 changes: 3 additions & 6 deletions controllers/datadogagent/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,10 @@ func (r *Reconciler) profilesCleanup() error {
newLabels[k] = v
}

patch := corev1.Node{
TypeMeta: node.TypeMeta,
ObjectMeta: node.ObjectMeta,
}
patch.Labels = newLabels
modifiedNode := node.DeepCopy()
modifiedNode.Labels = newLabels

err := r.client.Patch(context.TODO(), &patch, client.MergeFrom(&node))
err := r.client.Patch(context.TODO(), modifiedNode, client.MergeFrom(&node))
if err != nil && !errors.IsNotFound(err) {
return err
}
Expand Down

0 comments on commit 08130ef

Please sign in to comment.