Skip to content

Commit ce91255

Browse files
authored
Merge pull request #692 from fluxcd/ssa-nits
ssa: prevent unnecessary `DeepCopy`
2 parents cc07605 + 8fc4505 commit ce91255

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

ssa/manager_apply.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ func DefaultApplyOptions() ApplyOptions {
9292
// Drift detection is performed by comparing the server-side dry-run result with the existing object.
9393
// When immutable field changes are detected, the object is recreated if 'force' is set to 'true'.
9494
func (m *ResourceManager) Apply(ctx context.Context, object *unstructured.Unstructured, opts ApplyOptions) (*ChangeSetEntry, error) {
95-
existingObject := object.DeepCopy()
95+
existingObject := &unstructured.Unstructured{}
96+
existingObject.SetGroupVersionKind(object.GroupVersionKind())
9697
getError := m.client.Get(ctx, client.ObjectKeyFromObject(object), existingObject)
9798

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

155156
g.Go(func() error {
156-
existingObject := object.DeepCopy()
157+
existingObject := &unstructured.Unstructured{}
158+
existingObject.SetGroupVersionKind(object.GroupVersionKind())
157159
getError := m.client.Get(ctx, client.ObjectKeyFromObject(object), existingObject)
158160

159161
if m.shouldSkipApply(object, existingObject, opts) {

ssa/manager_delete.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ func DefaultDeleteOptions() DeleteOptions {
6161
// Delete deletes the given object (not found errors are ignored).
6262
func (m *ResourceManager) Delete(ctx context.Context, object *unstructured.Unstructured, opts DeleteOptions) (*ChangeSetEntry, error) {
6363

64-
existingObject := object.DeepCopy()
64+
existingObject := &unstructured.Unstructured{}
65+
existingObject.SetGroupVersionKind(object.GroupVersionKind())
6566
err := m.client.Get(ctx, client.ObjectKeyFromObject(object), existingObject)
6667
if err != nil {
6768
if !apierrors.IsNotFound(err) {

ssa/manager_diff.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package ssa
1919

2020
import (
2121
"context"
22+
2223
apiequality "k8s.io/apimachinery/pkg/api/equality"
2324
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2425
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -48,7 +49,8 @@ func (m *ResourceManager) Diff(ctx context.Context, object *unstructured.Unstruc
4849
*unstructured.Unstructured,
4950
error,
5051
) {
51-
existingObject := object.DeepCopy()
52+
existingObject := &unstructured.Unstructured{}
53+
existingObject.SetGroupVersionKind(object.GroupVersionKind())
5254
_ = m.client.Get(ctx, client.ObjectKeyFromObject(object), existingObject)
5355

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

0 commit comments

Comments
 (0)