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

drop support for legacy patches #4911

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/internal/target/kusttarget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestLoad(t *testing.T) {
},
},
"nonsenseLatin": {
errContains: "error converting YAML to JSON",
errContains: "found a tab character that violates indentation",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this points out the test isn't testing what it claimed, i.e. it is testing tab indent vs space indent instead of random text vs yaml. The real error in a nonsense case is fine too (yaml: line 6: could not find expected ':') and also an improvement on the misleading error we gave before!

content: `
Lorem ipsum dolor sit amet, consectetur
adipiscing elit, sed do eiusmod tempor
Expand Down
2 changes: 1 addition & 1 deletion api/krusty/openapicustomschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ spec:
`)

// component declared in overlay with custom schema and patch
th.WriteC("components/dc-openapi", `patches:
th.WriteC("components/dc-openapi", `patchesStrategicMerge:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅

- patch.yml
openapi:
path: openapi.json
Expand Down
32 changes: 0 additions & 32 deletions api/types/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ package types

import (
"regexp"

"sigs.k8s.io/yaml"
)

// FixKustomizationPreUnmarshalling modifies the raw data
Expand All @@ -20,35 +18,5 @@ func FixKustomizationPreUnmarshalling(data []byte) ([]byte, error) {
pattern := regexp.MustCompile(oldname)
data = pattern.ReplaceAll(data, []byte(newname))
}
doLegacy, err := useLegacyPatch(data)
if err != nil {
return nil, err
}
if doLegacy {
pattern := regexp.MustCompile("patches:")
data = pattern.ReplaceAll(data, []byte("patchesStrategicMerge:"))
}
return data, nil
}

func useLegacyPatch(data []byte) (bool, error) {
found := false
var object map[string]interface{}
err := yaml.Unmarshal(data, &object)
if err != nil {
return false, err
}
if rawPatches, ok := object["patches"]; ok {
patches, ok := rawPatches.([]interface{})
if !ok {
return false, err
}
for _, p := range patches {
_, ok := p.(string)
if ok {
found = true
}
}
}
return found, nil
}
36 changes: 0 additions & 36 deletions kustomize/commands/internal/kustfile/kustomizationfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,42 +280,6 @@ generatorOptions:
}
}

func TestFixPatchesField(t *testing.T) {
kustomizationContentWithComments := []byte(`
patches:
- patch1.yaml
- patch2.yaml
`)

expected := []byte(`
patchesStrategicMerge:
- patch1.yaml
- patch2.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
`)
fSys := filesys.MakeFsInMemory()
testutils_test.WriteTestKustomizationWith(
fSys, kustomizationContentWithComments)
mf, err := NewKustomizationFile(fSys)
if err != nil {
t.Fatalf("Unexpected Error: %v", err)
}

kustomization, err := mf.Read()
if err != nil {
t.Fatalf("Unexpected Error: %v", err)
}
if err = mf.Write(kustomization); err != nil {
t.Fatalf("Unexpected Error: %v", err)
}
bytes, _ := fSys.ReadFile(mf.path)

if diff := cmp.Diff(expected, bytes); diff != "" {
t.Errorf("Mismatch (-expected, +actual):\n%s", diff)
}
}

func TestFixPatchesFieldForExtendedPatch(t *testing.T) {
kustomizationContentWithComments := []byte(`
patches:
Expand Down