Skip to content

Commit 2db573b

Browse files
authored
drop support for legacy patches (#4911)
* drop support for legacy patches * fix CI
1 parent 8a869f6 commit 2db573b

File tree

4 files changed

+2
-70
lines changed

4 files changed

+2
-70
lines changed

api/internal/target/kusttarget_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestLoad(t *testing.T) {
4040
},
4141
},
4242
"nonsenseLatin": {
43-
errContains: "error converting YAML to JSON",
43+
errContains: "found a tab character that violates indentation",
4444
content: `
4545
Lorem ipsum dolor sit amet, consectetur
4646
adipiscing elit, sed do eiusmod tempor

api/krusty/openapicustomschema_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ spec:
503503
`)
504504

505505
// component declared in overlay with custom schema and patch
506-
th.WriteC("components/dc-openapi", `patches:
506+
th.WriteC("components/dc-openapi", `patchesStrategicMerge:
507507
- patch.yml
508508
openapi:
509509
path: openapi.json

api/types/fix.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ package types
55

66
import (
77
"regexp"
8-
9-
"sigs.k8s.io/yaml"
108
)
119

1210
// FixKustomizationPreUnmarshalling modifies the raw data
@@ -20,35 +18,5 @@ func FixKustomizationPreUnmarshalling(data []byte) ([]byte, error) {
2018
pattern := regexp.MustCompile(oldname)
2119
data = pattern.ReplaceAll(data, []byte(newname))
2220
}
23-
doLegacy, err := useLegacyPatch(data)
24-
if err != nil {
25-
return nil, err
26-
}
27-
if doLegacy {
28-
pattern := regexp.MustCompile("patches:")
29-
data = pattern.ReplaceAll(data, []byte("patchesStrategicMerge:"))
30-
}
3121
return data, nil
3222
}
33-
34-
func useLegacyPatch(data []byte) (bool, error) {
35-
found := false
36-
var object map[string]interface{}
37-
err := yaml.Unmarshal(data, &object)
38-
if err != nil {
39-
return false, err
40-
}
41-
if rawPatches, ok := object["patches"]; ok {
42-
patches, ok := rawPatches.([]interface{})
43-
if !ok {
44-
return false, err
45-
}
46-
for _, p := range patches {
47-
_, ok := p.(string)
48-
if ok {
49-
found = true
50-
}
51-
}
52-
}
53-
return found, nil
54-
}

kustomize/commands/internal/kustfile/kustomizationfile_test.go

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -280,42 +280,6 @@ generatorOptions:
280280
}
281281
}
282282

283-
func TestFixPatchesField(t *testing.T) {
284-
kustomizationContentWithComments := []byte(`
285-
patches:
286-
- patch1.yaml
287-
- patch2.yaml
288-
`)
289-
290-
expected := []byte(`
291-
patchesStrategicMerge:
292-
- patch1.yaml
293-
- patch2.yaml
294-
apiVersion: kustomize.config.k8s.io/v1beta1
295-
kind: Kustomization
296-
`)
297-
fSys := filesys.MakeFsInMemory()
298-
testutils_test.WriteTestKustomizationWith(
299-
fSys, kustomizationContentWithComments)
300-
mf, err := NewKustomizationFile(fSys)
301-
if err != nil {
302-
t.Fatalf("Unexpected Error: %v", err)
303-
}
304-
305-
kustomization, err := mf.Read()
306-
if err != nil {
307-
t.Fatalf("Unexpected Error: %v", err)
308-
}
309-
if err = mf.Write(kustomization); err != nil {
310-
t.Fatalf("Unexpected Error: %v", err)
311-
}
312-
bytes, _ := fSys.ReadFile(mf.path)
313-
314-
if diff := cmp.Diff(expected, bytes); diff != "" {
315-
t.Errorf("Mismatch (-expected, +actual):\n%s", diff)
316-
}
317-
}
318-
319283
func TestFixPatchesFieldForExtendedPatch(t *testing.T) {
320284
kustomizationContentWithComments := []byte(`
321285
patches:

0 commit comments

Comments
 (0)