Skip to content

Commit d5b36f1

Browse files
authored
Merge pull request #77 from authzed/fix-dfake
dfake: handle Patch with `type: Apply` as an Apply
2 parents 08ad4c6 + 9d51a98 commit d5b36f1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

client/fake/fake.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,28 @@ func (c *fakeDynamicResourceClient) Watch(ctx context.Context, opts metav1.ListO
356356
}
357357

358358
func (c *fakeDynamicResourceClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, options metav1.PatchOptions, subresources ...string) (*unstructured.Unstructured, error) {
359+
// Handle ApplyPatchType by redirecting to Apply method which has proper SSA conflict handling
360+
if pt == types.ApplyPatchType {
361+
// Convert patch data to unstructured object
362+
var obj unstructured.Unstructured
363+
if err := json.Unmarshal(data, &obj); err != nil {
364+
return nil, fmt.Errorf("failed to unmarshal apply patch data: %w", err)
365+
}
366+
367+
// Convert PatchOptions to ApplyOptions
368+
applyOptions := metav1.ApplyOptions{
369+
FieldManager: options.FieldManager,
370+
DryRun: options.DryRun,
371+
}
372+
if options.Force != nil {
373+
applyOptions.Force = *options.Force
374+
}
375+
376+
// Use Apply method for proper SSA handling
377+
return c.Apply(ctx, name, &obj, applyOptions, subresources...)
378+
}
379+
380+
// For other patch types, delegate to upstream client
359381
return c.client.FakeDynamicClient.Resource(c.resource).Namespace(c.namespace).Patch(ctx, name, pt, data, options, subresources...)
360382
}
361383

0 commit comments

Comments
 (0)