Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix a patch files accept multiple patches #5194

142 changes: 81 additions & 61 deletions api/internal/builtins/PatchTransformer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 4 additions & 11 deletions api/krusty/multiplepatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ package krusty_test
import (
"testing"

"github.com/stretchr/testify/assert"

kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
)

Expand Down Expand Up @@ -303,20 +301,15 @@ patchesStrategicMerge:
m = th.Run("overlay", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, expected)

// Technique 4: "patches:" field, one patch file. Fails.
// Technique 4: "patches:" field, one patch file.
th.WriteK("overlay", `
resources:
- ../base
patches:
- path: twoPatchesInOneFile.yaml
`)
err := th.RunWithErr("overlay", th.MakeDefaultOptions())
assert.Error(t, err)
// This should fail, because the semantics of the `patches` field.
// That field allows specific patch targeting to a list of targets,
// while the `patchesStrategicMerge` field accepts patches that
// implicitly identify their targets via GVKN.
assert.Contains(t, err.Error(), "unable to parse SM or JSON patch from ")
m = th.Run("overlay", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, expected)
}

func TestRemoveEmptyDirWithNullFieldInSmp(t *testing.T) {
Expand Down Expand Up @@ -1670,7 +1663,7 @@ spec:
template:
spec:
containers:
- image: fluentd:latest
- image: fluentd:latest
name: fluentd
serviceAccountName: fluentd-sa
---
Expand Down
3 changes: 1 addition & 2 deletions api/resmap/reswrangler.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,8 +696,7 @@ func (m *resWrangler) DeAnchor() (err error) {
}

// ApplySmPatch applies the patch, and errors on Id collisions.
func (m *resWrangler) ApplySmPatch(
selectedSet *resource.IdSet, patch *resource.Resource) error {
func (m *resWrangler) ApplySmPatch(selectedSet *resource.IdSet, patch *resource.Resource) error {
var list []*resource.Resource
for _, res := range m.rList {
if selectedSet.Contains(res.CurId()) {
Expand Down
Loading