From 1e3d875d2ce0d3ddba1f4be01032e134ca3ce117 Mon Sep 17 00:00:00 2001 From: Julio Chana Date: Fri, 27 Sep 2024 11:34:22 +0200 Subject: [PATCH 1/3] fix: Add test, when an empty patch file is given, it should not fail --- .../patchtransformer/PatchTransformer_test.go | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/plugin/builtin/patchtransformer/PatchTransformer_test.go b/plugin/builtin/patchtransformer/PatchTransformer_test.go index 805e5f99e4..24bfb0040a 100644 --- a/plugin/builtin/patchtransformer/PatchTransformer_test.go +++ b/plugin/builtin/patchtransformer/PatchTransformer_test.go @@ -1108,3 +1108,32 @@ spec: name: test-deployment `) } + +func TestPatchTransformerPatchEmpty(t *testing.T) { + th := kusttest_test.MakeEnhancedHarness(t). + PrepBuiltin("PatchTransformer") + defer th.Reset() + + th.RunTransformerAndCheckError(` +`, someDeploymentResources, func(t *testing.T, err error) { + if err != nil { + t.Fatalf("unexpected error") + } + }) +} + +func TestPatchTransformerPatchEmptyOnlyComments(t *testing.T) { + th := kusttest_test.MakeEnhancedHarness(t). + PrepBuiltin("PatchTransformer") + defer th.Reset() + + th.RunTransformerAndCheckError(` +# File with only comments + +# Is a virtually empty yaml +`, someDeploymentResources, func(t *testing.T, err error) { + if err != nil { + t.Fatalf("unexpected error") + } + }) +} From 5952169c169493c483f54d7345ab870a6bd5011d Mon Sep 17 00:00:00 2001 From: Julio Chana Date: Fri, 27 Sep 2024 11:35:01 +0200 Subject: [PATCH 2/3] fix: Add code so there's no error given if an empty file is given as a patch --- plugin/builtin/patchtransformer/PatchTransformer.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugin/builtin/patchtransformer/PatchTransformer.go b/plugin/builtin/patchtransformer/PatchTransformer.go index 04f15b7ee0..062e57930a 100644 --- a/plugin/builtin/patchtransformer/PatchTransformer.go +++ b/plugin/builtin/patchtransformer/PatchTransformer.go @@ -59,8 +59,9 @@ func (p *plugin) Config(h *resmap.PluginHelpers, c []byte) error { patchesSM, errSM := h.ResmapFactory().RF().SliceFromBytes([]byte(p.patchText)) patchesJson, errJson := jsonPatchFromBytes([]byte(p.patchText)) - if (errSM == nil && errJson == nil) || - (patchesSM != nil && patchesJson != nil) { + if ((errSM == nil && errJson == nil) || + (patchesSM != nil && patchesJson != nil)) && + (len(patchesSM) > 0 && len(patchesJson) > 0) { return fmt.Errorf( "illegally qualifies as both an SM and JSON patch: %s", p.patchSource) From bfd408c71d84217acc14ed8812669caa256dd41e Mon Sep 17 00:00:00 2001 From: Julio Chana Date: Tue, 19 Nov 2024 15:06:38 +0100 Subject: [PATCH 3/3] chore: Generate plugin with pluginator --- api/internal/builtins/PatchTransformer.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/api/internal/builtins/PatchTransformer.go b/api/internal/builtins/PatchTransformer.go index 8e6eb41128..05d96f23ca 100644 --- a/api/internal/builtins/PatchTransformer.go +++ b/api/internal/builtins/PatchTransformer.go @@ -56,8 +56,9 @@ func (p *PatchTransformerPlugin) Config(h *resmap.PluginHelpers, c []byte) error patchesSM, errSM := h.ResmapFactory().RF().SliceFromBytes([]byte(p.patchText)) patchesJson, errJson := jsonPatchFromBytes([]byte(p.patchText)) - if (errSM == nil && errJson == nil) || - (patchesSM != nil && patchesJson != nil) { + if ((errSM == nil && errJson == nil) || + (patchesSM != nil && patchesJson != nil)) && + (len(patchesSM) > 0 && len(patchesJson) > 0) { return fmt.Errorf( "illegally qualifies as both an SM and JSON patch: %s", p.patchSource)