mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-29 17:41:13 +00:00
Add support for using common base
This commit is contained in:
@@ -55,10 +55,15 @@ func (pt *patchTransformer) Transform(baseResourceMap resmap.ResMap) error {
|
||||
for _, patch := range patches {
|
||||
// Merge patches with base resource.
|
||||
id := patch.Id()
|
||||
base, found := baseResourceMap[id]
|
||||
if !found {
|
||||
matchedIds := baseResourceMap.FindByGVKN(id)
|
||||
if len(matchedIds) == 0 {
|
||||
return fmt.Errorf("failed to find an object with %#v to apply the patch", id.Gvk())
|
||||
}
|
||||
if len(matchedIds) > 1 {
|
||||
return fmt.Errorf("Found multiple objects %#v that the patch %#v can apply", matchedIds, id)
|
||||
}
|
||||
id = matchedIds[0]
|
||||
base := baseResourceMap[id]
|
||||
merged := map[string]interface{}{}
|
||||
versionedObj, err := scheme.Scheme.New(id.Gvk())
|
||||
baseName := base.GetName()
|
||||
|
||||
@@ -69,13 +69,17 @@ func (o *namePrefixTransformer) Transform(m resmap.ResMap) error {
|
||||
mf := resmap.ResMap{}
|
||||
|
||||
for id := range m {
|
||||
mf[id] = m[id]
|
||||
found := false
|
||||
for _, path := range o.skipPathConfigs {
|
||||
if selectByGVK(id.Gvk(), path.GroupVersionKind) {
|
||||
delete(mf, id)
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
mf[id] = m[id]
|
||||
delete(m, id)
|
||||
}
|
||||
}
|
||||
|
||||
for id := range mf {
|
||||
@@ -88,6 +92,8 @@ func (o *namePrefixTransformer) Transform(m resmap.ResMap) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
newId := id.CopyWithNewPrefix(o.prefix)
|
||||
m[newId] = mf[id]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -53,7 +53,7 @@ func TestPrefixNameRun(t *testing.T) {
|
||||
}),
|
||||
}
|
||||
expected := resmap.ResMap{
|
||||
resource.NewResId(cmap, "cm1"): resource.NewResourceFromMap(
|
||||
resource.NewResIdWithPrefix(cmap, "cm1", "someprefix-"): resource.NewResourceFromMap(
|
||||
map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "ConfigMap",
|
||||
@@ -61,7 +61,7 @@ func TestPrefixNameRun(t *testing.T) {
|
||||
"name": "someprefix-cm1",
|
||||
},
|
||||
}),
|
||||
resource.NewResId(cmap, "cm2"): resource.NewResourceFromMap(
|
||||
resource.NewResIdWithPrefix(cmap, "cm2", "someprefix-"): resource.NewResourceFromMap(
|
||||
map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "ConfigMap",
|
||||
|
||||
Reference in New Issue
Block a user