Skip to content

Commit 59696d1

Browse files
authored
fix a patch files accept multiple patches (#5194)
* fix a patch files accept multiple patches * fix comments and variable name * add error handling when using not allowed multiple strategic-merge patches * fix error message of Multiple Strategic-Merge Patch file * refactor transformStrategicMerge() * add TODO comment and test for Multiple JSON patch Yaml documents are not allowed * refactoring PatchTransformer * add multiple patch test for PatchTransformer package * improve error message to PatchTransformer * refactor const and error message check * fix some error messages
1 parent 56d37ac commit 59696d1

File tree

5 files changed

+386
-136
lines changed

5 files changed

+386
-136
lines changed

api/internal/builtins/PatchTransformer.go

Lines changed: 81 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/krusty/multiplepatch_test.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ package krusty_test
66
import (
77
"testing"
88

9-
"github.com/stretchr/testify/assert"
10-
119
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
1210
)
1311

@@ -303,20 +301,15 @@ patchesStrategicMerge:
303301
m = th.Run("overlay", th.MakeDefaultOptions())
304302
th.AssertActualEqualsExpected(m, expected)
305303

306-
// Technique 4: "patches:" field, one patch file. Fails.
304+
// Technique 4: "patches:" field, one patch file.
307305
th.WriteK("overlay", `
308306
resources:
309307
- ../base
310308
patches:
311309
- path: twoPatchesInOneFile.yaml
312310
`)
313-
err := th.RunWithErr("overlay", th.MakeDefaultOptions())
314-
assert.Error(t, err)
315-
// This should fail, because the semantics of the `patches` field.
316-
// That field allows specific patch targeting to a list of targets,
317-
// while the `patchesStrategicMerge` field accepts patches that
318-
// implicitly identify their targets via GVKN.
319-
assert.Contains(t, err.Error(), "unable to parse SM or JSON patch from ")
311+
m = th.Run("overlay", th.MakeDefaultOptions())
312+
th.AssertActualEqualsExpected(m, expected)
320313
}
321314

322315
func TestRemoveEmptyDirWithNullFieldInSmp(t *testing.T) {
@@ -1670,7 +1663,7 @@ spec:
16701663
template:
16711664
spec:
16721665
containers:
1673-
- image: fluentd:latest
1666+
- image: fluentd:latest
16741667
name: fluentd
16751668
serviceAccountName: fluentd-sa
16761669
---

api/resmap/reswrangler.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,8 +696,7 @@ func (m *resWrangler) DeAnchor() (err error) {
696696
}
697697

698698
// ApplySmPatch applies the patch, and errors on Id collisions.
699-
func (m *resWrangler) ApplySmPatch(
700-
selectedSet *resource.IdSet, patch *resource.Resource) error {
699+
func (m *resWrangler) ApplySmPatch(selectedSet *resource.IdSet, patch *resource.Resource) error {
701700
var list []*resource.Resource
702701
for _, res := range m.rList {
703702
if selectedSet.Contains(res.CurId()) {

0 commit comments

Comments
 (0)