mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 00:52:55 +00:00
drop support for legacy patches (#4911)
* drop support for legacy patches * fix CI
This commit is contained in:
@@ -40,7 +40,7 @@ func TestLoad(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
"nonsenseLatin": {
|
"nonsenseLatin": {
|
||||||
errContains: "error converting YAML to JSON",
|
errContains: "found a tab character that violates indentation",
|
||||||
content: `
|
content: `
|
||||||
Lorem ipsum dolor sit amet, consectetur
|
Lorem ipsum dolor sit amet, consectetur
|
||||||
adipiscing elit, sed do eiusmod tempor
|
adipiscing elit, sed do eiusmod tempor
|
||||||
|
|||||||
@@ -503,7 +503,7 @@ spec:
|
|||||||
`)
|
`)
|
||||||
|
|
||||||
// component declared in overlay with custom schema and patch
|
// component declared in overlay with custom schema and patch
|
||||||
th.WriteC("components/dc-openapi", `patches:
|
th.WriteC("components/dc-openapi", `patchesStrategicMerge:
|
||||||
- patch.yml
|
- patch.yml
|
||||||
openapi:
|
openapi:
|
||||||
path: openapi.json
|
path: openapi.json
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ package types
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"sigs.k8s.io/yaml"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// FixKustomizationPreUnmarshalling modifies the raw data
|
// FixKustomizationPreUnmarshalling modifies the raw data
|
||||||
@@ -20,35 +18,5 @@ func FixKustomizationPreUnmarshalling(data []byte) ([]byte, error) {
|
|||||||
pattern := regexp.MustCompile(oldname)
|
pattern := regexp.MustCompile(oldname)
|
||||||
data = pattern.ReplaceAll(data, []byte(newname))
|
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
|
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
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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) {
|
func TestFixPatchesFieldForExtendedPatch(t *testing.T) {
|
||||||
kustomizationContentWithComments := []byte(`
|
kustomizationContentWithComments := []byte(`
|
||||||
patches:
|
patches:
|
||||||
|
|||||||
Reference in New Issue
Block a user