...
1
2
3
4 package krusty_test
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import (
21 "testing"
22
23 kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
24 )
25
26 func TestConfMapNameResolutionInDiamondWithPatches(t *testing.T) {
27 th := kusttest_test.MakeHarness(t)
28
29 th.WriteK("bottom", `
30 configMapGenerator:
31 - name: bottom
32 literals:
33 - KEY=value
34 `)
35
36 th.WriteK("left-service", `
37 resources:
38 - deployment.yaml
39 `)
40
41 th.WriteF("left-service/deployment.yaml", `
42 apiVersion: apps/v1
43 kind: Deployment
44 metadata:
45 name: left-deploy
46 labels:
47 app.kubernetes.io/name: left-deploy
48 spec:
49 selector:
50 matchLabels:
51 app.kubernetes.io/name: left-pod
52 template:
53 metadata:
54 labels:
55 app.kubernetes.io/name: left-pod
56 spec:
57 containers:
58 - image: left-image:v1.0
59 name: service
60 `)
61
62 th.WriteK("right-service", `
63 resources:
64 - deployment.yaml
65 `)
66
67 th.WriteF("right-service/deployment.yaml", `
68 apiVersion: apps/v1
69 kind: Deployment
70 metadata:
71 name: right-deploy
72 labels:
73 app.kubernetes.io/name: right-deploy
74 spec:
75 selector:
76 matchLabels:
77 app.kubernetes.io/name: right-pod
78 template:
79 metadata:
80 labels:
81 app.kubernetes.io/name: right-pod
82 spec:
83 containers:
84 - image: right-image:v1.0
85 name: service
86 `)
87
88 th.WriteK("top", `
89 resources:
90 - ./left
91 - ./right
92 `)
93
94 th.WriteK("top/left", `
95 resources:
96 - ../../left-service
97 - ./bottom
98
99 patches:
100 - target:
101 kind: Deployment
102 name: left-deploy
103 patch: |-
104 apiVersion: apps/v1
105 kind: Deployment
106 metadata:
107 name: ignored-by-kustomize
108 spec:
109 template:
110 spec:
111 containers:
112 - name: service
113 env:
114 - name: MAPPED_CONFIG_ITEM
115 valueFrom:
116 configMapKeyRef:
117 name: left-bottom
118 key: KEY
119 `)
120
121 th.WriteK("top/left/bottom", `
122 namePrefix: left-
123
124 resources:
125 - ../../../bottom
126 `)
127
128 th.WriteK("top/right", `
129 resources:
130 - ../../right-service
131 - ./bottom
132
133 patches:
134 - target:
135 kind: Deployment
136 name: right-deploy
137 patch: |-
138 apiVersion: apps/v1
139 kind: Deployment
140 metadata:
141 name: ignored-by-kustomize
142 spec:
143 template:
144 spec:
145 containers:
146 - name: service
147 env:
148 - name: MAPPED_CONFIG_ITEM
149 valueFrom:
150 configMapKeyRef:
151 name: right-bottom
152 key: KEY
153 `)
154
155 th.WriteK("top/right/bottom", `
156 namePrefix: right-
157
158 resources:
159 - ../../../bottom
160 `)
161
162 m := th.Run("top", th.MakeDefaultOptions())
163 th.AssertActualEqualsExpected(m, `apiVersion: apps/v1
164 kind: Deployment
165 metadata:
166 labels:
167 app.kubernetes.io/name: left-deploy
168 name: left-deploy
169 spec:
170 selector:
171 matchLabels:
172 app.kubernetes.io/name: left-pod
173 template:
174 metadata:
175 labels:
176 app.kubernetes.io/name: left-pod
177 spec:
178 containers:
179 - env:
180 - name: MAPPED_CONFIG_ITEM
181 valueFrom:
182 configMapKeyRef:
183 key: KEY
184 name: left-bottom-9f2t6f5h6d
185 image: left-image:v1.0
186 name: service
187 ---
188 apiVersion: v1
189 data:
190 KEY: value
191 kind: ConfigMap
192 metadata:
193 name: left-bottom-9f2t6f5h6d
194 ---
195 apiVersion: apps/v1
196 kind: Deployment
197 metadata:
198 labels:
199 app.kubernetes.io/name: right-deploy
200 name: right-deploy
201 spec:
202 selector:
203 matchLabels:
204 app.kubernetes.io/name: right-pod
205 template:
206 metadata:
207 labels:
208 app.kubernetes.io/name: right-pod
209 spec:
210 containers:
211 - env:
212 - name: MAPPED_CONFIG_ITEM
213 valueFrom:
214 configMapKeyRef:
215 key: KEY
216 name: right-bottom-9f2t6f5h6d
217 image: right-image:v1.0
218 name: service
219 ---
220 apiVersion: v1
221 data:
222 KEY: value
223 kind: ConfigMap
224 metadata:
225 name: right-bottom-9f2t6f5h6d
226 `)
227 }
228
View as plain text