Skip to content

Commit 8826d59

Browse files
Revert syncer back to SSA patch to correctly remove fields
Signed-off-by: Danil-Grigorev <[email protected]>
1 parent b5d6a60 commit 8826d59

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

internal/sync/client.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"fmt"
2222

23-
apierrors "k8s.io/apimachinery/pkg/api/errors"
2423
"sigs.k8s.io/controller-runtime/pkg/client"
2524
"sigs.k8s.io/controller-runtime/pkg/log"
2625
)
@@ -52,24 +51,27 @@ func Patch(ctx context.Context, cl client.Client, obj client.Object, options ...
5251

5352
patchOptions := []client.PatchOption{
5453
client.FieldOwner(fieldOwner),
54+
client.ForceOwnership,
5555
}
5656
patchOptions = append(patchOptions, options...)
5757

58-
err := cl.Patch(ctx, obj, client.Merge, patchOptions...)
59-
if apierrors.IsNotFound(err) {
60-
return cl.Create(ctx, obj, []client.CreateOption{client.FieldOwner(fieldOwner)}...)
61-
}
62-
63-
return err
58+
return cl.Patch(ctx, obj, client.Apply, patchOptions...)
6459
}
6560

6661
// PatchStatus will only patch the status subresource of the provided object.
6762
func PatchStatus(ctx context.Context, cl client.Client, obj client.Object) error {
6863
log := log.FromContext(ctx)
6964

65+
obj.SetManagedFields(nil)
66+
67+
if err := setKind(cl, obj); err != nil {
68+
return err
69+
}
70+
7071
log.Info(fmt.Sprintf("Patching status %s: %s", obj.GetObjectKind().GroupVersionKind().Kind, client.ObjectKeyFromObject(obj)))
7172

72-
return cl.Status().Patch(ctx, obj, client.Merge, []client.SubResourcePatchOption{
73+
return cl.Status().Patch(ctx, obj, client.Apply, []client.SubResourcePatchOption{
7374
client.FieldOwner(fieldOwner),
75+
client.ForceOwnership,
7476
}...)
7577
}

0 commit comments

Comments
 (0)