mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 17:34:21 +00:00
Merge pull request #93 from Liujingfang1/configmaps
make generated configmaps composable
This commit is contained in:
6
pkg/commands/testdata/testcase-configmaps/base/myapp/mycomponent/kustomization.yaml
vendored
Normal file
6
pkg/commands/testdata/testcase-configmaps/base/myapp/mycomponent/kustomization.yaml
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
namePrefix: p1-
|
||||
configMapGenerator:
|
||||
- name: com1
|
||||
behavior: create
|
||||
literals:
|
||||
- from=base
|
||||
6
pkg/commands/testdata/testcase-configmaps/base/myapp/mycomponent2/kustomization.yaml
vendored
Normal file
6
pkg/commands/testdata/testcase-configmaps/base/myapp/mycomponent2/kustomization.yaml
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
namePrefix: p2-
|
||||
configMapGenerator:
|
||||
- name: com2
|
||||
behavior: create
|
||||
literals:
|
||||
- from=base
|
||||
16
pkg/commands/testdata/testcase-configmaps/expected.diff
vendored
Normal file
16
pkg/commands/testdata/testcase-configmaps/expected.diff
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
diff -u -N /tmp/noop/v1_ConfigMap_com1.yaml /tmp/transformed/v1_ConfigMap_com1.yaml
|
||||
--- /tmp/noop/v1_ConfigMap_com1.yaml YYYY-MM-DD HH:MM:SS
|
||||
+++ /tmp/transformed/v1_ConfigMap_com1.yaml YYYY-MM-DD HH:MM:SS
|
||||
@@ -1,9 +1,11 @@
|
||||
apiVersion: v1
|
||||
data:
|
||||
+ baz: qux
|
||||
+ foo: bar
|
||||
from: overlay
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
annotations: {}
|
||||
creationTimestamp: null
|
||||
labels: {}
|
||||
- name: p1-com1-cmdb776d5b
|
||||
+ name: p1-com1-dhbbm922gd
|
||||
21
pkg/commands/testdata/testcase-configmaps/expected.yaml
vendored
Normal file
21
pkg/commands/testdata/testcase-configmaps/expected.yaml
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
apiVersion: v1
|
||||
data:
|
||||
baz: qux
|
||||
foo: bar
|
||||
from: overlay
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
annotations: {}
|
||||
creationTimestamp: null
|
||||
labels: {}
|
||||
name: p1-com1-dhbbm922gd
|
||||
---
|
||||
apiVersion: v1
|
||||
data:
|
||||
from: overlay
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
annotations: {}
|
||||
creationTimestamp: null
|
||||
labels: {}
|
||||
name: p2-com2-c4b8md75k9
|
||||
9
pkg/commands/testdata/testcase-configmaps/overlay/dev/kustomization.yaml
vendored
Normal file
9
pkg/commands/testdata/testcase-configmaps/overlay/dev/kustomization.yaml
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
bases:
|
||||
- myapp/mycomponent
|
||||
- myapp/mycomponent2
|
||||
configMapGenerator:
|
||||
- name: com1
|
||||
behavior: merge
|
||||
literals:
|
||||
- foo=bar
|
||||
- baz=qux
|
||||
7
pkg/commands/testdata/testcase-configmaps/overlay/dev/myapp/mycomponent/kustomization.yaml
vendored
Normal file
7
pkg/commands/testdata/testcase-configmaps/overlay/dev/myapp/mycomponent/kustomization.yaml
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
bases:
|
||||
- ../../../../base/myapp/mycomponent
|
||||
configMapGenerator:
|
||||
- name: com1
|
||||
behavior: merge
|
||||
literals:
|
||||
- from=overlay
|
||||
7
pkg/commands/testdata/testcase-configmaps/overlay/dev/myapp/mycomponent2/kustomization.yaml
vendored
Normal file
7
pkg/commands/testdata/testcase-configmaps/overlay/dev/myapp/mycomponent2/kustomization.yaml
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
bases:
|
||||
- ../../../../base/myapp/mycomponent2
|
||||
configMapGenerator:
|
||||
- name: com2
|
||||
behavior: merge
|
||||
literals:
|
||||
- from=overlay
|
||||
5
pkg/commands/testdata/testcase-configmaps/test.yaml
vendored
Normal file
5
pkg/commands/testdata/testcase-configmaps/test.yaml
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
description: configmap generator overlay
|
||||
args: []
|
||||
filename: testdata/testcase-configmaps/overlay/dev
|
||||
expectedStdout: testdata/testcase-configmaps/expected.yaml
|
||||
expectedDiff: testdata/testcase-configmaps/expected.diff
|
||||
@@ -222,11 +222,13 @@ func MergeWithOverride(maps ...ResMap) (ResMap, error) {
|
||||
glog.V(4).Infof("Replace %v with %v", result[id].Object, r.Object)
|
||||
r.Replace(result[id])
|
||||
result[id] = r
|
||||
result[id].SetBehavior(resource.BehaviorCreate)
|
||||
case resource.BehaviorMerge:
|
||||
glog.V(4).Infof("Merging %v with %v", result[id].Object, r.Object)
|
||||
r.Merge(result[id])
|
||||
result[id] = r
|
||||
glog.V(4).Infof("Merged object is %v", result[id].Object)
|
||||
result[id].SetBehavior(resource.BehaviorCreate)
|
||||
default:
|
||||
return nil, fmt.Errorf("Id %#v exists; must merge or replace.", id)
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ metadata:
|
||||
}
|
||||
}
|
||||
|
||||
func TestMerge(t *testing.T) {
|
||||
func TestMergeWithoutOverride(t *testing.T) {
|
||||
input1 := ResMap{
|
||||
resource.NewResId(deploy, "deploy1"): resource.NewResourceFromMap(
|
||||
map[string]interface{}{
|
||||
@@ -199,3 +199,63 @@ func TestMerge(t *testing.T) {
|
||||
t.Fatalf("%#v doesn't equal expected %#v", merged, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMergeWithOverride(t *testing.T) {
|
||||
input1 := ResMap{
|
||||
resource.NewResId(cmap, "cmap"): resource.NewResourceFromMap(
|
||||
map[string]interface{}{
|
||||
"apiVersion": "apps/v1",
|
||||
"kind": "ConfigMap",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "cmap",
|
||||
},
|
||||
"data": map[string]interface{}{
|
||||
"a": "x",
|
||||
"b": "y",
|
||||
},
|
||||
}),
|
||||
}
|
||||
input2 := ResMap{
|
||||
resource.NewResId(cmap, "cmap"): resource.NewResourceFromMap(
|
||||
map[string]interface{}{
|
||||
"apiVersion": "apps/v1",
|
||||
"kind": "ConfigMap",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "cmap",
|
||||
},
|
||||
"data": map[string]interface{}{
|
||||
"a": "u",
|
||||
"b": "v",
|
||||
"c": "w",
|
||||
},
|
||||
}),
|
||||
}
|
||||
input1[resource.NewResId(cmap, "cmap")].SetBehavior(resource.BehaviorCreate)
|
||||
input2[resource.NewResId(cmap, "cmap")].SetBehavior(resource.BehaviorMerge)
|
||||
input := []ResMap{input1, input2}
|
||||
expected := ResMap{
|
||||
resource.NewResId(cmap, "cmap"): resource.NewResourceFromMap(
|
||||
map[string]interface{}{
|
||||
"apiVersion": "apps/v1",
|
||||
"kind": "ConfigMap",
|
||||
"metadata": map[string]interface{}{
|
||||
"annotations": map[string]interface{}{},
|
||||
"labels": map[string]interface{}{},
|
||||
"name": "cmap",
|
||||
},
|
||||
"data": map[string]interface{}{
|
||||
"a": "u",
|
||||
"b": "v",
|
||||
"c": "w",
|
||||
},
|
||||
}),
|
||||
}
|
||||
expected[resource.NewResId(cmap, "cmap")].SetBehavior(resource.BehaviorCreate)
|
||||
merged, err := MergeWithOverride(input...)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(merged, expected) {
|
||||
t.Fatalf("%#v doesn't equal expected %#v", merged, expected)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +61,11 @@ func (r *Resource) Behavior() GenerationBehavior {
|
||||
return r.b
|
||||
}
|
||||
|
||||
// SetBehavior changes the resource to the new behavior
|
||||
func (r *Resource) SetBehavior(b GenerationBehavior) {
|
||||
r.b = b
|
||||
}
|
||||
|
||||
// Id returns the ResId for the resource.
|
||||
func (r *Resource) Id() ResId {
|
||||
return NewResId(r.GroupVersionKind(), r.GetName())
|
||||
|
||||
Reference in New Issue
Block a user