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) 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") + } + }) +}