Skip to content

Commit

Permalink
Merge pull request #692 from fluxcd/ssa-nits
Browse files Browse the repository at this point in the history
ssa: prevent unnecessary `DeepCopy`
  • Loading branch information
hiddeco authored Nov 27, 2023
2 parents cc07605 + 8fc4505 commit ce91255
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions ssa/manager_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ func DefaultApplyOptions() ApplyOptions {
// Drift detection is performed by comparing the server-side dry-run result with the existing object.
// When immutable field changes are detected, the object is recreated if 'force' is set to 'true'.
func (m *ResourceManager) Apply(ctx context.Context, object *unstructured.Unstructured, opts ApplyOptions) (*ChangeSetEntry, error) {
existingObject := object.DeepCopy()
existingObject := &unstructured.Unstructured{}
existingObject.SetGroupVersionKind(object.GroupVersionKind())
getError := m.client.Get(ctx, client.ObjectKeyFromObject(object), existingObject)

if m.shouldSkipApply(object, existingObject, opts) {
Expand Down Expand Up @@ -153,7 +154,8 @@ func (m *ResourceManager) ApplyAll(ctx context.Context, objects []*unstructured.
i, object := i, object

g.Go(func() error {
existingObject := object.DeepCopy()
existingObject := &unstructured.Unstructured{}
existingObject.SetGroupVersionKind(object.GroupVersionKind())
getError := m.client.Get(ctx, client.ObjectKeyFromObject(object), existingObject)

if m.shouldSkipApply(object, existingObject, opts) {
Expand Down
3 changes: 2 additions & 1 deletion ssa/manager_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ func DefaultDeleteOptions() DeleteOptions {
// Delete deletes the given object (not found errors are ignored).
func (m *ResourceManager) Delete(ctx context.Context, object *unstructured.Unstructured, opts DeleteOptions) (*ChangeSetEntry, error) {

existingObject := object.DeepCopy()
existingObject := &unstructured.Unstructured{}
existingObject.SetGroupVersionKind(object.GroupVersionKind())
err := m.client.Get(ctx, client.ObjectKeyFromObject(object), existingObject)
if err != nil {
if !apierrors.IsNotFound(err) {
Expand Down
4 changes: 3 additions & 1 deletion ssa/manager_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package ssa

import (
"context"

apiequality "k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -48,7 +49,8 @@ func (m *ResourceManager) Diff(ctx context.Context, object *unstructured.Unstruc
*unstructured.Unstructured,
error,
) {
existingObject := object.DeepCopy()
existingObject := &unstructured.Unstructured{}
existingObject.SetGroupVersionKind(object.GroupVersionKind())
_ = m.client.Get(ctx, client.ObjectKeyFromObject(object), existingObject)

if existingObject != nil && AnyInMetadata(existingObject, opts.Exclusions) {
Expand Down

0 comments on commit ce91255

Please sign in to comment.