mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 01:50:55 +00:00
Add coverage for kusttarget.Load
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"log"
|
||||
"regexp"
|
||||
|
||||
"sigs.k8s.io/yaml"
|
||||
@@ -13,7 +12,7 @@ import (
|
||||
// FixKustomizationPreUnmarshalling modies the raw data
|
||||
// before marshalling - e.g. changes old field names to
|
||||
// new field names.
|
||||
func FixKustomizationPreUnmarshalling(data []byte) []byte {
|
||||
func FixKustomizationPreUnmarshalling(data []byte) ([]byte, error) {
|
||||
deprecateFieldsMap := map[string]string{
|
||||
"imageTags:": "images:",
|
||||
}
|
||||
@@ -21,24 +20,28 @@ func FixKustomizationPreUnmarshalling(data []byte) []byte {
|
||||
pattern := regexp.MustCompile(oldname)
|
||||
data = pattern.ReplaceAll(data, []byte(newname))
|
||||
}
|
||||
if useLegacyPatch(data) {
|
||||
doLegacy, err := useLegacyPatch(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if doLegacy {
|
||||
pattern := regexp.MustCompile("patches:")
|
||||
data = pattern.ReplaceAll(data, []byte("patchesStrategicMerge:"))
|
||||
}
|
||||
return data
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func useLegacyPatch(data []byte) bool {
|
||||
func useLegacyPatch(data []byte) (bool, error) {
|
||||
found := false
|
||||
var object map[string]interface{}
|
||||
err := yaml.Unmarshal(data, &object)
|
||||
if err != nil {
|
||||
log.Fatalf("invalid content from %s\n", string(data))
|
||||
return false, err
|
||||
}
|
||||
if rawPatches, ok := object["patches"]; ok {
|
||||
patches, ok := rawPatches.([]interface{})
|
||||
if !ok {
|
||||
log.Fatalf("invalid patches from %v\n", rawPatches)
|
||||
return false, err
|
||||
}
|
||||
for _, p := range patches {
|
||||
_, ok := p.(string)
|
||||
@@ -47,5 +50,5 @@ func useLegacyPatch(data []byte) bool {
|
||||
}
|
||||
}
|
||||
}
|
||||
return found
|
||||
return found, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user