mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-29 01:30:51 +00:00
Compare commits
816 Commits
api/v0.4.0
...
api/v0.6.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
351a4a48e4 | ||
|
|
b3cf475024 | ||
|
|
ded25075b1 | ||
|
|
05b8671d17 | ||
|
|
1bfcc81f08 | ||
|
|
3d058830b9 | ||
|
|
bdb53fca9e | ||
|
|
b7265440f8 | ||
|
|
72e1a27177 | ||
|
|
0a1fde1e41 | ||
|
|
ae4618d327 | ||
|
|
aee6ccb05c | ||
|
|
3cd2a0a2f7 | ||
|
|
c96fa7c347 | ||
|
|
ad01d8d34e | ||
|
|
b214fa7d5a | ||
|
|
68f67c183e | ||
|
|
fe5c3a291f | ||
|
|
f38cc4446b | ||
|
|
e695b0534d | ||
|
|
51ecca8f2f | ||
|
|
460c54064c | ||
|
|
50c0200429 | ||
|
|
b1b5a95466 | ||
|
|
3f71c671df | ||
|
|
2ce9c02ada | ||
|
|
3ffc13dd6e | ||
|
|
2fb8603b2a | ||
|
|
1d4b3fa36c | ||
|
|
03ea8f3615 | ||
|
|
74d0d7960e | ||
|
|
ffed4c95b3 | ||
|
|
c59b393fa4 | ||
|
|
fafe24c9df | ||
|
|
d62d8dcade | ||
|
|
ae7f984c71 | ||
|
|
7c8c827a88 | ||
|
|
ff927fd11a | ||
|
|
a4f6fee6c8 | ||
|
|
dd8edb1b01 | ||
|
|
bb42d8aa1b | ||
|
|
bb60c29672 | ||
|
|
c93274c224 | ||
|
|
f5feffbd23 | ||
|
|
e17bab7e55 | ||
|
|
bd534441ce | ||
|
|
85f79edc97 | ||
|
|
4c48a4ff83 | ||
|
|
eb6c715bc3 | ||
|
|
1320e0c3dc | ||
|
|
df0022c985 | ||
|
|
15fc341a13 | ||
|
|
dd90c41f85 | ||
|
|
3a5951563d | ||
|
|
acdfd9a920 | ||
|
|
52016b22dd | ||
|
|
11049fa0bb | ||
|
|
db6c825c05 | ||
|
|
cb7974cf45 | ||
|
|
00111846d3 | ||
|
|
eafa37810b | ||
|
|
0c0cb9aaba | ||
|
|
b51e09d5fe | ||
|
|
c8cd5e55fc | ||
|
|
103d1461a1 | ||
|
|
f02af7a48b | ||
|
|
eba9edd7a6 | ||
|
|
cf38166bd6 | ||
|
|
03498b46b8 | ||
|
|
9fa9c6c30c | ||
|
|
884e35b4c8 | ||
|
|
28787396b2 | ||
|
|
e3cf8987e1 | ||
|
|
551841b789 | ||
|
|
66740dfad6 | ||
|
|
537ff024dd | ||
|
|
cfab28a5ff | ||
|
|
471d5ccf84 | ||
|
|
6a9e75ee0d | ||
|
|
7500764cbf | ||
|
|
544fc60bfe | ||
|
|
0850eae0b9 | ||
|
|
3818cebe33 | ||
|
|
31b395a33f | ||
|
|
ce0dba9217 | ||
|
|
9abd0119e1 | ||
|
|
b6c6cfa7ac | ||
|
|
0c5fc5e694 | ||
|
|
64cbfbe56d | ||
|
|
6a94eb873f | ||
|
|
0bfec6b39b | ||
|
|
9002c338cb | ||
|
|
f86cb6479e | ||
|
|
8285af8cf1 | ||
|
|
5fa1282dcb | ||
|
|
5a0abc8b12 | ||
|
|
3f2508fa94 | ||
|
|
9d992aae68 | ||
|
|
8c906b804f | ||
|
|
4ff4940fa7 | ||
|
|
09aec5694a | ||
|
|
1f917c0499 | ||
|
|
225ffc7cd8 | ||
|
|
eb638cc312 | ||
|
|
7dfb96425e | ||
|
|
6d4c6127c8 | ||
|
|
6aa72b66ef | ||
|
|
f03fdc09cb | ||
|
|
30b6eeb460 | ||
|
|
bf67fcb6d6 | ||
|
|
4ae420cce1 | ||
|
|
87d2187436 | ||
|
|
f1dabbd4fc | ||
|
|
747e05f2a4 | ||
|
|
3514317b3d | ||
|
|
9299821571 | ||
|
|
d91f313137 | ||
|
|
161af9d99c | ||
|
|
b115c95ea1 | ||
|
|
4c75dac10a | ||
|
|
2f8a376ae4 | ||
|
|
20cd4bfef9 | ||
|
|
b314ca185f | ||
|
|
f6c06b58ef | ||
|
|
c45e05b7bd | ||
|
|
76bae738a0 | ||
|
|
98c88805c3 | ||
|
|
0770661b2a | ||
|
|
67d5871e87 | ||
|
|
f98c683915 | ||
|
|
ffe9c9d947 | ||
|
|
4d42ffc7f8 | ||
|
|
d7dc7d911e | ||
|
|
04404ff61b | ||
|
|
f864e15c68 | ||
|
|
29a444fffc | ||
|
|
327035a43a | ||
|
|
ad7fed061e | ||
|
|
cea2986574 | ||
|
|
00f0fd7109 | ||
|
|
1c6481d011 | ||
|
|
f0bc926640 | ||
|
|
11d9ff5690 | ||
|
|
6a0a909e73 | ||
|
|
bd8f0c88e5 | ||
|
|
e5809e49cb | ||
|
|
880009b648 | ||
|
|
d083c7f1d0 | ||
|
|
684ce141de | ||
|
|
5c8c7a043a | ||
|
|
0fe7f65ef2 | ||
|
|
950c1de46d | ||
|
|
fc690f14a8 | ||
|
|
a6e03e4d11 | ||
|
|
60428be5fb | ||
|
|
4d402d4875 | ||
|
|
fbddd264be | ||
|
|
d3c46d3f7c | ||
|
|
dda3984a8f | ||
|
|
f889ca8885 | ||
|
|
341bacb9a2 | ||
|
|
badc1177d9 | ||
|
|
1680cc72c0 | ||
|
|
2f89de86f8 | ||
|
|
ab4e9c718b | ||
|
|
288c03ddca | ||
|
|
5c60285f25 | ||
|
|
6df0a45368 | ||
|
|
8206987580 | ||
|
|
6189ca9798 | ||
|
|
b8c1601a93 | ||
|
|
34d610a38d | ||
|
|
8e4c8464e7 | ||
|
|
43ab7a8e71 | ||
|
|
d2f23a4b8b | ||
|
|
0dc36a4f7c | ||
|
|
678ae12115 | ||
|
|
c4d937322f | ||
|
|
a2adb835b6 | ||
|
|
01b5c4e9da | ||
|
|
5a4e2c2898 | ||
|
|
51719d8089 | ||
|
|
eb4c5dc035 | ||
|
|
e976386931 | ||
|
|
bae9986422 | ||
|
|
e7970d82a8 | ||
|
|
9bdd489c96 | ||
|
|
0f49fef5ed | ||
|
|
8d74b8c3b5 | ||
|
|
39a8798a87 | ||
|
|
980f407552 | ||
|
|
9ca8f4602d | ||
|
|
ba0f583ee5 | ||
|
|
f432f4d75e | ||
|
|
17793abacd | ||
|
|
64cd4ec1d5 | ||
|
|
fb822984e3 | ||
|
|
6d2a737c29 | ||
|
|
6e7713281e | ||
|
|
6a7bb9e33e | ||
|
|
0e9428c8b0 | ||
|
|
c838962432 | ||
|
|
548d10ef08 | ||
|
|
2db8487f02 | ||
|
|
b42f71a20f | ||
|
|
e9824aa749 | ||
|
|
92cc9fc5e1 | ||
|
|
e53b4c9884 | ||
|
|
d4503dfd1e | ||
|
|
e2973f6ecc | ||
|
|
2bf9fc816d | ||
|
|
ff55856c63 | ||
|
|
ceef219eec | ||
|
|
b21699a277 | ||
|
|
2ab85d2f63 | ||
|
|
320545884c | ||
|
|
16bbc2d67e | ||
|
|
6d860e8ace | ||
|
|
80c8a6df61 | ||
|
|
90bc96d9d8 | ||
|
|
2be59aefec | ||
|
|
91b779269f | ||
|
|
e6ea4ad260 | ||
|
|
f5cab0f6e1 | ||
|
|
e39afc9f68 | ||
|
|
3801a29d9b | ||
|
|
39cf4af638 | ||
|
|
9d65dd0786 | ||
|
|
3dced70850 | ||
|
|
4356043582 | ||
|
|
c202be0338 | ||
|
|
9359155418 | ||
|
|
ba22bbe19e | ||
|
|
3e5989ae18 | ||
|
|
fbebd990a4 | ||
|
|
257707d839 | ||
|
|
c1cd872df6 | ||
|
|
646e0b4f61 | ||
|
|
0f67692265 | ||
|
|
6a7afd8694 | ||
|
|
46194b3385 | ||
|
|
904a9dea08 | ||
|
|
30b58e90a3 | ||
|
|
5bdd8657a5 | ||
|
|
893c99da1c | ||
|
|
43980f8586 | ||
|
|
0c8e033c96 | ||
|
|
fa15242719 | ||
|
|
a2e080bf6c | ||
|
|
e91cdb5eba | ||
|
|
ef54f9be5a | ||
|
|
f051acb83c | ||
|
|
bbb046081b | ||
|
|
77b28a986f | ||
|
|
97bc34eb37 | ||
|
|
719380f523 | ||
|
|
640ae9521b | ||
|
|
1dffc7577b | ||
|
|
a0b7288329 | ||
|
|
cc5617c048 | ||
|
|
a77d7e5164 | ||
|
|
40dc90b3b1 | ||
|
|
16229095b3 | ||
|
|
1d91401772 | ||
|
|
007a5327d7 | ||
|
|
24beeb429d | ||
|
|
9b4d4c9d46 | ||
|
|
d5f868c5c7 | ||
|
|
ff3f39d84b | ||
|
|
451c5c32c9 | ||
|
|
faef5714bf | ||
|
|
7833c6edcf | ||
|
|
a1cd23c91d | ||
|
|
e39a5adc00 | ||
|
|
b6900ead22 | ||
|
|
d03cf061e8 | ||
|
|
8293f3002d | ||
|
|
edced4b3f6 | ||
|
|
501684a9c6 | ||
|
|
4e42e1a058 | ||
|
|
b450b624e8 | ||
|
|
0be4a61f64 | ||
|
|
596c39b7bc | ||
|
|
037ac3b134 | ||
|
|
0ff4e53046 | ||
|
|
660f7f9435 | ||
|
|
e6ee03e3e3 | ||
|
|
ca04c874f2 | ||
|
|
cbfef858a0 | ||
|
|
62fbfdfa21 | ||
|
|
5d72fbc6c9 | ||
|
|
bc37ec9d88 | ||
|
|
8619c9aa13 | ||
|
|
5d8722a786 | ||
|
|
0d5552fca6 | ||
|
|
8a8e35f3bb | ||
|
|
25dbe1eaa8 | ||
|
|
2289e7d2e9 | ||
|
|
eb0f484e3d | ||
|
|
d438271263 | ||
|
|
c4c8decb74 | ||
|
|
0590b225c7 | ||
|
|
45131a6d62 | ||
|
|
4dfe3c6296 | ||
|
|
881f358228 | ||
|
|
86c93b9fb7 | ||
|
|
25e30de2d6 | ||
|
|
a8160356bd | ||
|
|
32de6de313 | ||
|
|
501ec38777 | ||
|
|
1b2a966c62 | ||
|
|
bcdbb1a282 | ||
|
|
01f28e6779 | ||
|
|
3f8e3686e2 | ||
|
|
b47e34ea5e | ||
|
|
762e587471 | ||
|
|
6f782ac8c3 | ||
|
|
e5bc644653 | ||
|
|
1bc9225302 | ||
|
|
99d7ad6dc9 | ||
|
|
345dbc83e3 | ||
|
|
8ddf2297e8 | ||
|
|
b407675fc0 | ||
|
|
fd5eeb1645 | ||
|
|
ff5051711f | ||
|
|
51268a5f06 | ||
|
|
1366e0344a | ||
|
|
9be38e815e | ||
|
|
88c318bf46 | ||
|
|
b71b36a213 | ||
|
|
e5a78710aa | ||
|
|
7ee75c33a9 | ||
|
|
2b328eeb36 | ||
|
|
4da40461d3 | ||
|
|
c96a4f3d73 | ||
|
|
45893b2588 | ||
|
|
2f3c89e73f | ||
|
|
eee581462c | ||
|
|
616363ee73 | ||
|
|
0e13eadd7a | ||
|
|
0c37388135 | ||
|
|
5d1352882b | ||
|
|
c469e80cad | ||
|
|
5559601ecb | ||
|
|
01b34c8ea0 | ||
|
|
eba0ffdde2 | ||
|
|
31c59bd7f2 | ||
|
|
bd7d0f864b | ||
|
|
2da8959198 | ||
|
|
dc591f0a10 | ||
|
|
c94f164e66 | ||
|
|
fb216d8af8 | ||
|
|
72207bfa04 | ||
|
|
fe3321d710 | ||
|
|
35b5890e46 | ||
|
|
ca807019f0 | ||
|
|
6420fc4911 | ||
|
|
bd8262630e | ||
|
|
cf5b26db8a | ||
|
|
4b4049e646 | ||
|
|
f211841035 | ||
|
|
efa4587f92 | ||
|
|
873c8c1d17 | ||
|
|
686e97f2fe | ||
|
|
669ae59982 | ||
|
|
868a226e4e | ||
|
|
a2693d0249 | ||
|
|
b7d913b58c | ||
|
|
f199b747e9 | ||
|
|
5a9fbf7da3 | ||
|
|
c18c803d3f | ||
|
|
d59d0401f4 | ||
|
|
83a70f7830 | ||
|
|
6afabf26ae | ||
|
|
2bcece5f1e | ||
|
|
e605391895 | ||
|
|
9de2c6b58e | ||
|
|
b3f147d012 | ||
|
|
fc70e3181f | ||
|
|
8cd7c13fad | ||
|
|
740ec39dd8 | ||
|
|
e6927a2fdf | ||
|
|
083dccfe91 | ||
|
|
b61553e584 | ||
|
|
8cdc97a0dd | ||
|
|
f205641498 | ||
|
|
bfaca2122a | ||
|
|
9482c571f0 | ||
|
|
1ad49de087 | ||
|
|
5e89565930 | ||
|
|
ef713e33ce | ||
|
|
2f7241f4c3 | ||
|
|
34e0ade3e7 | ||
|
|
436c688bd0 | ||
|
|
9d8fbd9f04 | ||
|
|
bb6fb703a0 | ||
|
|
c99bc47c8d | ||
|
|
60422c8090 | ||
|
|
fc83477ec8 | ||
|
|
c9e8631399 | ||
|
|
974e3847dd | ||
|
|
8f4e7e8072 | ||
|
|
4e74947731 | ||
|
|
43b0f2d925 | ||
|
|
efd5f414a8 | ||
|
|
9b8232533f | ||
|
|
bc5859d44b | ||
|
|
5c433ead5e | ||
|
|
feeaa994b7 | ||
|
|
17f935452f | ||
|
|
6faff2d031 | ||
|
|
18a86bd7d6 | ||
|
|
7eac250cf4 | ||
|
|
52083c6e49 | ||
|
|
6f63cf7238 | ||
|
|
de0c8dedc4 | ||
|
|
c23004df79 | ||
|
|
1a44c3c543 | ||
|
|
a9d1182322 | ||
|
|
a3d5628133 | ||
|
|
a563169461 | ||
|
|
729544b9f4 | ||
|
|
69d497ccdd | ||
|
|
c58c142849 | ||
|
|
9ba04e3f7d | ||
|
|
3f842e5e92 | ||
|
|
9fdb3e1e9e | ||
|
|
462dbcb999 | ||
|
|
3e0448f1b7 | ||
|
|
3c3f9a26f6 | ||
|
|
7d7c889285 | ||
|
|
4fe2f9dd5b | ||
|
|
0cb852b98a | ||
|
|
7f5ce3e6f0 | ||
|
|
bf5656b02b | ||
|
|
0ec901a9a9 | ||
|
|
af057a95c5 | ||
|
|
c48e584d1a | ||
|
|
2ee4eec791 | ||
|
|
f06a64e9cc | ||
|
|
51f9a84358 | ||
|
|
07c25eb458 | ||
|
|
ba57cdbd99 | ||
|
|
8a9dc011f4 | ||
|
|
fd196f5d70 | ||
|
|
4c577f6667 | ||
|
|
65fd7c3e6e | ||
|
|
1dff481883 | ||
|
|
d437f67035 | ||
|
|
ee57e9db12 | ||
|
|
a0fdcfe2e3 | ||
|
|
d9fe98a289 | ||
|
|
8b9829f222 | ||
|
|
2114b97969 | ||
|
|
508d193e7a | ||
|
|
e0eb79adcc | ||
|
|
dcab3cbb5f | ||
|
|
8225ca45a8 | ||
|
|
ef924a5c9c | ||
|
|
33b03fce89 | ||
|
|
3907643880 | ||
|
|
b7f7536cfa | ||
|
|
15bc399d5a | ||
|
|
46a6bf0bb4 | ||
|
|
6717bbd36b | ||
|
|
6fccb7fd48 | ||
|
|
370a3d2e74 | ||
|
|
eb7beba8ad | ||
|
|
1e3bc51645 | ||
|
|
92e1d452b7 | ||
|
|
7abedcf87b | ||
|
|
aa991956ef | ||
|
|
c6524f984c | ||
|
|
a70c6b3496 | ||
|
|
166c7f3167 | ||
|
|
10371aa1b5 | ||
|
|
95fb639fa8 | ||
|
|
0f7aae38e3 | ||
|
|
c660fd33ae | ||
|
|
108195185f | ||
|
|
4fbe565b36 | ||
|
|
e9bc2c00c1 | ||
|
|
45eed23b26 | ||
|
|
27b2c7f294 | ||
|
|
03d6229c0b | ||
|
|
71b7b00bd8 | ||
|
|
e9396dca2c | ||
|
|
bc581b70bf | ||
|
|
ac1c31c82b | ||
|
|
c878957d0b | ||
|
|
f9ee578aed | ||
|
|
0b359d0ef0 | ||
|
|
22ee7cbd49 | ||
|
|
7bf9c7002f | ||
|
|
155411f229 | ||
|
|
699cc70a7c | ||
|
|
a63a472024 | ||
|
|
e894756003 | ||
|
|
55f55a5091 | ||
|
|
8401196ef9 | ||
|
|
14edc3890c | ||
|
|
897698fb29 | ||
|
|
ec9ae3d7b0 | ||
|
|
3a828941fa | ||
|
|
b63b5ce7cc | ||
|
|
23bd4390d3 | ||
|
|
21a0fd33a2 | ||
|
|
c6b6dec91f | ||
|
|
9cf4367db7 | ||
|
|
e9c118fd55 | ||
|
|
bfbb1971d4 | ||
|
|
6fabfe963e | ||
|
|
67cdd2e27e | ||
|
|
6c6b5f744d | ||
|
|
7775666c50 | ||
|
|
bdd7ae085e | ||
|
|
ba3e09849a | ||
|
|
236ae29e9a | ||
|
|
5c3bd83252 | ||
|
|
3674e0a91d | ||
|
|
f9631e4bb2 | ||
|
|
c419c1efc3 | ||
|
|
63f9f79fc0 | ||
|
|
33e68c0f97 | ||
|
|
556eb48651 | ||
|
|
5b26c3b4cc | ||
|
|
42e19d610a | ||
|
|
950b1c895f | ||
|
|
ca5feb7751 | ||
|
|
488a88ec6e | ||
|
|
fd3a4a88be | ||
|
|
e6147347a8 | ||
|
|
0b756877e1 | ||
|
|
0f4b5e6787 | ||
|
|
1b531c6ac7 | ||
|
|
f6cac7e7e8 | ||
|
|
fe0577a15f | ||
|
|
f68740be66 | ||
|
|
855ce1a8db | ||
|
|
6a50372dd5 | ||
|
|
5a0228629f | ||
|
|
def00220ce | ||
|
|
d3a7335bbc | ||
|
|
94095a63ff | ||
|
|
42d1f7b792 | ||
|
|
8912c454ff | ||
|
|
d4eb2c9426 | ||
|
|
d2b95fb09a | ||
|
|
298b3c8622 | ||
|
|
c12e95fe06 | ||
|
|
87c7a32ffe | ||
|
|
a7545bdad3 | ||
|
|
622a121042 | ||
|
|
c2ccfd72ad | ||
|
|
6d324d70c4 | ||
|
|
c7bc9d2066 | ||
|
|
9567d7ef16 | ||
|
|
e5b0ceb4e3 | ||
|
|
5fb238a581 | ||
|
|
3ddc9af6c5 | ||
|
|
128e171c20 | ||
|
|
c2681b6fae | ||
|
|
ae5c392319 | ||
|
|
66bcf84682 | ||
|
|
436dada184 | ||
|
|
a689e0c2b4 | ||
|
|
30ae7183a4 | ||
|
|
279a9b673f | ||
|
|
0ac45c65c9 | ||
|
|
d7fb813c16 | ||
|
|
83c5c4d1f1 | ||
|
|
7259d3eb48 | ||
|
|
0e44202c20 | ||
|
|
0d90b769f1 | ||
|
|
7ad2791072 | ||
|
|
6de94548ba | ||
|
|
b1b190227e | ||
|
|
4ceddaa8f4 | ||
|
|
9e64ac5315 | ||
|
|
f24ec14956 | ||
|
|
98a92a6443 | ||
|
|
8bb612889c | ||
|
|
e3ec184e92 | ||
|
|
3019230283 | ||
|
|
69adcf9aaf | ||
|
|
8d543d8483 | ||
|
|
94a55210e1 | ||
|
|
441581b745 | ||
|
|
a066ba9628 | ||
|
|
3a0dd72c88 | ||
|
|
d4ed285fd1 | ||
|
|
4cae8cfe9b | ||
|
|
b044a52a84 | ||
|
|
5607478d8e | ||
|
|
d60cf8ebc5 | ||
|
|
ef04983392 | ||
|
|
2153863355 | ||
|
|
4afab168c5 | ||
|
|
2c52e3a851 | ||
|
|
781e396122 | ||
|
|
cebb1b31ab | ||
|
|
9137d2a39a | ||
|
|
95f4ecd261 | ||
|
|
600d4f2c0b | ||
|
|
6c4c5cf9ad | ||
|
|
5f5b23af58 | ||
|
|
ae5a690146 | ||
|
|
625e011e2b | ||
|
|
01ce33b926 | ||
|
|
a323d78bbc | ||
|
|
69dc34500a | ||
|
|
919bdb84c9 | ||
|
|
178f4e21f0 | ||
|
|
d732a6faab | ||
|
|
f053ca6a5f | ||
|
|
dfc5c32af5 | ||
|
|
80b3f4e00a | ||
|
|
4646bca230 | ||
|
|
57ca8fa321 | ||
|
|
de7fa4bf3a | ||
|
|
af1280ea43 | ||
|
|
0dd191c0f6 | ||
|
|
e20e126d65 | ||
|
|
abf862fff1 | ||
|
|
27cf3981ca | ||
|
|
2c39ff0fa0 | ||
|
|
afc14afe45 | ||
|
|
6e91e0667d | ||
|
|
1aca8b8b9e | ||
|
|
448c060084 | ||
|
|
b3951942e3 | ||
|
|
b78464c8b1 | ||
|
|
9bd4f78288 | ||
|
|
85e9fa94b0 | ||
|
|
c754927112 | ||
|
|
8049c57b72 | ||
|
|
695ec44bf7 | ||
|
|
5b394b2079 | ||
|
|
97c2ac77cd | ||
|
|
3183fcc926 | ||
|
|
0af9ca1266 | ||
|
|
a6111b5c3c | ||
|
|
fdbd1bdbbb | ||
|
|
16baf7a955 | ||
|
|
69aea07c4e | ||
|
|
2250ad3e18 | ||
|
|
c107d1ddff | ||
|
|
e32aa8ddb2 | ||
|
|
b92de5cb80 | ||
|
|
ecfa732a04 | ||
|
|
f17b893dd2 | ||
|
|
09894d3022 | ||
|
|
fd3e84f701 | ||
|
|
22d5d4d2c1 | ||
|
|
145ba0c7ff | ||
|
|
a83433d5cf | ||
|
|
2d496e0efe | ||
|
|
171412cc98 | ||
|
|
68ab3b87d9 | ||
|
|
e9bd11caaa | ||
|
|
a895220743 | ||
|
|
ab2dc7fcb9 | ||
|
|
afde29601a | ||
|
|
be0f1a7fcb | ||
|
|
99d2994b98 | ||
|
|
94101fb7cc | ||
|
|
346071897e | ||
|
|
0772540214 | ||
|
|
6791688f5f | ||
|
|
28307bc435 | ||
|
|
29cadfe8b0 | ||
|
|
68f4f330f5 | ||
|
|
507779c9dc | ||
|
|
062d0f7b75 | ||
|
|
e783af2881 | ||
|
|
f2da1f621f | ||
|
|
294312f2fc | ||
|
|
ff79bd0b31 | ||
|
|
410e300243 | ||
|
|
e994b3b566 | ||
|
|
b39c522cc1 | ||
|
|
dc4bf03da2 | ||
|
|
a158eeaaff | ||
|
|
4cd3944860 | ||
|
|
79a48a8802 | ||
|
|
5a33e90f18 | ||
|
|
e77d1a881f | ||
|
|
343b938c73 | ||
|
|
25186e94af | ||
|
|
e4ba898e20 | ||
|
|
22a6017870 | ||
|
|
e62f1adabf | ||
|
|
7e2d3ff5ab | ||
|
|
fb6830c98a | ||
|
|
52e8a701ac | ||
|
|
160485ef19 | ||
|
|
cea1154cd9 | ||
|
|
4843718a2b | ||
|
|
a0c1979798 | ||
|
|
8576acf1aa | ||
|
|
1e7a764900 | ||
|
|
9b5ce5002a | ||
|
|
0952421800 | ||
|
|
df9af1869f | ||
|
|
dbb16dcb6d | ||
|
|
cc8fc99999 | ||
|
|
0f0efe2a4c | ||
|
|
36165d2843 | ||
|
|
3e9276271a | ||
|
|
af7df1448d | ||
|
|
518147c129 | ||
|
|
a0072a2cf9 | ||
|
|
c4518e964f | ||
|
|
c2eb09cd8f | ||
|
|
89b4e7ae02 | ||
|
|
714ff85806 | ||
|
|
589ddcb4fa | ||
|
|
3d09b0cb83 | ||
|
|
3012dd67ac | ||
|
|
60f826fb2d | ||
|
|
5d24062d42 | ||
|
|
d553919dfb | ||
|
|
661743c7e5 | ||
|
|
1dc22e3f0d | ||
|
|
808843457a | ||
|
|
42497c664f | ||
|
|
88cc78d5b7 | ||
|
|
9ac9a28db7 | ||
|
|
5cf0d887b1 | ||
|
|
58c2df2dec | ||
|
|
1644fdd076 | ||
|
|
cd25740b61 | ||
|
|
28045399f3 | ||
|
|
e630334837 | ||
|
|
b97df057c1 | ||
|
|
546a7386ff | ||
|
|
4b117c4736 | ||
|
|
bc968d17e3 | ||
|
|
51c2fe9742 | ||
|
|
25a38ad2b6 | ||
|
|
8046efd261 | ||
|
|
9a4acba118 | ||
|
|
d9d67e33e7 | ||
|
|
18d6a96f80 | ||
|
|
458a7c532c | ||
|
|
701c217791 | ||
|
|
e042a22d0f | ||
|
|
4fca00014c | ||
|
|
1c2eaa9d29 | ||
|
|
1f32e89d95 | ||
|
|
b7a379604c | ||
|
|
cea461e8f2 | ||
|
|
73157c7141 | ||
|
|
72dc895c52 | ||
|
|
2aca65a126 | ||
|
|
ac2e6990c3 | ||
|
|
8f0900f95e | ||
|
|
2549a8c6be | ||
|
|
88ebe1c73e | ||
|
|
08922cfe29 | ||
|
|
952a2ebbf4 | ||
|
|
075846c731 | ||
|
|
d531de6774 | ||
|
|
cedcf3ac04 | ||
|
|
8ce637a004 | ||
|
|
10250286c7 | ||
|
|
a43d43f2c4 | ||
|
|
8356979e1f | ||
|
|
46d9a8dc46 | ||
|
|
cb3854edaa | ||
|
|
083a266b0b | ||
|
|
d6fdf1c01a | ||
|
|
b679e33d47 | ||
|
|
e63b9ef825 | ||
|
|
4b5b0dfdce | ||
|
|
572260c0f0 | ||
|
|
0e5e2648b3 | ||
|
|
144471ce78 | ||
|
|
98cb7fc8cd | ||
|
|
ca8e00fc15 | ||
|
|
93b0b1b0b1 | ||
|
|
34a442bbef | ||
|
|
37918ae745 | ||
|
|
dca164e967 | ||
|
|
8ac2365406 | ||
|
|
c1a2bf14da | ||
|
|
a7af7df9cb | ||
|
|
8d148c7ee4 | ||
|
|
0b94a1405d | ||
|
|
b083187e6a | ||
|
|
4dcf81050e | ||
|
|
c97fa946d5 | ||
|
|
c35f5b0189 | ||
|
|
dd4aafe148 | ||
|
|
adb56abd99 | ||
|
|
def978b334 | ||
|
|
f7ca4fa106 | ||
|
|
ff7a7937c5 | ||
|
|
90c23026c2 | ||
|
|
e5e4f33ac7 | ||
|
|
5449dbc775 | ||
|
|
52c5a9d380 | ||
|
|
74d59f87c2 | ||
|
|
98ba8b7491 | ||
|
|
e05404f89c | ||
|
|
9e40cc177a | ||
|
|
315f7c6e7f | ||
|
|
b3f5874978 | ||
|
|
59f8f4ae14 | ||
|
|
ab9d4c7e7b | ||
|
|
7bae481252 | ||
|
|
c5c53011da | ||
|
|
fdfb58cc3e | ||
|
|
1079d8604c | ||
|
|
4454edc14c | ||
|
|
bf71dce60c |
68
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
68
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Create a report to help us improve
|
||||||
|
title: ""
|
||||||
|
labels:
|
||||||
|
- kind/bug
|
||||||
|
assignees: ""
|
||||||
|
---
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Please read this page: https://kubernetes-sigs.github.io/kustomize/contributing/bugs/ before
|
||||||
|
filing a bug
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- Feel free to skip the sections if they are not applicable. -->
|
||||||
|
|
||||||
|
**Describe the bug**
|
||||||
|
|
||||||
|
<!-- A clear and concise description of what the bug is. -->
|
||||||
|
|
||||||
|
**Files that can reproduce the issue**
|
||||||
|
|
||||||
|
<!--
|
||||||
|
We cannot figure out or fix the issue if we don't know how to reproduce. Please
|
||||||
|
provide a minimum set of files that can reproduce the issue. You can paste the
|
||||||
|
file contents here or provide a link to a tarball or git repo.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
kustomization.yaml
|
||||||
|
|
||||||
|
```
|
||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
resources:
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
resources.yaml
|
||||||
|
|
||||||
|
```
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Deployment
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
...
|
||||||
|
-->
|
||||||
|
|
||||||
|
**Expected output**
|
||||||
|
|
||||||
|
<!-- What's the expected output? -->
|
||||||
|
|
||||||
|
**Actual output**
|
||||||
|
|
||||||
|
<!-- What's the actual output? -->
|
||||||
|
|
||||||
|
**Kustomize version**
|
||||||
|
|
||||||
|
<!-- Please use the latest version when it's possible. -->
|
||||||
|
|
||||||
|
**Platform**
|
||||||
|
|
||||||
|
<!-- Linux/macOS/Windows? -->
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
|
||||||
|
<!-- Add any other context about the problem here. -->
|
||||||
1
.github/ISSUE_TEMPLATE/config.yaml
vendored
Normal file
1
.github/ISSUE_TEMPLATE/config.yaml
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
blank_issues_enabled: true
|
||||||
26
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
26
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
---
|
||||||
|
name: Feature request
|
||||||
|
about: Suggest an idea for this project
|
||||||
|
title: ""
|
||||||
|
labels:
|
||||||
|
- kind/feature
|
||||||
|
assignees: ""
|
||||||
|
---
|
||||||
|
|
||||||
|
<!-- Feel free to skip the sections if they are not applicable. -->
|
||||||
|
|
||||||
|
**Is your feature request related to a problem? Please describe.**
|
||||||
|
|
||||||
|
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->
|
||||||
|
|
||||||
|
**Describe the solution you'd like**
|
||||||
|
|
||||||
|
<!-- A clear and concise description of what you want to happen. -->
|
||||||
|
|
||||||
|
**Describe alternatives you've considered**
|
||||||
|
|
||||||
|
<!-- A clear and concise description of any alternative solutions or features you've considered. -->
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
|
||||||
|
<!-- Add any other context or screenshots about the feature request here. -->
|
||||||
9
.github/ISSUE_TEMPLATE/question.md
vendored
Normal file
9
.github/ISSUE_TEMPLATE/question.md
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
---
|
||||||
|
name: Question
|
||||||
|
about: Ask a question about the kustomize
|
||||||
|
title: "[Question]"
|
||||||
|
labels: ""
|
||||||
|
assignees: ""
|
||||||
|
---
|
||||||
|
|
||||||
|
<!-- Please describe your question here -->
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -19,3 +19,5 @@
|
|||||||
|
|
||||||
# macOS
|
# macOS
|
||||||
*.DS_store
|
*.DS_store
|
||||||
|
|
||||||
|
.bin
|
||||||
|
|||||||
46
Makefile
46
Makefile
@@ -14,11 +14,9 @@ all: verify-kustomize
|
|||||||
verify-kustomize: \
|
verify-kustomize: \
|
||||||
lint-kustomize \
|
lint-kustomize \
|
||||||
test-unit-kustomize-all \
|
test-unit-kustomize-all \
|
||||||
test-examples-kustomize-against-HEAD
|
test-examples-kustomize-against-HEAD \
|
||||||
# TODO: restore test-examples-kustomize-against-3.5.5 \
|
test-examples-kustomize-against-3.8.0 \
|
||||||
# once it works. Likely have to fix and release 3.6
|
test-examples-kustomize-against-3.8.2
|
||||||
# test-examples-kustomize-against-3.5.4 no longer works because
|
|
||||||
# the examples tests features not in 3.5.4
|
|
||||||
|
|
||||||
# The following target referenced by a file in
|
# The following target referenced by a file in
|
||||||
# https://github.com/kubernetes/test-infra/tree/master/config/jobs/kubernetes-sigs/kustomize
|
# https://github.com/kubernetes/test-infra/tree/master/config/jobs/kubernetes-sigs/kustomize
|
||||||
@@ -26,9 +24,11 @@ verify-kustomize: \
|
|||||||
prow-presubmit-check: \
|
prow-presubmit-check: \
|
||||||
lint-kustomize \
|
lint-kustomize \
|
||||||
test-unit-kustomize-all \
|
test-unit-kustomize-all \
|
||||||
test-examples-kustomize-against-HEAD \
|
|
||||||
test-unit-cmd-all \
|
test-unit-cmd-all \
|
||||||
test-go-mod
|
test-go-mod \
|
||||||
|
test-examples-kustomize-against-HEAD \
|
||||||
|
test-examples-kustomize-against-3.8.0 \
|
||||||
|
test-examples-kustomize-against-3.8.2
|
||||||
|
|
||||||
.PHONY: verify-kustomize-e2e
|
.PHONY: verify-kustomize-e2e
|
||||||
verify-kustomize-e2e: test-examples-e2e-kustomize
|
verify-kustomize-e2e: test-examples-e2e-kustomize
|
||||||
@@ -47,17 +47,18 @@ $(MYGOBIN)/golangci-lint-kustomize:
|
|||||||
GO111MODULE=on go build -tags=tools -o $(MYGOBIN)/golangci-lint-kustomize github.com/golangci/golangci-lint/cmd/golangci-lint; \
|
GO111MODULE=on go build -tags=tools -o $(MYGOBIN)/golangci-lint-kustomize github.com/golangci/golangci-lint/cmd/golangci-lint; \
|
||||||
)
|
)
|
||||||
|
|
||||||
# Version pinned by api/go.mod
|
$(MYGOBIN)/gorepomod:
|
||||||
|
cd api; \
|
||||||
|
go install github.com/monopole/gorepomod
|
||||||
|
|
||||||
$(MYGOBIN)/mdrip:
|
$(MYGOBIN)/mdrip:
|
||||||
cd api; \
|
cd api; \
|
||||||
go install github.com/monopole/mdrip
|
go install github.com/monopole/mdrip
|
||||||
|
|
||||||
# Version pinned by api/go.mod
|
|
||||||
$(MYGOBIN)/stringer:
|
$(MYGOBIN)/stringer:
|
||||||
cd api; \
|
cd api; \
|
||||||
go install golang.org/x/tools/cmd/stringer
|
go install golang.org/x/tools/cmd/stringer
|
||||||
|
|
||||||
# Version pinned by api/go.mod
|
|
||||||
$(MYGOBIN)/goimports:
|
$(MYGOBIN)/goimports:
|
||||||
cd api; \
|
cd api; \
|
||||||
go install golang.org/x/tools/cmd/goimports
|
go install golang.org/x/tools/cmd/goimports
|
||||||
@@ -83,6 +84,8 @@ $(MYGOBIN)/kustomize:
|
|||||||
install-tools: \
|
install-tools: \
|
||||||
$(MYGOBIN)/goimports \
|
$(MYGOBIN)/goimports \
|
||||||
$(MYGOBIN)/golangci-lint-kustomize \
|
$(MYGOBIN)/golangci-lint-kustomize \
|
||||||
|
$(MYGOBIN)/gh \
|
||||||
|
$(MYGOBIN)/gorepomod \
|
||||||
$(MYGOBIN)/mdrip \
|
$(MYGOBIN)/mdrip \
|
||||||
$(MYGOBIN)/pluginator \
|
$(MYGOBIN)/pluginator \
|
||||||
$(MYGOBIN)/stringer
|
$(MYGOBIN)/stringer
|
||||||
@@ -198,7 +201,7 @@ build-kustomize-api: $(builtinplugins)
|
|||||||
|
|
||||||
.PHONY: test-unit-kustomize-api
|
.PHONY: test-unit-kustomize-api
|
||||||
test-unit-kustomize-api: build-kustomize-api
|
test-unit-kustomize-api: build-kustomize-api
|
||||||
cd api; go test ./...
|
cd api; go test ./... -ldflags "-X sigs.k8s.io/kustomize/api/provenance.version=v444.333.222"
|
||||||
|
|
||||||
.PHONY: test-unit-kustomize-plugins
|
.PHONY: test-unit-kustomize-plugins
|
||||||
test-unit-kustomize-plugins:
|
test-unit-kustomize-plugins:
|
||||||
@@ -235,10 +238,10 @@ test-examples-kustomize-against-HEAD: $(MYGOBIN)/kustomize $(MYGOBIN)/mdrip
|
|||||||
./hack/testExamplesAgainstKustomize.sh HEAD
|
./hack/testExamplesAgainstKustomize.sh HEAD
|
||||||
|
|
||||||
.PHONY:
|
.PHONY:
|
||||||
test-examples-kustomize-against-3.5.4: $(MYGOBIN)/mdrip
|
test-examples-kustomize-against-3.8.0: $(MYGOBIN)/mdrip
|
||||||
( \
|
( \
|
||||||
set -e; \
|
set -e; \
|
||||||
tag=v3.5.4; \
|
tag=v3.8.0; \
|
||||||
/bin/rm -f $(MYGOBIN)/kustomize; \
|
/bin/rm -f $(MYGOBIN)/kustomize; \
|
||||||
echo "Installing kustomize $$tag."; \
|
echo "Installing kustomize $$tag."; \
|
||||||
GO111MODULE=on go get sigs.k8s.io/kustomize/kustomize/v3@$${tag}; \
|
GO111MODULE=on go get sigs.k8s.io/kustomize/kustomize/v3@$${tag}; \
|
||||||
@@ -248,10 +251,10 @@ test-examples-kustomize-against-3.5.4: $(MYGOBIN)/mdrip
|
|||||||
)
|
)
|
||||||
|
|
||||||
.PHONY:
|
.PHONY:
|
||||||
test-examples-kustomize-against-3.5.5: $(MYGOBIN)/mdrip
|
test-examples-kustomize-against-3.8.2: $(MYGOBIN)/mdrip
|
||||||
( \
|
( \
|
||||||
set -e; \
|
set -e; \
|
||||||
tag=v3.5.5; \
|
tag=v3.8.2; \
|
||||||
/bin/rm -f $(MYGOBIN)/kustomize; \
|
/bin/rm -f $(MYGOBIN)/kustomize; \
|
||||||
echo "Installing kustomize $$tag."; \
|
echo "Installing kustomize $$tag."; \
|
||||||
GO111MODULE=on go get sigs.k8s.io/kustomize/kustomize/v3@$${tag}; \
|
GO111MODULE=on go get sigs.k8s.io/kustomize/kustomize/v3@$${tag}; \
|
||||||
@@ -260,7 +263,6 @@ test-examples-kustomize-against-3.5.5: $(MYGOBIN)/mdrip
|
|||||||
cd kustomize; go install .; \
|
cd kustomize; go install .; \
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# linux only.
|
# linux only.
|
||||||
# This is for testing an example plugin that
|
# This is for testing an example plugin that
|
||||||
# uses kubeval for validation.
|
# uses kubeval for validation.
|
||||||
@@ -320,6 +322,18 @@ $(MYGOBIN)/kind:
|
|||||||
rm -rf $$d; \
|
rm -rf $$d; \
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# linux only.
|
||||||
|
$(MYGOBIN)/gh:
|
||||||
|
( \
|
||||||
|
set -e; \
|
||||||
|
d=$(shell mktemp -d); cd $$d; \
|
||||||
|
tgzFile=gh_1.0.0_linux_amd64.tar.gz; \
|
||||||
|
wget https://github.com/cli/cli/releases/download/v1.0.0/$$tgzFile; \
|
||||||
|
tar -xvzf $$tgzFile; \
|
||||||
|
mv gh_1.0.0_linux_amd64/bin/gh $(MYGOBIN)/gh; \
|
||||||
|
rm -rf $$d \
|
||||||
|
)
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean: kustomize-external-go-plugin-clean
|
clean: kustomize-external-go-plugin-clean
|
||||||
go clean --cache
|
go clean --cache
|
||||||
|
|||||||
@@ -11,3 +11,4 @@ aliases:
|
|||||||
- pwittrock
|
- pwittrock
|
||||||
- mortent
|
- mortent
|
||||||
- phanimarupaka
|
- phanimarupaka
|
||||||
|
- Shell32-Natsu
|
||||||
|
|||||||
66
README.md
66
README.md
@@ -9,18 +9,15 @@ patch [kubernetes style] API objects. It's like
|
|||||||
[`make`], in that what it does is declared in a file,
|
[`make`], in that what it does is declared in a file,
|
||||||
and it's like [`sed`], in that it emits edited text.
|
and it's like [`sed`], in that it emits edited text.
|
||||||
|
|
||||||
This tool is sponsored by [sig-cli] ([KEP]), and
|
This tool is sponsored by [sig-cli] ([KEP]).
|
||||||
inspired by [DAM].
|
|
||||||
|
- [Installation instructions](https://kubernetes-sigs.github.io/kustomize/installation)
|
||||||
|
- [General documentation](https://kubernetes-sigs.github.io/kustomize)
|
||||||
|
- [Examples](examples)
|
||||||
|
|
||||||
[](https://prow.k8s.io/job-history/kubernetes-jenkins/pr-logs/directory/kustomize-presubmit-master)
|
[](https://prow.k8s.io/job-history/kubernetes-jenkins/pr-logs/directory/kustomize-presubmit-master)
|
||||||
[](https://goreportcard.com/report/github.com/kubernetes-sigs/kustomize)
|
[](https://goreportcard.com/report/github.com/kubernetes-sigs/kustomize)
|
||||||
|
|
||||||
Download a binary from the [release page], or see
|
|
||||||
these [instructions](docs/INSTALL.md).
|
|
||||||
|
|
||||||
Browse the [docs](docs) or jump right into the
|
|
||||||
tested [examples](examples).
|
|
||||||
|
|
||||||
## kubectl integration
|
## kubectl integration
|
||||||
|
|
||||||
Since [v1.14][kubectl announcement] the kustomize build system has been included in kubectl.
|
Since [v1.14][kubectl announcement] the kustomize build system has been included in kubectl.
|
||||||
@@ -132,20 +129,8 @@ The YAML can be directly [applied] to a cluster:
|
|||||||
|
|
||||||
## Community
|
## Community
|
||||||
|
|
||||||
To file bugs please read [this](docs/bugs.md).
|
- [file a bug](https://kubernetes-sigs.github.io/kustomize/contributing/bugs/) instructions
|
||||||
|
- [contribute a feature](https://kubernetes-sigs.github.io/kustomize/contributing/features/) instructions
|
||||||
Before working on an implementation, please
|
|
||||||
|
|
||||||
* Read the [eschewed feature list].
|
|
||||||
* File an issue describing
|
|
||||||
how the new feature would behave
|
|
||||||
and label it [kind/feature].
|
|
||||||
|
|
||||||
### Other communication channels
|
|
||||||
|
|
||||||
- [Slack]
|
|
||||||
- [Mailing List]
|
|
||||||
- General kubernetes [community page]
|
|
||||||
|
|
||||||
### Code of conduct
|
### Code of conduct
|
||||||
|
|
||||||
@@ -154,32 +139,27 @@ is governed by the [Kubernetes Code of Conduct].
|
|||||||
|
|
||||||
[`make`]: https://www.gnu.org/software/make
|
[`make`]: https://www.gnu.org/software/make
|
||||||
[`sed`]: https://www.gnu.org/software/sed
|
[`sed`]: https://www.gnu.org/software/sed
|
||||||
[DAM]: docs/glossary.md#declarative-application-management
|
[DAM]: https://kubernetes-sigs.github.io/kustomize/api-reference/glossary#declarative-application-management
|
||||||
[KEP]: https://github.com/kubernetes/enhancements/blob/master/keps/sig-cli/0008-kustomize.md
|
[KEP]: https://github.com/kubernetes/enhancements/blob/master/keps/sig-cli/0008-kustomize.md
|
||||||
[Kubernetes Code of Conduct]: code-of-conduct.md
|
[Kubernetes Code of Conduct]: code-of-conduct.md
|
||||||
[Mailing List]: https://groups.google.com/forum/#!forum/kubernetes-sig-cli
|
[applied]: https://kubernetes-sigs.github.io/kustomize/api-reference/glossary#apply
|
||||||
[Slack]: https://kubernetes.slack.com/messages/sig-cli
|
[base]: https://kubernetes-sigs.github.io/kustomize/api-reference/glossary#base
|
||||||
[applied]: docs/glossary.md#apply
|
[declarative configuration]: https://kubernetes-sigs.github.io/kustomize/api-reference/glossary#declarative-application-management
|
||||||
[base]: docs/glossary.md#base
|
|
||||||
[community page]: http://kubernetes.io/community/
|
|
||||||
[declarative configuration]: docs/glossary.md#declarative-application-management
|
|
||||||
[eschewed feature list]: docs/eschewedFeatures.md
|
|
||||||
[imageBase]: docs/images/base.jpg
|
[imageBase]: docs/images/base.jpg
|
||||||
[imageOverlay]: docs/images/overlay.jpg
|
[imageOverlay]: docs/images/overlay.jpg
|
||||||
[kind/feature]: /../../labels/kind%2Ffeature
|
|
||||||
[kubectl announcement]: https://kubernetes.io/blog/2019/03/25/kubernetes-1-14-release-announcement
|
[kubectl announcement]: https://kubernetes.io/blog/2019/03/25/kubernetes-1-14-release-announcement
|
||||||
[kubectl book]: https://kubectl.docs.kubernetes.io/pages/app_customization/introduction.html
|
[kubectl book]: https://kubectl.docs.kubernetes.io/pages/app_customization/introduction.html
|
||||||
[kubernetes documentation]: https://kubernetes.io/docs/tasks/manage-kubernetes-objects/kustomization/
|
[kubernetes documentation]: https://kubernetes.io/docs/tasks/manage-kubernetes-objects/kustomization/
|
||||||
[kubernetes style]: docs/glossary.md#kubernetes-style-object
|
[kubernetes style]: https://kubernetes-sigs.github.io/kustomize/api-reference/glossary#kubernetes-style-object
|
||||||
[kustomization]: docs/glossary.md#kustomization
|
[kustomization]: https://kubernetes-sigs.github.io/kustomize/api-reference/glossary#kustomization
|
||||||
[overlay]: docs/glossary.md#overlay
|
[overlay]: https://kubernetes-sigs.github.io/kustomize/api-reference/glossary#overlay
|
||||||
[overlays]: docs/glossary.md#overlay
|
[overlays]: https://kubernetes-sigs.github.io/kustomize/api-reference/glossary#overlay
|
||||||
[release page]: /../../releases
|
[release page]: https://github.com/kubernetes-sigs/kustomize/releases
|
||||||
[resource]: docs/glossary.md#resource
|
[resource]: https://kubernetes-sigs.github.io/kustomize/api-reference/glossary#resource
|
||||||
[resources]: docs/glossary.md#resource
|
[resources]: https://kubernetes-sigs.github.io/kustomize/api-reference/glossary#resource
|
||||||
[sig-cli]: https://github.com/kubernetes/community/blob/master/sig-cli/README.md
|
[sig-cli]: https://github.com/kubernetes/community/blob/master/sig-cli/README.md
|
||||||
[variant]: docs/glossary.md#variant
|
[variant]: https://kubernetes-sigs.github.io/kustomize/api-reference/glossary#variant
|
||||||
[variants]: docs/glossary.md#variant
|
[variants]: https://kubernetes-sigs.github.io/kustomize/api-reference/glossary#variant
|
||||||
[v2.0.3]: /../../releases/tag/v2.0.3
|
[v2.0.3]: https://github.com/kubernetes-sigs/kustomize/releases/tag/v2.0.3
|
||||||
[v2.1.0]: /../../releases/tag/v2.1.0
|
[v2.1.0]: https://github.com/kubernetes-sigs/kustomize/releases/tag/v2.1.0
|
||||||
[workflows]: docs/workflows.md
|
[workflows]: https://kubernetes-sigs.github.io/kustomize/guides
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ func (p *AnnotationsTransformerPlugin) Transform(m resmap.ResMap) error {
|
|||||||
err := filtersutil.ApplyToJSON(annotations.Filter{
|
err := filtersutil.ApplyToJSON(annotations.Filter{
|
||||||
Annotations: p.Annotations,
|
Annotations: p.Annotations,
|
||||||
FsSlice: p.FieldSpecs,
|
FsSlice: p.FieldSpecs,
|
||||||
}, r.Kunstructured)
|
}, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/transform"
|
"sigs.k8s.io/kustomize/api/filters/imagetag"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/filtersutil"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -31,18 +31,19 @@ func (p *ImageTagTransformerPlugin) Config(
|
|||||||
|
|
||||||
func (p *ImageTagTransformerPlugin) Transform(m resmap.ResMap) error {
|
func (p *ImageTagTransformerPlugin) Transform(m resmap.ResMap) error {
|
||||||
for _, r := range m.Resources() {
|
for _, r := range m.Resources() {
|
||||||
for _, path := range p.FieldSpecs {
|
// traverse all fields at first
|
||||||
if !r.OrgId().IsSelected(&path.Gvk) {
|
err := filtersutil.ApplyToJSON(imagetag.LegacyFilter{
|
||||||
continue
|
ImageTag: p.ImageTag,
|
||||||
}
|
}, r)
|
||||||
err := transform.MutateField(
|
if err != nil {
|
||||||
r.Map(), path.PathSlice(), false, p.mutateImage)
|
return err
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Kept for backward compatibility
|
// then use user specified field specs
|
||||||
if err := p.findAndReplaceImage(r.Map()); err != nil && r.OrgId().Kind != `CustomResourceDefinition` {
|
err = filtersutil.ApplyToJSON(imagetag.Filter{
|
||||||
|
ImageTag: p.ImageTag,
|
||||||
|
FsSlice: p.FieldSpecs,
|
||||||
|
}, r)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ func (p *LabelTransformerPlugin) Transform(m resmap.ResMap) error {
|
|||||||
err := filtersutil.ApplyToJSON(labels.Filter{
|
err := filtersutil.ApplyToJSON(labels.Filter{
|
||||||
Labels: p.Labels,
|
Labels: p.Labels,
|
||||||
FsSlice: p.FieldSpecs,
|
FsSlice: p.FieldSpecs,
|
||||||
}, r.Kunstructured)
|
}, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/api/resid"
|
"sigs.k8s.io/kustomize/api/resid"
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
"sigs.k8s.io/kustomize/api/resource"
|
"sigs.k8s.io/kustomize/api/resource"
|
||||||
"sigs.k8s.io/kustomize/api/transform"
|
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
"sigs.k8s.io/kustomize/kyaml/filtersutil"
|
"sigs.k8s.io/kustomize/kyaml/filtersutil"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
@@ -20,11 +19,6 @@ import (
|
|||||||
type NamespaceTransformerPlugin struct {
|
type NamespaceTransformerPlugin struct {
|
||||||
types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
|
types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
|
||||||
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
||||||
|
|
||||||
// YAMLSupport can be set to true to use the kyaml filter instead of the
|
|
||||||
// kunstruct transformer.
|
|
||||||
// TODO: change the default to use kyaml when it is stable
|
|
||||||
YAMLSupport bool `json:"yamlSupport,omitempty" yaml:"yamlSupport,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *NamespaceTransformerPlugin) Config(
|
func (p *NamespaceTransformerPlugin) Config(
|
||||||
@@ -39,35 +33,17 @@ func (p *NamespaceTransformerPlugin) Transform(m resmap.ResMap) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, r := range m.Resources() {
|
for _, r := range m.Resources() {
|
||||||
if len(r.Map()) == 0 {
|
if r.IsEmpty() {
|
||||||
// Don't mutate empty objects?
|
// Don't mutate empty objects?
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
err := filtersutil.ApplyToJSON(namespace.Filter{
|
||||||
id := r.OrgId()
|
Namespace: p.Namespace,
|
||||||
|
FsSlice: p.FieldSpecs,
|
||||||
if p.YAMLSupport {
|
}, r)
|
||||||
// use the new style transform
|
if err != nil {
|
||||||
err := filtersutil.ApplyToJSON(namespace.Filter{
|
return err
|
||||||
Namespace: p.Namespace,
|
|
||||||
FsSlice: p.FieldSpecs,
|
|
||||||
}, r.Kunstructured)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// use the old style transform
|
|
||||||
applicableFs := p.applicableFieldSpecs(id)
|
|
||||||
for _, fs := range applicableFs {
|
|
||||||
err := transform.MutateField(
|
|
||||||
r.Map(), fs.PathSlice(), fs.CreateIfNotPresent,
|
|
||||||
p.changeNamespace(r))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
matches := m.GetMatchingResourcesByCurrentId(r.CurId().Equals)
|
matches := m.GetMatchingResourcesByCurrentId(r.CurId().Equals)
|
||||||
if len(matches) != 1 {
|
if len(matches) != 1 {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ type PatchJson6902TransformerPlugin struct {
|
|||||||
Target types.PatchTarget `json:"target,omitempty" yaml:"target,omitempty"`
|
Target types.PatchTarget `json:"target,omitempty" yaml:"target,omitempty"`
|
||||||
Path string `json:"path,omitempty" yaml:"path,omitempty"`
|
Path string `json:"path,omitempty" yaml:"path,omitempty"`
|
||||||
JsonOp string `json:"jsonOp,omitempty" yaml:"jsonOp,omitempty"`
|
JsonOp string `json:"jsonOp,omitempty" yaml:"jsonOp,omitempty"`
|
||||||
|
|
||||||
YAMLSupport bool `json:"yamlSupport,omitempty" yaml:"yamlSupport,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PatchJson6902TransformerPlugin) Config(
|
func (p *PatchJson6902TransformerPlugin) Config(
|
||||||
@@ -87,22 +85,9 @@ func (p *PatchJson6902TransformerPlugin) Transform(m resmap.ResMap) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !p.YAMLSupport {
|
return filtersutil.ApplyToJSON(patchjson6902.Filter{
|
||||||
rawObj, err := obj.MarshalJSON()
|
Patch: p.JsonOp,
|
||||||
if err != nil {
|
}, obj)
|
||||||
return err
|
|
||||||
}
|
|
||||||
modifiedObj, err := p.decodedPatch.Apply(rawObj)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrapf(
|
|
||||||
err, "failed to apply json patch '%s'", p.JsonOp)
|
|
||||||
}
|
|
||||||
return obj.UnmarshalJSON(modifiedObj)
|
|
||||||
} else {
|
|
||||||
return filtersutil.ApplyToJSON(patchjson6902.Filter{
|
|
||||||
Patch: p.JsonOp,
|
|
||||||
}, obj.Kunstructured)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPatchJson6902TransformerPlugin() resmap.TransformerPlugin {
|
func NewPatchJson6902TransformerPlugin() resmap.TransformerPlugin {
|
||||||
|
|||||||
@@ -4,11 +4,10 @@
|
|||||||
package builtins
|
package builtins
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
kyaml "sigs.k8s.io/kustomize/kyaml/yaml"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/filters/patchstrategicmerge"
|
"sigs.k8s.io/kustomize/api/filters/patchstrategicmerge"
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
"sigs.k8s.io/kustomize/api/resource"
|
"sigs.k8s.io/kustomize/api/resource"
|
||||||
@@ -22,8 +21,6 @@ type PatchStrategicMergeTransformerPlugin struct {
|
|||||||
loadedPatches []*resource.Resource
|
loadedPatches []*resource.Resource
|
||||||
Paths []types.PatchStrategicMerge `json:"paths,omitempty" yaml:"paths,omitempty"`
|
Paths []types.PatchStrategicMerge `json:"paths,omitempty" yaml:"paths,omitempty"`
|
||||||
Patches string `json:"patches,omitempty" yaml:"patches,omitempty"`
|
Patches string `json:"patches,omitempty" yaml:"patches,omitempty"`
|
||||||
|
|
||||||
YAMLSupport bool `json:"yamlSupport,omitempty" yaml:"yamlSupport,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PatchStrategicMergeTransformerPlugin) Config(
|
func (p *PatchStrategicMergeTransformerPlugin) Config(
|
||||||
@@ -67,7 +64,7 @@ func (p *PatchStrategicMergeTransformerPlugin) Config(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *PatchStrategicMergeTransformerPlugin) Transform(m resmap.ResMap) error {
|
func (p *PatchStrategicMergeTransformerPlugin) Transform(m resmap.ResMap) error {
|
||||||
patches, err := p.h.ResmapFactory().MergePatches(p.loadedPatches)
|
patches, err := p.h.ResmapFactory().Merge(p.loadedPatches)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -76,42 +73,48 @@ func (p *PatchStrategicMergeTransformerPlugin) Transform(m resmap.ResMap) error
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !p.YAMLSupport {
|
patchCopy := patch.DeepCopy()
|
||||||
err = target.Patch(patch.Kunstructured)
|
patchCopy.SetName(target.GetName())
|
||||||
|
patchCopy.SetNamespace(target.GetNamespace())
|
||||||
|
patchCopy.SetGvk(target.GetGvk())
|
||||||
|
node, err := filtersutil.GetRNode(patchCopy)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = filtersutil.ApplyToJSON(patchstrategicmerge.Filter{
|
||||||
|
Patch: node,
|
||||||
|
}, target)
|
||||||
|
if err != nil {
|
||||||
|
// Check for an error string from UnmarshalJSON that's indicative
|
||||||
|
// of an object that's missing basic KRM fields, and thus may have been
|
||||||
|
// entirely deleted (an acceptable outcome). This error handling should
|
||||||
|
// be deleted along with use of ResMap and apimachinery functions like
|
||||||
|
// UnmarshalJSON.
|
||||||
|
if !strings.Contains(err.Error(), "Object 'Kind' is missing") {
|
||||||
|
// Some unknown error, let it through.
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !target.IsEmpty() {
|
||||||
|
return errors.Wrapf(
|
||||||
|
err, "with unexpectedly non-empty object map of size %d",
|
||||||
|
len(target.Map()))
|
||||||
|
}
|
||||||
|
// Fall through to handle deleted object.
|
||||||
|
}
|
||||||
|
if target.IsEmpty() {
|
||||||
|
// This means all fields have been removed from the object.
|
||||||
|
// This can happen if a patch required deletion of the
|
||||||
|
// entire resource (not just a part of it). This means
|
||||||
|
// the overall resmap must shrink by one.
|
||||||
|
err = m.Remove(target.CurId())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// remove the resource from resmap
|
|
||||||
// when the patch is to $patch: delete that target
|
|
||||||
if len(target.Map()) == 0 {
|
|
||||||
err = m.Remove(target.CurId())
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
node, err := getRNode(patch)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = filtersutil.ApplyToJSON(patchstrategicmerge.Filter{
|
|
||||||
Patch: node,
|
|
||||||
}, target.Kunstructured)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Remove this once the next version of kyaml is released which
|
|
||||||
// exposes GetRNode from the filutersutil package.
|
|
||||||
func getRNode(k json.Marshaler) (*kyaml.RNode, error) {
|
|
||||||
j, err := k.MarshalJSON()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return kyaml.Parse(string(j))
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewPatchStrategicMergeTransformerPlugin() resmap.TransformerPlugin {
|
func NewPatchStrategicMergeTransformerPlugin() resmap.TransformerPlugin {
|
||||||
return &PatchStrategicMergeTransformerPlugin{}
|
return &PatchStrategicMergeTransformerPlugin{}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,8 +24,6 @@ type PatchTransformerPlugin struct {
|
|||||||
Path string `json:"path,omitempty" yaml:"path,omitempty"`
|
Path string `json:"path,omitempty" yaml:"path,omitempty"`
|
||||||
Patch string `json:"patch,omitempty" yaml:"patch,omitempty"`
|
Patch string `json:"patch,omitempty" yaml:"patch,omitempty"`
|
||||||
Target *types.Selector `json:"target,omitempty" yaml:"target,omitempty"`
|
Target *types.Selector `json:"target,omitempty" yaml:"target,omitempty"`
|
||||||
|
|
||||||
YAMLSupport bool `json:"yamlSupport,omitempty" yaml:"yamlSupport,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PatchTransformerPlugin) Config(
|
func (p *PatchTransformerPlugin) Config(
|
||||||
@@ -73,11 +71,11 @@ func (p *PatchTransformerPlugin) Config(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *PatchTransformerPlugin) Transform(m resmap.ResMap) error {
|
func (p *PatchTransformerPlugin) Transform(m resmap.ResMap) error {
|
||||||
if p.loadedPatch != nil {
|
if p.loadedPatch == nil {
|
||||||
|
return p.transformJson6902(m, p.decodedPatch)
|
||||||
|
} else {
|
||||||
// The patch was a strategic merge patch
|
// The patch was a strategic merge patch
|
||||||
return p.transformStrategicMerge(m, p.loadedPatch)
|
return p.transformStrategicMerge(m, p.loadedPatch)
|
||||||
} else {
|
|
||||||
return p.transformJson6902(m, p.decodedPatch)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,27 +102,52 @@ func (p *PatchTransformerPlugin) transformStrategicMerge(m resmap.ResMap, patch
|
|||||||
patchCopy.SetGvk(res.GetGvk())
|
patchCopy.SetGvk(res.GetGvk())
|
||||||
err := p.applySMPatch(res, patchCopy)
|
err := p.applySMPatch(res, patchCopy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
// Check for an error string from UnmarshalJSON that's indicative
|
||||||
|
// of an object that's missing basic KRM fields, and thus may have been
|
||||||
|
// entirely deleted (an acceptable outcome). This error handling should
|
||||||
|
// be deleted along with use of ResMap and apimachinery functions like
|
||||||
|
// UnmarshalJSON.
|
||||||
|
if !strings.Contains(err.Error(), "Object 'Kind' is missing") {
|
||||||
|
// Some unknown error, let it through.
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !res.IsEmpty() {
|
||||||
|
return errors.Wrapf(
|
||||||
|
err, "with unexpectedly non-empty object map of size %d",
|
||||||
|
len(res.Map()))
|
||||||
|
}
|
||||||
|
// Fall through to handle deleted object.
|
||||||
|
}
|
||||||
|
if res.IsEmpty() {
|
||||||
|
// This means all fields have been removed from the object.
|
||||||
|
// This can happen if a patch required deletion of the
|
||||||
|
// entire resource (not just a part of it). This means
|
||||||
|
// the overall resmap must shrink by one.
|
||||||
|
err = m.Remove(res.CurId())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// applySMPatch applies the provided strategic merge patch to the
|
// applySMPatch applies the provided strategic merge patch to the
|
||||||
// given resource. Depending on the value of YAMLSupport, it will either
|
// given resource.
|
||||||
// use the legacy implementation or the kyaml-based solution.
|
|
||||||
func (p *PatchTransformerPlugin) applySMPatch(resource, patch *resource.Resource) error {
|
func (p *PatchTransformerPlugin) applySMPatch(resource, patch *resource.Resource) error {
|
||||||
if !p.YAMLSupport {
|
node, err := filtersutil.GetRNode(patch)
|
||||||
return resource.Patch(patch.Kunstructured)
|
if err != nil {
|
||||||
} else {
|
return err
|
||||||
node, err := filtersutil.GetRNode(patch)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return filtersutil.ApplyToJSON(patchstrategicmerge.Filter{
|
|
||||||
Patch: node,
|
|
||||||
}, resource.Kunstructured)
|
|
||||||
}
|
}
|
||||||
|
n, ns := resource.GetName(), resource.GetNamespace()
|
||||||
|
err = filtersutil.ApplyToJSON(patchstrategicmerge.Filter{
|
||||||
|
Patch: node,
|
||||||
|
}, resource)
|
||||||
|
if !resource.IsEmpty() {
|
||||||
|
resource.SetName(n)
|
||||||
|
resource.SetNamespace(ns)
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// transformJson6902 applies the provided json6902 patch
|
// transformJson6902 applies the provided json6902 patch
|
||||||
@@ -133,13 +156,14 @@ func (p *PatchTransformerPlugin) transformJson6902(m resmap.ResMap, patch jsonpa
|
|||||||
if p.Target == nil {
|
if p.Target == nil {
|
||||||
return fmt.Errorf("must specify a target for patch %s", p.Patch)
|
return fmt.Errorf("must specify a target for patch %s", p.Patch)
|
||||||
}
|
}
|
||||||
|
|
||||||
resources, err := m.Select(*p.Target)
|
resources, err := m.Select(*p.Target)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, res := range resources {
|
for _, res := range resources {
|
||||||
err = p.applyJson6902Patch(res, patch)
|
err = filtersutil.ApplyToJSON(patchjson6902.Filter{
|
||||||
|
Patch: p.Patch,
|
||||||
|
}, res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -147,28 +171,6 @@ func (p *PatchTransformerPlugin) transformJson6902(m resmap.ResMap, patch jsonpa
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// applyJson6902Patch applies the provided patch to the given resource.
|
|
||||||
// Depending on the value of YAMLSupport, it will either
|
|
||||||
// use the legacy implementation or the kyaml-based solution.
|
|
||||||
func (p *PatchTransformerPlugin) applyJson6902Patch(resource *resource.Resource, patch jsonpatch.Patch) error {
|
|
||||||
if !p.YAMLSupport {
|
|
||||||
rawObj, err := resource.MarshalJSON()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
modifiedObj, err := patch.Apply(rawObj)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrapf(
|
|
||||||
err, "failed to apply json patch '%s'", p.Patch)
|
|
||||||
}
|
|
||||||
return resource.UnmarshalJSON(modifiedObj)
|
|
||||||
} else {
|
|
||||||
return filtersutil.ApplyToJSON(patchjson6902.Filter{
|
|
||||||
Patch: p.Patch,
|
|
||||||
}, resource.Kunstructured)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// jsonPatchFromBytes loads a Json 6902 patch from
|
// jsonPatchFromBytes loads a Json 6902 patch from
|
||||||
// a bytes input
|
// a bytes input
|
||||||
func jsonPatchFromBytes(
|
func jsonPatchFromBytes(
|
||||||
|
|||||||
@@ -5,31 +5,28 @@ package builtins
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/transform"
|
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
|
||||||
|
|
||||||
|
"sigs.k8s.io/kustomize/api/filters/prefixsuffix"
|
||||||
"sigs.k8s.io/kustomize/api/resid"
|
"sigs.k8s.io/kustomize/api/resid"
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/filtersutil"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Add the given prefix and suffix to the field.
|
// Add the given prefix and suffix to the field.
|
||||||
type PrefixSuffixTransformerPlugin struct {
|
type PrefixSuffixTransformerPlugin struct {
|
||||||
Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
|
Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
|
||||||
Suffix string `json:"suffix,omitempty" yaml:"suffix,omitempty"`
|
Suffix string `json:"suffix,omitempty" yaml:"suffix,omitempty"`
|
||||||
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
FieldSpecs types.FsSlice `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not placed in a file yet due to lack of demand.
|
// A Gvk skip list for prefix/suffix modification.
|
||||||
var prefixSuffixFieldSpecsToSkip = []types.FieldSpec{
|
// hard coded for now - eventually should be part of config.
|
||||||
{
|
var prefixSuffixFieldSpecsToSkip = types.FsSlice{
|
||||||
Gvk: resid.Gvk{Kind: "CustomResourceDefinition"},
|
{Gvk: resid.Gvk{Kind: "CustomResourceDefinition"}},
|
||||||
},
|
{Gvk: resid.Gvk{Group: "apiregistration.k8s.io", Kind: "APIService"}},
|
||||||
{
|
{Gvk: resid.Gvk{Kind: "Namespace"}},
|
||||||
Gvk: resid.Gvk{Group: "apiregistration.k8s.io", Kind: "APIService"},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PrefixSuffixTransformerPlugin) Config(
|
func (p *PrefixSuffixTransformerPlugin) Config(
|
||||||
@@ -48,29 +45,24 @@ func (p *PrefixSuffixTransformerPlugin) Config(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *PrefixSuffixTransformerPlugin) Transform(m resmap.ResMap) error {
|
func (p *PrefixSuffixTransformerPlugin) Transform(m resmap.ResMap) error {
|
||||||
|
|
||||||
// Even if both the Prefix and Suffix are empty we want
|
// Even if both the Prefix and Suffix are empty we want
|
||||||
// to proceed with the transformation. This allows to add contextual
|
// to proceed with the transformation. This allows to add contextual
|
||||||
// information to the resources (AddNamePrefix and AddNameSuffix).
|
// information to the resources (AddNamePrefix and AddNameSuffix).
|
||||||
|
|
||||||
for _, r := range m.Resources() {
|
for _, r := range m.Resources() {
|
||||||
|
// TODO: move this test into the filter (i.e. make a better filter)
|
||||||
if p.shouldSkip(r.OrgId()) {
|
if p.shouldSkip(r.OrgId()) {
|
||||||
// Don't change the actual definition
|
|
||||||
// of a CRD.
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
id := r.OrgId()
|
id := r.OrgId()
|
||||||
// current default configuration contains
|
// current default configuration contains
|
||||||
// only one entry: "metadata/name" with no GVK
|
// only one entry: "metadata/name" with no GVK
|
||||||
for _, path := range p.FieldSpecs {
|
for _, fs := range p.FieldSpecs {
|
||||||
if !id.IsSelected(&path.Gvk) {
|
// TODO: this is redundant to filter (but needed for now)
|
||||||
// With the currrent default configuration,
|
if !id.IsSelected(&fs.Gvk) {
|
||||||
// because no Gvk is specified, so a wild
|
|
||||||
// card
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
// TODO: move this test into the filter.
|
||||||
if smellsLikeANameChange(&path) {
|
if smellsLikeANameChange(&fs) {
|
||||||
// "metadata/name" is the only field.
|
// "metadata/name" is the only field.
|
||||||
// this will add a prefix and a suffix
|
// this will add a prefix and a suffix
|
||||||
// to the resource even if those are
|
// to the resource even if those are
|
||||||
@@ -78,15 +70,11 @@ func (p *PrefixSuffixTransformerPlugin) Transform(m resmap.ResMap) error {
|
|||||||
r.AddNamePrefix(p.Prefix)
|
r.AddNamePrefix(p.Prefix)
|
||||||
r.AddNameSuffix(p.Suffix)
|
r.AddNameSuffix(p.Suffix)
|
||||||
}
|
}
|
||||||
|
err := filtersutil.ApplyToJSON(prefixsuffix.Filter{
|
||||||
// the addPrefixSuffix method will not
|
Prefix: p.Prefix,
|
||||||
// change the name if both the prefix and suffix
|
Suffix: p.Suffix,
|
||||||
// are empty.
|
FieldSpec: fs,
|
||||||
err := transform.MutateField(
|
}, r)
|
||||||
r.Map(),
|
|
||||||
path.PathSlice(),
|
|
||||||
path.CreateIfNotPresent,
|
|
||||||
p.addPrefixSuffix)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -99,8 +87,7 @@ func smellsLikeANameChange(fs *types.FieldSpec) bool {
|
|||||||
return fs.Path == "metadata/name"
|
return fs.Path == "metadata/name"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PrefixSuffixTransformerPlugin) shouldSkip(
|
func (p *PrefixSuffixTransformerPlugin) shouldSkip(id resid.ResId) bool {
|
||||||
id resid.ResId) bool {
|
|
||||||
for _, path := range prefixSuffixFieldSpecsToSkip {
|
for _, path := range prefixSuffixFieldSpecsToSkip {
|
||||||
if id.IsSelected(&path.Gvk) {
|
if id.IsSelected(&path.Gvk) {
|
||||||
return true
|
return true
|
||||||
@@ -109,15 +96,6 @@ func (p *PrefixSuffixTransformerPlugin) shouldSkip(
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PrefixSuffixTransformerPlugin) addPrefixSuffix(
|
|
||||||
in interface{}) (interface{}, error) {
|
|
||||||
s, ok := in.(string)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("%#v is expected to be %T", in, s)
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("%s%s%s", p.Prefix, s, p.Suffix), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewPrefixSuffixTransformerPlugin() resmap.TransformerPlugin {
|
func NewPrefixSuffixTransformerPlugin() resmap.TransformerPlugin {
|
||||||
return &PrefixSuffixTransformerPlugin{}
|
return &PrefixSuffixTransformerPlugin{}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ package builtins
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/transform"
|
"sigs.k8s.io/kustomize/api/filters/replicacount"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/filtersutil"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/resid"
|
"sigs.k8s.io/kustomize/api/resid"
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
@@ -30,18 +31,24 @@ func (p *ReplicaCountTransformerPlugin) Config(
|
|||||||
|
|
||||||
func (p *ReplicaCountTransformerPlugin) Transform(m resmap.ResMap) error {
|
func (p *ReplicaCountTransformerPlugin) Transform(m resmap.ResMap) error {
|
||||||
found := false
|
found := false
|
||||||
for i, replicaSpec := range p.FieldSpecs {
|
for _, fs := range p.FieldSpecs {
|
||||||
matcher := p.createMatcher(i)
|
matcher := p.createMatcher(fs)
|
||||||
matchOriginal := m.GetMatchingResourcesByOriginalId(matcher)
|
matchOriginal := m.GetMatchingResourcesByOriginalId(matcher)
|
||||||
matchCurrent := m.GetMatchingResourcesByCurrentId(matcher)
|
resList := append(
|
||||||
|
matchOriginal, m.GetMatchingResourcesByCurrentId(matcher)...)
|
||||||
for _, res := range append(matchOriginal, matchCurrent...) {
|
if len(resList) > 0 {
|
||||||
found = true
|
found = true
|
||||||
err := transform.MutateField(
|
for _, r := range resList {
|
||||||
res.Map(), replicaSpec.PathSlice(),
|
// There are redundant checks in the filter
|
||||||
replicaSpec.CreateIfNotPresent, p.addReplicas)
|
// that we'll live with until resolution of
|
||||||
if err != nil {
|
// https://github.com/kubernetes-sigs/kustomize/issues/2506
|
||||||
return err
|
err := filtersutil.ApplyToJSON(replicacount.Filter{
|
||||||
|
Replica: p.Replica,
|
||||||
|
FieldSpec: fs,
|
||||||
|
}, r)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,30 +66,12 @@ func (p *ReplicaCountTransformerPlugin) Transform(m resmap.ResMap) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Match Replica.Name and FieldSpec
|
// Match Replica.Name and FieldSpec
|
||||||
func (p *ReplicaCountTransformerPlugin) createMatcher(i int) resmap.IdMatcher {
|
func (p *ReplicaCountTransformerPlugin) createMatcher(fs types.FieldSpec) resmap.IdMatcher {
|
||||||
return func(r resid.ResId) bool {
|
return func(r resid.ResId) bool {
|
||||||
return r.Name == p.Replica.Name &&
|
return r.Name == p.Replica.Name && r.Gvk.IsSelected(&fs.Gvk)
|
||||||
r.Gvk.IsSelected(&p.FieldSpecs[i].Gvk)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ReplicaCountTransformerPlugin) addReplicas(in interface{}) (interface{}, error) {
|
|
||||||
switch m := in.(type) {
|
|
||||||
case int64:
|
|
||||||
// Was already in the field.
|
|
||||||
case map[string]interface{}:
|
|
||||||
if len(m) != 0 {
|
|
||||||
// A map was already in the replicas field, don't want to
|
|
||||||
// discard this data silently.
|
|
||||||
return nil, fmt.Errorf("%#v is expected to be %T", in, m)
|
|
||||||
}
|
|
||||||
// Just got added, default type is map, but we can return anything.
|
|
||||||
default:
|
|
||||||
return nil, fmt.Errorf("%#v is expected to be %T", in, m)
|
|
||||||
}
|
|
||||||
return p.Replica.Count, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewReplicaCountTransformerPlugin() resmap.TransformerPlugin {
|
func NewReplicaCountTransformerPlugin() resmap.TransformerPlugin {
|
||||||
return &ReplicaCountTransformerPlugin{}
|
return &ReplicaCountTransformerPlugin{}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,13 +121,13 @@ func (p *ValueAddTransformerPlugin) Transform(m resmap.ResMap) (err error) {
|
|||||||
if t.FieldPath == types.MetadataNamespacePath {
|
if t.FieldPath == types.MetadataNamespacePath {
|
||||||
err = filtersutil.ApplyToJSON(namespace.Filter{
|
err = filtersutil.ApplyToJSON(namespace.Filter{
|
||||||
Namespace: p.Value,
|
Namespace: p.Value,
|
||||||
}, res.Kunstructured)
|
}, res)
|
||||||
} else {
|
} else {
|
||||||
err = filtersutil.ApplyToJSON(valueadd.Filter{
|
err = filtersutil.ApplyToJSON(valueadd.Filter{
|
||||||
Value: p.Value,
|
Value: p.Value,
|
||||||
FieldPath: t.FieldPath,
|
FieldPath: t.FieldPath,
|
||||||
FilePathPosition: t.FilePathPosition,
|
FilePathPosition: t.FilePathPosition,
|
||||||
}, res.Kunstructured)
|
}, res)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -29,10 +29,11 @@ func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
|
|||||||
func(node *yaml.RNode) (*yaml.RNode, error) {
|
func(node *yaml.RNode) (*yaml.RNode, error) {
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
if err := node.PipeE(fsslice.Filter{
|
if err := node.PipeE(fsslice.Filter{
|
||||||
FsSlice: f.FsSlice,
|
FsSlice: f.FsSlice,
|
||||||
SetValue: fsslice.SetEntry(k, f.Annotations[k], yaml.StringTag),
|
SetValue: filtersutil.SetEntry(
|
||||||
|
k, f.Annotations[k], yaml.NodeTagString),
|
||||||
CreateKind: yaml.MappingNode, // Annotations are MappingNodes.
|
CreateKind: yaml.MappingNode, // Annotations are MappingNodes.
|
||||||
CreateTag: "!!map",
|
CreateTag: yaml.NodeTagMap,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
6
api/filters/fieldspec/doc.go
Normal file
6
api/filters/fieldspec/doc.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
// Copyright 2020 The Kubernetes Authors.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
// Package fieldspec contains a yaml.Filter to modify a resource
|
||||||
|
// that matches the FieldSpec.
|
||||||
|
package fieldspec
|
||||||
61
api/filters/fieldspec/example_test.go
Normal file
61
api/filters/fieldspec/example_test.go
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
// Copyright 2020 The Kubernetes Authors.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package fieldspec_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
. "sigs.k8s.io/kustomize/api/filters/fieldspec"
|
||||||
|
"sigs.k8s.io/kustomize/api/filters/filtersutil"
|
||||||
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ExampleFilter() {
|
||||||
|
in := &kio.ByteReader{
|
||||||
|
Reader: bytes.NewBufferString(`
|
||||||
|
apiVersion: example.com/v1
|
||||||
|
kind: Foo
|
||||||
|
metadata:
|
||||||
|
name: instance
|
||||||
|
---
|
||||||
|
apiVersion: example.com/v1
|
||||||
|
kind: Bar
|
||||||
|
metadata:
|
||||||
|
name: instance
|
||||||
|
`),
|
||||||
|
}
|
||||||
|
fltr := Filter{
|
||||||
|
CreateKind: yaml.ScalarNode,
|
||||||
|
SetValue: filtersutil.SetScalar("green"),
|
||||||
|
FieldSpec: types.FieldSpec{Path: "a/b", CreateIfNotPresent: true},
|
||||||
|
}
|
||||||
|
|
||||||
|
err := kio.Pipeline{
|
||||||
|
Inputs: []kio.Reader{in},
|
||||||
|
Filters: []kio.Filter{kio.FilterAll(fltr)},
|
||||||
|
Outputs: []kio.Writer{kio.ByteWriter{Writer: os.Stdout}},
|
||||||
|
}.Execute()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// apiVersion: example.com/v1
|
||||||
|
// kind: Foo
|
||||||
|
// metadata:
|
||||||
|
// name: instance
|
||||||
|
// a:
|
||||||
|
// b: green
|
||||||
|
// ---
|
||||||
|
// apiVersion: example.com/v1
|
||||||
|
// kind: Bar
|
||||||
|
// metadata:
|
||||||
|
// name: instance
|
||||||
|
// a:
|
||||||
|
// b: green
|
||||||
|
}
|
||||||
@@ -1,24 +1,27 @@
|
|||||||
// Copyright 2019 The Kubernetes Authors.
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
package fsslice
|
package fieldspec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"sigs.k8s.io/kustomize/api/filters/filtersutil"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
"sigs.k8s.io/kustomize/kyaml/errors"
|
"sigs.k8s.io/kustomize/kyaml/errors"
|
||||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// fieldSpecFilter applies a single fieldSpec to a single object
|
var _ yaml.Filter = Filter{}
|
||||||
// fieldSpecFilter stores internal state and should not be reused
|
|
||||||
type fieldSpecFilter struct {
|
// Filter applies a single fieldSpec to a single object
|
||||||
|
// Filter stores internal state and should not be reused
|
||||||
|
type Filter struct {
|
||||||
// FieldSpec contains the path to the value to set.
|
// FieldSpec contains the path to the value to set.
|
||||||
FieldSpec types.FieldSpec `yaml:"fieldSpec"`
|
FieldSpec types.FieldSpec `yaml:"fieldSpec"`
|
||||||
|
|
||||||
// Set the field using this function
|
// Set the field using this function
|
||||||
SetValue SetFn
|
SetValue filtersutil.SetFn
|
||||||
|
|
||||||
// CreateKind defines the type of node to create if the field is not found
|
// CreateKind defines the type of node to create if the field is not found
|
||||||
CreateKind yaml.Kind
|
CreateKind yaml.Kind
|
||||||
@@ -29,48 +32,54 @@ type fieldSpecFilter struct {
|
|||||||
path []string
|
path []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fltr fieldSpecFilter) Filter(obj *yaml.RNode) (*yaml.RNode, error) {
|
func (fltr Filter) Filter(obj *yaml.RNode) (*yaml.RNode, error) {
|
||||||
// check if the FieldSpec applies to the object
|
// check if the FieldSpec applies to the object
|
||||||
if match, err := isMatchGVK(fltr.FieldSpec, obj); !match || err != nil {
|
if match, err := isMatchGVK(fltr.FieldSpec, obj); !match || err != nil {
|
||||||
return obj, errors.Wrap(err)
|
return obj, errors.Wrap(err)
|
||||||
}
|
}
|
||||||
fltr.path = strings.Split(fltr.FieldSpec.Path, "/")
|
fltr.path = splitPath(fltr.FieldSpec.Path)
|
||||||
if err := fltr.filter(obj); err != nil {
|
if err := fltr.filter(obj); err != nil {
|
||||||
s, _ := obj.String()
|
s, _ := obj.String()
|
||||||
return nil, errors.WrapPrefixf(err,
|
return nil, errors.WrapPrefixf(err,
|
||||||
"obj %v at path %v", s, fltr.FieldSpec.Path)
|
"obj '%s' at path '%v'", s, fltr.FieldSpec.Path)
|
||||||
}
|
}
|
||||||
return obj, nil
|
return obj, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fltr fieldSpecFilter) filter(obj *yaml.RNode) error {
|
func (fltr Filter) filter(obj *yaml.RNode) error {
|
||||||
if len(fltr.path) == 0 {
|
if len(fltr.path) == 0 {
|
||||||
// found the field -- set its value
|
// found the field -- set its value
|
||||||
return fltr.SetValue(obj)
|
return fltr.SetValue(obj)
|
||||||
}
|
}
|
||||||
|
if obj.IsTaggedNull() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
switch obj.YNode().Kind {
|
switch obj.YNode().Kind {
|
||||||
case yaml.SequenceNode:
|
case yaml.SequenceNode:
|
||||||
return fltr.seq(obj)
|
return fltr.seq(obj)
|
||||||
case yaml.MappingNode:
|
case yaml.MappingNode:
|
||||||
return fltr.field(obj)
|
return fltr.field(obj)
|
||||||
|
default:
|
||||||
|
return errors.Errorf("expected sequence or mapping node")
|
||||||
}
|
}
|
||||||
// not found -- this might be an error since the type doesn't match
|
|
||||||
|
|
||||||
return errors.Errorf("unsupported yaml node")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// field calls filter on the field matching the next path element
|
// field calls filter on the field matching the next path element
|
||||||
func (fltr fieldSpecFilter) field(obj *yaml.RNode) error {
|
func (fltr Filter) field(obj *yaml.RNode) error {
|
||||||
fieldName, isSeq := isSequenceField(fltr.path[0])
|
fieldName, isSeq := isSequenceField(fltr.path[0])
|
||||||
|
|
||||||
// lookup the field matching the next path element
|
// lookup the field matching the next path element
|
||||||
var lookupField yaml.Filter
|
var lookupField yaml.Filter
|
||||||
var kind yaml.Kind
|
var kind yaml.Kind
|
||||||
var tag string
|
tag := yaml.NodeTagEmpty
|
||||||
switch {
|
switch {
|
||||||
case !fltr.FieldSpec.CreateIfNotPresent || fltr.CreateKind == 0 || isSeq:
|
case !fltr.FieldSpec.CreateIfNotPresent || fltr.CreateKind == 0 || isSeq:
|
||||||
// dont' create the field if we don't find it
|
// dont' create the field if we don't find it
|
||||||
lookupField = yaml.Lookup(fieldName)
|
lookupField = yaml.Lookup(fieldName)
|
||||||
|
if isSeq {
|
||||||
|
// The query path thinks this field should be a sequence;
|
||||||
|
// accept this hint for use later if the tag is NodeTagNull.
|
||||||
|
kind = yaml.SequenceNode
|
||||||
|
}
|
||||||
case len(fltr.path) <= 1:
|
case len(fltr.path) <= 1:
|
||||||
// create the field if it is missing: use the provided node kind
|
// create the field if it is missing: use the provided node kind
|
||||||
lookupField = yaml.LookupCreate(fltr.CreateKind, fieldName)
|
lookupField = yaml.LookupCreate(fltr.CreateKind, fieldName)
|
||||||
@@ -80,7 +89,7 @@ func (fltr fieldSpecFilter) field(obj *yaml.RNode) error {
|
|||||||
// create the field if it is missing: must be a mapping node
|
// create the field if it is missing: must be a mapping node
|
||||||
lookupField = yaml.LookupCreate(yaml.MappingNode, fieldName)
|
lookupField = yaml.LookupCreate(yaml.MappingNode, fieldName)
|
||||||
kind = yaml.MappingNode
|
kind = yaml.MappingNode
|
||||||
tag = "!!map"
|
tag = yaml.NodeTagMap
|
||||||
}
|
}
|
||||||
|
|
||||||
// locate (or maybe create) the field
|
// locate (or maybe create) the field
|
||||||
@@ -89,9 +98,10 @@ func (fltr fieldSpecFilter) field(obj *yaml.RNode) error {
|
|||||||
return errors.WrapPrefixf(err, "fieldName: %s", fieldName)
|
return errors.WrapPrefixf(err, "fieldName: %s", fieldName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the value exists, but is null, then change it to the creation type
|
// if the value exists, but is null and kind is set,
|
||||||
|
// then change it to the creation type
|
||||||
// TODO: update yaml.LookupCreate to support this
|
// TODO: update yaml.LookupCreate to support this
|
||||||
if field.YNode().Tag == "!!null" {
|
if field.YNode().Tag == yaml.NodeTagNull && yaml.IsCreate(kind) {
|
||||||
field.YNode().Kind = kind
|
field.YNode().Kind = kind
|
||||||
field.YNode().Tag = tag
|
field.YNode().Tag = tag
|
||||||
}
|
}
|
||||||
@@ -104,9 +114,9 @@ func (fltr fieldSpecFilter) field(obj *yaml.RNode) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// seq calls filter on all sequence elements
|
// seq calls filter on all sequence elements
|
||||||
func (fltr fieldSpecFilter) seq(obj *yaml.RNode) error {
|
func (fltr Filter) seq(obj *yaml.RNode) error {
|
||||||
if err := obj.VisitElements(func(node *yaml.RNode) error {
|
if err := obj.VisitElements(func(node *yaml.RNode) error {
|
||||||
// recurse on each element -- re-allocating a fieldSpecFilter is
|
// recurse on each element -- re-allocating a Filter is
|
||||||
// not strictly required, but is more consistent with field
|
// not strictly required, but is more consistent with field
|
||||||
// and less likely to have side effects
|
// and less likely to have side effects
|
||||||
// keep the entire path -- it does not contain parts for sequences
|
// keep the entire path -- it does not contain parts for sequences
|
||||||
@@ -153,3 +163,18 @@ func isMatchGVK(fs types.FieldSpec, obj *yaml.RNode) (bool, error) {
|
|||||||
|
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func splitPath(path string) []string {
|
||||||
|
ps := strings.Split(path, "/")
|
||||||
|
var res []string
|
||||||
|
res = append(res, ps[0])
|
||||||
|
for i := 1; i < len(ps); i++ {
|
||||||
|
lastIndex := len(res) - 1
|
||||||
|
if strings.HasSuffix(res[lastIndex], "\\") {
|
||||||
|
res[lastIndex] = strings.TrimSuffix(res[lastIndex], "\\") + "/" + ps[i]
|
||||||
|
} else {
|
||||||
|
res = append(res, ps[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
535
api/filters/fieldspec/fieldspec_test.go
Normal file
535
api/filters/fieldspec/fieldspec_test.go
Normal file
@@ -0,0 +1,535 @@
|
|||||||
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package fieldspec_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"sigs.k8s.io/kustomize/api/filters/fieldspec"
|
||||||
|
"sigs.k8s.io/kustomize/api/filters/filtersutil"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TestCase struct {
|
||||||
|
name string
|
||||||
|
input string
|
||||||
|
expected string
|
||||||
|
filter fieldspec.Filter
|
||||||
|
fieldSpec string
|
||||||
|
error string
|
||||||
|
}
|
||||||
|
|
||||||
|
var tests = []TestCase{
|
||||||
|
{
|
||||||
|
name: "update",
|
||||||
|
fieldSpec: `
|
||||||
|
path: a/b
|
||||||
|
group: foo
|
||||||
|
kind: Bar
|
||||||
|
`,
|
||||||
|
input: `
|
||||||
|
apiVersion: foo/v1beta1
|
||||||
|
kind: Bar
|
||||||
|
a:
|
||||||
|
b: c
|
||||||
|
`,
|
||||||
|
expected: `
|
||||||
|
apiVersion: foo/v1beta1
|
||||||
|
kind: Bar
|
||||||
|
a:
|
||||||
|
b: e
|
||||||
|
`,
|
||||||
|
filter: fieldspec.Filter{
|
||||||
|
SetValue: filtersutil.SetScalar("e"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: "update-kind-not-match",
|
||||||
|
fieldSpec: `
|
||||||
|
path: a/b
|
||||||
|
group: foo
|
||||||
|
kind: Bar1
|
||||||
|
`,
|
||||||
|
input: `
|
||||||
|
apiVersion: foo/v1beta1
|
||||||
|
kind: Bar2
|
||||||
|
a:
|
||||||
|
b: c
|
||||||
|
`,
|
||||||
|
expected: `
|
||||||
|
apiVersion: foo/v1beta1
|
||||||
|
kind: Bar2
|
||||||
|
a:
|
||||||
|
b: c
|
||||||
|
`,
|
||||||
|
filter: fieldspec.Filter{
|
||||||
|
SetValue: filtersutil.SetScalar("e"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: "update-group-not-match",
|
||||||
|
fieldSpec: `
|
||||||
|
path: a/b
|
||||||
|
group: foo1
|
||||||
|
kind: Bar
|
||||||
|
`,
|
||||||
|
input: `
|
||||||
|
apiVersion: foo2/v1beta1
|
||||||
|
kind: Bar
|
||||||
|
a:
|
||||||
|
b: c
|
||||||
|
`,
|
||||||
|
expected: `
|
||||||
|
apiVersion: foo2/v1beta1
|
||||||
|
kind: Bar
|
||||||
|
a:
|
||||||
|
b: c
|
||||||
|
`,
|
||||||
|
filter: fieldspec.Filter{
|
||||||
|
SetValue: filtersutil.SetScalar("e"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: "update-version-not-match",
|
||||||
|
fieldSpec: `
|
||||||
|
path: a/b
|
||||||
|
group: foo
|
||||||
|
version: v1beta1
|
||||||
|
kind: Bar
|
||||||
|
`,
|
||||||
|
input: `
|
||||||
|
apiVersion: foo/v1beta2
|
||||||
|
kind: Bar
|
||||||
|
a:
|
||||||
|
b: c
|
||||||
|
`,
|
||||||
|
expected: `
|
||||||
|
apiVersion: foo/v1beta2
|
||||||
|
kind: Bar
|
||||||
|
a:
|
||||||
|
b: c
|
||||||
|
`,
|
||||||
|
filter: fieldspec.Filter{
|
||||||
|
SetValue: filtersutil.SetScalar("e"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: "bad-version",
|
||||||
|
fieldSpec: `
|
||||||
|
path: a/b
|
||||||
|
group: foo
|
||||||
|
version: v1beta1
|
||||||
|
kind: Bar
|
||||||
|
`,
|
||||||
|
input: `
|
||||||
|
apiVersion: foo/v1beta2/something
|
||||||
|
kind: Bar
|
||||||
|
a:
|
||||||
|
b: c
|
||||||
|
`,
|
||||||
|
expected: `
|
||||||
|
apiVersion: foo/v1beta2/something
|
||||||
|
kind: Bar
|
||||||
|
a:
|
||||||
|
b: c
|
||||||
|
`,
|
||||||
|
filter: fieldspec.Filter{
|
||||||
|
SetValue: filtersutil.SetScalar("e"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: "bad-meta",
|
||||||
|
fieldSpec: `
|
||||||
|
path: a/b
|
||||||
|
group: foo
|
||||||
|
version: v1beta1
|
||||||
|
kind: Bar
|
||||||
|
`,
|
||||||
|
input: `
|
||||||
|
a:
|
||||||
|
b: c
|
||||||
|
`,
|
||||||
|
filter: fieldspec.Filter{
|
||||||
|
SetValue: filtersutil.SetScalar("e"),
|
||||||
|
},
|
||||||
|
error: "missing Resource metadata",
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: "miss-match-type",
|
||||||
|
fieldSpec: `
|
||||||
|
path: a/b/c
|
||||||
|
kind: Bar
|
||||||
|
`,
|
||||||
|
input: `
|
||||||
|
kind: Bar
|
||||||
|
a:
|
||||||
|
b: a
|
||||||
|
`,
|
||||||
|
error: "obj 'kind: Bar\na:\n b: a\n' at path 'a/b/c': " +
|
||||||
|
"expected sequence or mapping node",
|
||||||
|
filter: fieldspec.Filter{
|
||||||
|
SetValue: filtersutil.SetScalar("e"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: "add",
|
||||||
|
fieldSpec: `
|
||||||
|
path: a/b/c/d
|
||||||
|
group: foo
|
||||||
|
create: true
|
||||||
|
kind: Bar
|
||||||
|
`,
|
||||||
|
input: `
|
||||||
|
apiVersion: foo/v1beta1
|
||||||
|
kind: Bar
|
||||||
|
a: {}
|
||||||
|
`,
|
||||||
|
expected: `
|
||||||
|
apiVersion: foo/v1beta1
|
||||||
|
kind: Bar
|
||||||
|
a: {b: {c: {d: e}}}
|
||||||
|
`,
|
||||||
|
filter: fieldspec.Filter{
|
||||||
|
SetValue: filtersutil.SetScalar("e"),
|
||||||
|
CreateKind: yaml.ScalarNode,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: "update-in-sequence",
|
||||||
|
fieldSpec: `
|
||||||
|
path: a/b[]/c/d
|
||||||
|
group: foo
|
||||||
|
kind: Bar
|
||||||
|
`,
|
||||||
|
input: `
|
||||||
|
apiVersion: foo/v1beta1
|
||||||
|
kind: Bar
|
||||||
|
a:
|
||||||
|
b:
|
||||||
|
- c:
|
||||||
|
d: a
|
||||||
|
`,
|
||||||
|
expected: `
|
||||||
|
apiVersion: foo/v1beta1
|
||||||
|
kind: Bar
|
||||||
|
a:
|
||||||
|
b:
|
||||||
|
- c:
|
||||||
|
d: e
|
||||||
|
`,
|
||||||
|
filter: fieldspec.Filter{
|
||||||
|
SetValue: filtersutil.SetScalar("e"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
// Don't create a sequence
|
||||||
|
{
|
||||||
|
name: "empty-sequence-no-create",
|
||||||
|
fieldSpec: `
|
||||||
|
path: a/b[]/c/d
|
||||||
|
group: foo
|
||||||
|
create: true
|
||||||
|
kind: Bar
|
||||||
|
`,
|
||||||
|
input: `
|
||||||
|
apiVersion: foo/v1beta1
|
||||||
|
kind: Bar
|
||||||
|
a: {}
|
||||||
|
`,
|
||||||
|
expected: `
|
||||||
|
apiVersion: foo/v1beta1
|
||||||
|
kind: Bar
|
||||||
|
a: {}
|
||||||
|
`,
|
||||||
|
filter: fieldspec.Filter{
|
||||||
|
SetValue: filtersutil.SetScalar("e"),
|
||||||
|
CreateKind: yaml.ScalarNode,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
// Create a new field for an element in a sequence
|
||||||
|
{
|
||||||
|
name: "empty-sequence-create",
|
||||||
|
fieldSpec: `
|
||||||
|
path: a/b[]/c/d
|
||||||
|
group: foo
|
||||||
|
create: true
|
||||||
|
kind: Bar
|
||||||
|
`,
|
||||||
|
input: `
|
||||||
|
apiVersion: foo/v1beta1
|
||||||
|
kind: Bar
|
||||||
|
a:
|
||||||
|
b:
|
||||||
|
- c: {}
|
||||||
|
`,
|
||||||
|
expected: `
|
||||||
|
apiVersion: foo/v1beta1
|
||||||
|
kind: Bar
|
||||||
|
a:
|
||||||
|
b:
|
||||||
|
- c: {d: e}
|
||||||
|
`,
|
||||||
|
filter: fieldspec.Filter{
|
||||||
|
SetValue: filtersutil.SetScalar("e"),
|
||||||
|
CreateKind: yaml.ScalarNode,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: "group v1",
|
||||||
|
fieldSpec: `
|
||||||
|
path: a/b
|
||||||
|
group: v1
|
||||||
|
create: true
|
||||||
|
kind: Bar
|
||||||
|
`,
|
||||||
|
input: `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Bar
|
||||||
|
`,
|
||||||
|
expected: `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Bar
|
||||||
|
`,
|
||||||
|
filter: fieldspec.Filter{
|
||||||
|
SetValue: filtersutil.SetScalar("e"),
|
||||||
|
CreateKind: yaml.ScalarNode,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: "version v1",
|
||||||
|
fieldSpec: `
|
||||||
|
path: a/b
|
||||||
|
version: v1
|
||||||
|
create: true
|
||||||
|
kind: Bar
|
||||||
|
`,
|
||||||
|
input: `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Bar
|
||||||
|
`,
|
||||||
|
expected: `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Bar
|
||||||
|
a:
|
||||||
|
b: e
|
||||||
|
`,
|
||||||
|
filter: fieldspec.Filter{
|
||||||
|
SetValue: filtersutil.SetScalar("e"),
|
||||||
|
CreateKind: yaml.ScalarNode,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "successfully set field on array entry no sequence hint",
|
||||||
|
fieldSpec: `
|
||||||
|
path: spec/containers/image
|
||||||
|
version: v1
|
||||||
|
kind: Bar
|
||||||
|
`,
|
||||||
|
input: `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Bar
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: foo
|
||||||
|
`,
|
||||||
|
expected: `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Bar
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: bar
|
||||||
|
`,
|
||||||
|
filter: fieldspec.Filter{
|
||||||
|
SetValue: filtersutil.SetScalar("bar"),
|
||||||
|
CreateKind: yaml.ScalarNode,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "successfully set field on array entry with sequence hint",
|
||||||
|
fieldSpec: `
|
||||||
|
path: spec/containers[]/image
|
||||||
|
version: v1
|
||||||
|
kind: Bar
|
||||||
|
`,
|
||||||
|
input: `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Bar
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: foo
|
||||||
|
`,
|
||||||
|
expected: `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Bar
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: bar
|
||||||
|
`,
|
||||||
|
filter: fieldspec.Filter{
|
||||||
|
SetValue: filtersutil.SetScalar("bar"),
|
||||||
|
CreateKind: yaml.ScalarNode,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "failure to set field on array entry with sequence hint in path",
|
||||||
|
fieldSpec: `
|
||||||
|
path: spec/containers[]/image
|
||||||
|
version: v1
|
||||||
|
kind: Bar
|
||||||
|
`,
|
||||||
|
input: `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Bar
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
`,
|
||||||
|
expected: `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Bar
|
||||||
|
spec:
|
||||||
|
containers: []
|
||||||
|
`,
|
||||||
|
filter: fieldspec.Filter{
|
||||||
|
SetValue: filtersutil.SetScalar("bar"),
|
||||||
|
CreateKind: yaml.ScalarNode,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "failure to set field on array entry, no sequence hint in path",
|
||||||
|
fieldSpec: `
|
||||||
|
path: spec/containers/image
|
||||||
|
version: v1
|
||||||
|
kind: Bar
|
||||||
|
`,
|
||||||
|
input: `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Bar
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
`,
|
||||||
|
expected: `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Bar
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
`,
|
||||||
|
filter: fieldspec.Filter{
|
||||||
|
SetValue: filtersutil.SetScalar("bar"),
|
||||||
|
CreateKind: yaml.ScalarNode,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "filedname with slash '/'",
|
||||||
|
fieldSpec: `
|
||||||
|
path: a/b\/c/d
|
||||||
|
version: v1
|
||||||
|
kind: Bar
|
||||||
|
`,
|
||||||
|
input: `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Bar
|
||||||
|
a:
|
||||||
|
b/c:
|
||||||
|
d: foo
|
||||||
|
`,
|
||||||
|
expected: `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Bar
|
||||||
|
a:
|
||||||
|
b/c:
|
||||||
|
d: bar
|
||||||
|
`,
|
||||||
|
filter: fieldspec.Filter{
|
||||||
|
SetValue: filtersutil.SetScalar("bar"),
|
||||||
|
CreateKind: yaml.ScalarNode,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "filedname with multiple '/'",
|
||||||
|
fieldSpec: `
|
||||||
|
path: a/b\/c/d\/e/f
|
||||||
|
version: v1
|
||||||
|
kind: Bar
|
||||||
|
`,
|
||||||
|
input: `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Bar
|
||||||
|
a:
|
||||||
|
b/c:
|
||||||
|
d/e:
|
||||||
|
f: foo
|
||||||
|
`,
|
||||||
|
expected: `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Bar
|
||||||
|
a:
|
||||||
|
b/c:
|
||||||
|
d/e:
|
||||||
|
f: bar
|
||||||
|
`,
|
||||||
|
filter: fieldspec.Filter{
|
||||||
|
SetValue: filtersutil.SetScalar("bar"),
|
||||||
|
CreateKind: yaml.ScalarNode,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFilter_Filter(t *testing.T) {
|
||||||
|
for i := range tests {
|
||||||
|
test := tests[i]
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
err := yaml.Unmarshal([]byte(test.fieldSpec), &test.filter.FieldSpec)
|
||||||
|
if !assert.NoError(t, err) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
|
||||||
|
out := &bytes.Buffer{}
|
||||||
|
rw := &kio.ByteReadWriter{
|
||||||
|
Reader: bytes.NewBufferString(test.input),
|
||||||
|
Writer: out,
|
||||||
|
OmitReaderAnnotations: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
// run the filter
|
||||||
|
err = kio.Pipeline{
|
||||||
|
Inputs: []kio.Reader{rw},
|
||||||
|
Filters: []kio.Filter{kio.FilterAll(test.filter)},
|
||||||
|
Outputs: []kio.Writer{rw},
|
||||||
|
}.Execute()
|
||||||
|
if test.error != "" {
|
||||||
|
if !assert.EqualError(t, err, test.error) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
// stop rest of test
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !assert.NoError(t, err) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
|
||||||
|
// check results
|
||||||
|
if !assert.Equal(t,
|
||||||
|
strings.TrimSpace(test.expected),
|
||||||
|
strings.TrimSpace(out.String())) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
// Copyright 2019 The Kubernetes Authors.
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
package fsslice
|
package fieldspec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
// Copyright 2019 The Kubernetes Authors.
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
package fsslice
|
package fieldspec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
33
api/filters/filtersutil/setters.go
Normal file
33
api/filters/filtersutil/setters.go
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package filtersutil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SetFn is a function that accepts an RNode to possibly modify.
|
||||||
|
type SetFn func(*yaml.RNode) error
|
||||||
|
|
||||||
|
// SetScalar returns a SetFn to set a scalar value
|
||||||
|
func SetScalar(value string) SetFn {
|
||||||
|
return func(node *yaml.RNode) error {
|
||||||
|
return node.PipeE(yaml.FieldSetter{StringValue: value})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetEntry returns a SetFn to set an entry in a map
|
||||||
|
func SetEntry(key, value, tag string) SetFn {
|
||||||
|
n := &yaml.Node{
|
||||||
|
Kind: yaml.ScalarNode,
|
||||||
|
Value: value,
|
||||||
|
Tag: tag,
|
||||||
|
}
|
||||||
|
if tag == yaml.NodeTagString && yaml.IsYaml1_1NonString(n) {
|
||||||
|
n.Style = yaml.DoubleQuotedStyle
|
||||||
|
}
|
||||||
|
return func(node *yaml.RNode) error {
|
||||||
|
return node.PipeE(yaml.FieldSetter{
|
||||||
|
Name: key,
|
||||||
|
Value: yaml.NewRNode(n),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
// Copyright 2020 The Kubernetes Authors.
|
// Copyright 2020 The Kubernetes Authors.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
// Package fsslice contains a yaml.Filter to modify a resource using an
|
// Package fsslice contains a yaml.Filter to modify a resource if
|
||||||
// FsSlice to identify fields to be updated within the resource.
|
// it matches one or more FieldSpec entries.
|
||||||
package fsslice
|
package fsslice
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"sigs.k8s.io/kustomize/api/filters/filtersutil"
|
||||||
"sigs.k8s.io/kustomize/api/filters/fsslice"
|
"sigs.k8s.io/kustomize/api/filters/fsslice"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
"sigs.k8s.io/kustomize/kyaml/kio"
|
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||||
@@ -30,7 +31,7 @@ metadata:
|
|||||||
}
|
}
|
||||||
fltr := fsslice.Filter{
|
fltr := fsslice.Filter{
|
||||||
CreateKind: yaml.ScalarNode,
|
CreateKind: yaml.ScalarNode,
|
||||||
SetValue: fsslice.SetScalar("green"),
|
SetValue: filtersutil.SetScalar("green"),
|
||||||
FsSlice: []types.FieldSpec{
|
FsSlice: []types.FieldSpec{
|
||||||
{Path: "a/b", CreateIfNotPresent: true},
|
{Path: "a/b", CreateIfNotPresent: true},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -4,48 +4,22 @@
|
|||||||
package fsslice
|
package fsslice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sigs.k8s.io/kustomize/api/filters/fieldspec"
|
||||||
|
"sigs.k8s.io/kustomize/api/filters/filtersutil"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetFn sets a value
|
|
||||||
type SetFn func(*yaml.RNode) error
|
|
||||||
|
|
||||||
// SetScalar returns a SetFn to set a scalar value
|
|
||||||
func SetScalar(value string) SetFn {
|
|
||||||
return func(node *yaml.RNode) error {
|
|
||||||
return node.PipeE(yaml.FieldSetter{StringValue: value})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetEntry returns a SetFn to set an entry in a map
|
|
||||||
func SetEntry(key, value, tag string) SetFn {
|
|
||||||
n := &yaml.Node{
|
|
||||||
Kind: yaml.ScalarNode,
|
|
||||||
Value: value,
|
|
||||||
Tag: tag,
|
|
||||||
}
|
|
||||||
if tag == yaml.StringTag && yaml.IsYaml1_1NonString(n) {
|
|
||||||
n.Style = yaml.DoubleQuotedStyle
|
|
||||||
}
|
|
||||||
return func(node *yaml.RNode) error {
|
|
||||||
return node.PipeE(yaml.FieldSetter{
|
|
||||||
Name: key,
|
|
||||||
Value: yaml.NewRNode(n),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ yaml.Filter = Filter{}
|
var _ yaml.Filter = Filter{}
|
||||||
|
|
||||||
// Filter uses an FsSlice to modify fields on a single object
|
// Filter ranges over an FsSlice to modify fields on a single object.
|
||||||
|
// An FsSlice is a range of FieldSpecs. A FieldSpec is a GVK plus a path.
|
||||||
type Filter struct {
|
type Filter struct {
|
||||||
// FieldSpecList list of FieldSpecs to set
|
// FieldSpecList list of FieldSpecs to set
|
||||||
FsSlice types.FsSlice `yaml:"fsSlice"`
|
FsSlice types.FsSlice `yaml:"fsSlice"`
|
||||||
|
|
||||||
// SetValue is called on each field that matches one of the FieldSpecs
|
// SetValue is called on each field that matches one of the FieldSpecs
|
||||||
SetValue SetFn
|
SetValue filtersutil.SetFn
|
||||||
|
|
||||||
// CreateKind is used to create fields that do not exist
|
// CreateKind is used to create fields that do not exist
|
||||||
CreateKind yaml.Kind
|
CreateKind yaml.Kind
|
||||||
@@ -59,7 +33,7 @@ func (fltr Filter) Filter(obj *yaml.RNode) (*yaml.RNode, error) {
|
|||||||
// apply this FieldSpec
|
// apply this FieldSpec
|
||||||
// create a new filter for each iteration because they
|
// create a new filter for each iteration because they
|
||||||
// store internal state about the field paths
|
// store internal state about the field paths
|
||||||
_, err := (&fieldSpecFilter{
|
_, err := (&fieldspec.Filter{
|
||||||
FieldSpec: fltr.FsSlice[i],
|
FieldSpec: fltr.FsSlice[i],
|
||||||
SetValue: fltr.SetValue,
|
SetValue: fltr.SetValue,
|
||||||
CreateKind: fltr.CreateKind,
|
CreateKind: fltr.CreateKind,
|
||||||
|
|||||||
@@ -9,335 +9,77 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"sigs.k8s.io/kustomize/api/filters/fsslice"
|
"sigs.k8s.io/kustomize/api/filters/filtersutil"
|
||||||
|
. "sigs.k8s.io/kustomize/api/filters/fsslice"
|
||||||
"sigs.k8s.io/kustomize/kyaml/kio"
|
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TestCase struct {
|
type TestCase struct {
|
||||||
name string
|
|
||||||
input string
|
input string
|
||||||
expected string
|
expected string
|
||||||
filter fsslice.Filter
|
filter Filter
|
||||||
fsSlice string
|
fsSlice string
|
||||||
error string
|
error string
|
||||||
}
|
}
|
||||||
|
|
||||||
var tests = []TestCase{
|
var tests = map[string]TestCase{
|
||||||
{
|
"empty": {
|
||||||
name: "update",
|
|
||||||
fsSlice: `
|
fsSlice: `
|
||||||
- path: a/b
|
|
||||||
group: foo
|
|
||||||
kind: Bar
|
|
||||||
`,
|
`,
|
||||||
input: `
|
input: `
|
||||||
apiVersion: foo/v1beta1
|
apiVersion: foo/v1
|
||||||
kind: Bar
|
kind: Bar
|
||||||
a:
|
|
||||||
b: c
|
|
||||||
`,
|
`,
|
||||||
expected: `
|
expected: `
|
||||||
apiVersion: foo/v1beta1
|
apiVersion: foo/v1
|
||||||
kind: Bar
|
kind: Bar
|
||||||
a:
|
|
||||||
b: e
|
|
||||||
`,
|
`,
|
||||||
filter: fsslice.Filter{
|
filter: Filter{
|
||||||
SetValue: fsslice.SetScalar("e"),
|
SetValue: filtersutil.SetScalar("e"),
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
name: "update-kind-not-match",
|
|
||||||
fsSlice: `
|
|
||||||
- path: a/b
|
|
||||||
group: foo
|
|
||||||
kind: Bar1
|
|
||||||
`,
|
|
||||||
input: `
|
|
||||||
apiVersion: foo/v1beta1
|
|
||||||
kind: Bar2
|
|
||||||
a:
|
|
||||||
b: c
|
|
||||||
`,
|
|
||||||
expected: `
|
|
||||||
apiVersion: foo/v1beta1
|
|
||||||
kind: Bar2
|
|
||||||
a:
|
|
||||||
b: c
|
|
||||||
`,
|
|
||||||
filter: fsslice.Filter{
|
|
||||||
SetValue: fsslice.SetScalar("e"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
name: "update-group-not-match",
|
|
||||||
fsSlice: `
|
|
||||||
- path: a/b
|
|
||||||
group: foo1
|
|
||||||
kind: Bar
|
|
||||||
`,
|
|
||||||
input: `
|
|
||||||
apiVersion: foo2/v1beta1
|
|
||||||
kind: Bar
|
|
||||||
a:
|
|
||||||
b: c
|
|
||||||
`,
|
|
||||||
expected: `
|
|
||||||
apiVersion: foo2/v1beta1
|
|
||||||
kind: Bar
|
|
||||||
a:
|
|
||||||
b: c
|
|
||||||
`,
|
|
||||||
filter: fsslice.Filter{
|
|
||||||
SetValue: fsslice.SetScalar("e"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
name: "update-version-not-match",
|
|
||||||
fsSlice: `
|
|
||||||
- path: a/b
|
|
||||||
group: foo
|
|
||||||
version: v1beta1
|
|
||||||
kind: Bar
|
|
||||||
`,
|
|
||||||
input: `
|
|
||||||
apiVersion: foo/v1beta2
|
|
||||||
kind: Bar
|
|
||||||
a:
|
|
||||||
b: c
|
|
||||||
`,
|
|
||||||
expected: `
|
|
||||||
apiVersion: foo/v1beta2
|
|
||||||
kind: Bar
|
|
||||||
a:
|
|
||||||
b: c
|
|
||||||
`,
|
|
||||||
filter: fsslice.Filter{
|
|
||||||
SetValue: fsslice.SetScalar("e"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
name: "bad-version",
|
|
||||||
fsSlice: `
|
|
||||||
- path: a/b
|
|
||||||
group: foo
|
|
||||||
version: v1beta1
|
|
||||||
kind: Bar
|
|
||||||
`,
|
|
||||||
input: `
|
|
||||||
apiVersion: foo/v1beta2/something
|
|
||||||
kind: Bar
|
|
||||||
a:
|
|
||||||
b: c
|
|
||||||
`,
|
|
||||||
expected: `
|
|
||||||
apiVersion: foo/v1beta2/something
|
|
||||||
kind: Bar
|
|
||||||
a:
|
|
||||||
b: c
|
|
||||||
`,
|
|
||||||
filter: fsslice.Filter{
|
|
||||||
SetValue: fsslice.SetScalar("e"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
name: "bad-meta",
|
|
||||||
fsSlice: `
|
|
||||||
- path: a/b
|
|
||||||
group: foo
|
|
||||||
version: v1beta1
|
|
||||||
kind: Bar
|
|
||||||
`,
|
|
||||||
input: `
|
|
||||||
a:
|
|
||||||
b: c
|
|
||||||
`,
|
|
||||||
filter: fsslice.Filter{
|
|
||||||
SetValue: fsslice.SetScalar("e"),
|
|
||||||
},
|
|
||||||
error: "missing Resource metadata",
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
name: "miss-match-type",
|
|
||||||
fsSlice: `
|
|
||||||
- path: a/b/c
|
|
||||||
kind: Bar
|
|
||||||
`,
|
|
||||||
input: `
|
|
||||||
kind: Bar
|
|
||||||
a:
|
|
||||||
b: a
|
|
||||||
`,
|
|
||||||
error: "obj kind: Bar\na:\n b: a\n at path a/b/c: unsupported yaml node",
|
|
||||||
filter: fsslice.Filter{
|
|
||||||
SetValue: fsslice.SetScalar("e"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
name: "add",
|
|
||||||
fsSlice: `
|
|
||||||
- path: a/b/c/d
|
|
||||||
group: foo
|
|
||||||
create: true
|
|
||||||
kind: Bar
|
|
||||||
`,
|
|
||||||
input: `
|
|
||||||
apiVersion: foo/v1beta1
|
|
||||||
kind: Bar
|
|
||||||
a: {}
|
|
||||||
`,
|
|
||||||
expected: `
|
|
||||||
apiVersion: foo/v1beta1
|
|
||||||
kind: Bar
|
|
||||||
a: {b: {c: {d: e}}}
|
|
||||||
`,
|
|
||||||
filter: fsslice.Filter{
|
|
||||||
SetValue: fsslice.SetScalar("e"),
|
|
||||||
CreateKind: yaml.ScalarNode,
|
CreateKind: yaml.ScalarNode,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"two": {
|
||||||
{
|
|
||||||
name: "update-in-sequence",
|
|
||||||
fsSlice: `
|
|
||||||
- path: a/b[]/c/d
|
|
||||||
group: foo
|
|
||||||
kind: Bar
|
|
||||||
`,
|
|
||||||
input: `
|
|
||||||
apiVersion: foo/v1beta1
|
|
||||||
kind: Bar
|
|
||||||
a:
|
|
||||||
b:
|
|
||||||
- c:
|
|
||||||
d: a
|
|
||||||
`,
|
|
||||||
expected: `
|
|
||||||
apiVersion: foo/v1beta1
|
|
||||||
kind: Bar
|
|
||||||
a:
|
|
||||||
b:
|
|
||||||
- c:
|
|
||||||
d: e
|
|
||||||
`,
|
|
||||||
filter: fsslice.Filter{
|
|
||||||
SetValue: fsslice.SetScalar("e"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
// Don't create a sequence
|
|
||||||
{
|
|
||||||
name: "empty-sequence-no-create",
|
|
||||||
fsSlice: `
|
|
||||||
- path: a/b[]/c/d
|
|
||||||
group: foo
|
|
||||||
create: true
|
|
||||||
kind: Bar
|
|
||||||
`,
|
|
||||||
input: `
|
|
||||||
apiVersion: foo/v1beta1
|
|
||||||
kind: Bar
|
|
||||||
a: {}
|
|
||||||
`,
|
|
||||||
expected: `
|
|
||||||
apiVersion: foo/v1beta1
|
|
||||||
kind: Bar
|
|
||||||
a: {}
|
|
||||||
`,
|
|
||||||
filter: fsslice.Filter{
|
|
||||||
SetValue: fsslice.SetScalar("e"),
|
|
||||||
CreateKind: yaml.ScalarNode,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
// Create a new field for an element in a sequence
|
|
||||||
{
|
|
||||||
name: "empty-sequence-create",
|
|
||||||
fsSlice: `
|
|
||||||
- path: a/b[]/c/d
|
|
||||||
group: foo
|
|
||||||
create: true
|
|
||||||
kind: Bar
|
|
||||||
`,
|
|
||||||
input: `
|
|
||||||
apiVersion: foo/v1beta1
|
|
||||||
kind: Bar
|
|
||||||
a:
|
|
||||||
b:
|
|
||||||
- c: {}
|
|
||||||
`,
|
|
||||||
expected: `
|
|
||||||
apiVersion: foo/v1beta1
|
|
||||||
kind: Bar
|
|
||||||
a:
|
|
||||||
b:
|
|
||||||
- c: {d: e}
|
|
||||||
`,
|
|
||||||
filter: fsslice.Filter{
|
|
||||||
SetValue: fsslice.SetScalar("e"),
|
|
||||||
CreateKind: yaml.ScalarNode,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
name: "group v1",
|
|
||||||
fsSlice: `
|
fsSlice: `
|
||||||
- path: a/b
|
- path: a/b
|
||||||
group: v1
|
group: foo
|
||||||
|
version: v1
|
||||||
create: true
|
create: true
|
||||||
kind: Bar
|
kind: Bar
|
||||||
`,
|
- path: q/r[]/s/t
|
||||||
input: `
|
group: foo
|
||||||
apiVersion: v1
|
|
||||||
kind: Bar
|
|
||||||
`,
|
|
||||||
expected: `
|
|
||||||
apiVersion: v1
|
|
||||||
kind: Bar
|
|
||||||
`,
|
|
||||||
filter: fsslice.Filter{
|
|
||||||
SetValue: fsslice.SetScalar("e"),
|
|
||||||
CreateKind: yaml.ScalarNode,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
name: "version v1",
|
|
||||||
fsSlice: `
|
|
||||||
- path: a/b
|
|
||||||
version: v1
|
version: v1
|
||||||
create: true
|
create: true
|
||||||
kind: Bar
|
kind: Bar
|
||||||
`,
|
`,
|
||||||
input: `
|
input: `
|
||||||
apiVersion: v1
|
apiVersion: foo/v1
|
||||||
kind: Bar
|
kind: Bar
|
||||||
|
q:
|
||||||
|
r:
|
||||||
|
- s: {}
|
||||||
`,
|
`,
|
||||||
expected: `
|
expected: `
|
||||||
apiVersion: v1
|
apiVersion: foo/v1
|
||||||
kind: Bar
|
kind: Bar
|
||||||
|
q:
|
||||||
|
r:
|
||||||
|
- s: {t: e}
|
||||||
a:
|
a:
|
||||||
b: e
|
b: e
|
||||||
`,
|
`,
|
||||||
filter: fsslice.Filter{
|
filter: Filter{
|
||||||
SetValue: fsslice.SetScalar("e"),
|
SetValue: filtersutil.SetScalar("e"),
|
||||||
CreateKind: yaml.ScalarNode,
|
CreateKind: yaml.ScalarNode,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilter_Filter(t *testing.T) {
|
func TestFilter(t *testing.T) {
|
||||||
for i := range tests {
|
for name := range tests {
|
||||||
test := tests[i]
|
test := tests[name]
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
err := yaml.Unmarshal([]byte(test.fsSlice), &test.filter.FsSlice)
|
err := yaml.Unmarshal([]byte(test.fsSlice), &test.filter.FsSlice)
|
||||||
if !assert.NoError(t, err) {
|
if !assert.NoError(t, err) {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
|
|||||||
@@ -4,17 +4,24 @@
|
|||||||
package imagetag
|
package imagetag
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sigs.k8s.io/kustomize/api/filters/filtersutil"
|
||||||
"sigs.k8s.io/kustomize/api/filters/fsslice"
|
"sigs.k8s.io/kustomize/api/filters/fsslice"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
"sigs.k8s.io/kustomize/kyaml/kio"
|
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Filter modifies an "image tag", the value used to specify the
|
||||||
|
// name, tag, version digest etc. of (docker) container images
|
||||||
|
// used by a pod template.
|
||||||
type Filter struct {
|
type Filter struct {
|
||||||
// imageTag is the tag we want to apply to the inputs
|
// imageTag is the tag we want to apply to the inputs
|
||||||
|
// The name of the image is used as a key, and other fields
|
||||||
|
// can specify a new name, tag, etc.
|
||||||
ImageTag types.Image `json:"imageTag,omitempty" yaml:"imageTag,omitempty"`
|
ImageTag types.Image `json:"imageTag,omitempty" yaml:"imageTag,omitempty"`
|
||||||
|
|
||||||
// FsSlice contains the FieldSpecs to locate the namespace field
|
// FsSlice contains the FieldSpecs to locate an image field,
|
||||||
|
// e.g. Path: "spec/myContainers[]/image"
|
||||||
FsSlice types.FsSlice `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
FsSlice types.FsSlice `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,6 +33,12 @@ func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f Filter) filter(node *yaml.RNode) (*yaml.RNode, error) {
|
func (f Filter) filter(node *yaml.RNode) (*yaml.RNode, error) {
|
||||||
|
// FsSlice is an allowlist, not a denyList, so to deny
|
||||||
|
// something via configuration a new config mechanism is
|
||||||
|
// needed. Until then, hardcode it.
|
||||||
|
if f.isOnDenyList(node) {
|
||||||
|
return node, nil
|
||||||
|
}
|
||||||
if err := node.PipeE(fsslice.Filter{
|
if err := node.PipeE(fsslice.Filter{
|
||||||
FsSlice: f.FsSlice,
|
FsSlice: f.FsSlice,
|
||||||
SetValue: updateImageTagFn(f.ImageTag),
|
SetValue: updateImageTagFn(f.ImageTag),
|
||||||
@@ -35,7 +48,19 @@ func (f Filter) filter(node *yaml.RNode) (*yaml.RNode, error) {
|
|||||||
return node, nil
|
return node, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateImageTagFn(imageTag types.Image) fsslice.SetFn {
|
func (f Filter) isOnDenyList(node *yaml.RNode) bool {
|
||||||
|
meta, err := node.GetMeta()
|
||||||
|
if err != nil {
|
||||||
|
// A missing 'meta' field will cause problems elsewhere;
|
||||||
|
// ignore it here to keep the signature simple.
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
// Ignore CRDs
|
||||||
|
// https://github.com/kubernetes-sigs/kustomize/issues/890
|
||||||
|
return meta.Kind == `CustomResourceDefinition`
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateImageTagFn(imageTag types.Image) filtersutil.SetFn {
|
||||||
return func(node *yaml.RNode) error {
|
return func(node *yaml.RNode) error {
|
||||||
return node.PipeE(imageTagUpdater{
|
return node.PipeE(imageTagUpdater{
|
||||||
ImageTag: imageTag,
|
ImageTag: imageTag,
|
||||||
|
|||||||
@@ -19,6 +19,162 @@ func TestImageTagUpdater_Filter(t *testing.T) {
|
|||||||
filter Filter
|
filter Filter
|
||||||
fsSlice types.FsSlice
|
fsSlice types.FsSlice
|
||||||
}{
|
}{
|
||||||
|
"ignore CustomResourceDefinition": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apiextensions.k8s.io/v1beta1
|
||||||
|
kind: CustomResourceDefinition
|
||||||
|
metadata:
|
||||||
|
name: whatever
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: whatever
|
||||||
|
`,
|
||||||
|
expectedOutput: `
|
||||||
|
apiVersion: apiextensions.k8s.io/v1beta1
|
||||||
|
kind: CustomResourceDefinition
|
||||||
|
metadata:
|
||||||
|
name: whatever
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: whatever
|
||||||
|
`,
|
||||||
|
filter: Filter{
|
||||||
|
ImageTag: types.Image{
|
||||||
|
Name: "whatever",
|
||||||
|
NewName: "theImageShouldNotChangeInACrd",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fsSlice: []types.FieldSpec{
|
||||||
|
{
|
||||||
|
Path: "spec/containers/image",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
"legacy multiple images in containers": {
|
||||||
|
input: `
|
||||||
|
apiVersion: example.com/v1
|
||||||
|
kind: Foo
|
||||||
|
metadata:
|
||||||
|
name: instance
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: nginx:1.2.1
|
||||||
|
- image: nginx:2.1.2
|
||||||
|
`,
|
||||||
|
expectedOutput: `
|
||||||
|
apiVersion: example.com/v1
|
||||||
|
kind: Foo
|
||||||
|
metadata:
|
||||||
|
name: instance
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: apache@12345
|
||||||
|
- image: apache@12345
|
||||||
|
`,
|
||||||
|
filter: Filter{
|
||||||
|
ImageTag: types.Image{
|
||||||
|
Name: "nginx",
|
||||||
|
NewName: "apache",
|
||||||
|
Digest: "12345",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fsSlice: []types.FieldSpec{
|
||||||
|
{
|
||||||
|
Path: "spec/containers/image",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"legacy both containers and initContainers": {
|
||||||
|
input: `
|
||||||
|
apiVersion: example.com/v1
|
||||||
|
kind: Foo
|
||||||
|
metadata:
|
||||||
|
name: instance
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: nginx:1.2.1
|
||||||
|
- image: tomcat:1.2.3
|
||||||
|
initContainers:
|
||||||
|
- image: nginx:1.2.1
|
||||||
|
- image: apache:1.2.3
|
||||||
|
`,
|
||||||
|
expectedOutput: `
|
||||||
|
apiVersion: example.com/v1
|
||||||
|
kind: Foo
|
||||||
|
metadata:
|
||||||
|
name: instance
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: apache:3.2.1
|
||||||
|
- image: tomcat:1.2.3
|
||||||
|
initContainers:
|
||||||
|
- image: apache:3.2.1
|
||||||
|
- image: apache:1.2.3
|
||||||
|
`,
|
||||||
|
filter: Filter{
|
||||||
|
ImageTag: types.Image{
|
||||||
|
Name: "nginx",
|
||||||
|
NewName: "apache",
|
||||||
|
NewTag: "3.2.1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fsSlice: []types.FieldSpec{
|
||||||
|
{
|
||||||
|
Path: "spec/containers/image",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Path: "spec/initContainers/image",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"legacy updates at multiple depths": {
|
||||||
|
input: `
|
||||||
|
apiVersion: example.com/v1
|
||||||
|
kind: Foo
|
||||||
|
metadata:
|
||||||
|
name: instance
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: nginx:1.2.1
|
||||||
|
- image: tomcat:1.2.3
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
initContainers:
|
||||||
|
- image: nginx:1.2.1
|
||||||
|
- image: apache:1.2.3
|
||||||
|
`,
|
||||||
|
expectedOutput: `
|
||||||
|
apiVersion: example.com/v1
|
||||||
|
kind: Foo
|
||||||
|
metadata:
|
||||||
|
name: instance
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: apache:3.2.1
|
||||||
|
- image: tomcat:1.2.3
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
initContainers:
|
||||||
|
- image: apache:3.2.1
|
||||||
|
- image: apache:1.2.3
|
||||||
|
`,
|
||||||
|
filter: Filter{
|
||||||
|
ImageTag: types.Image{
|
||||||
|
Name: "nginx",
|
||||||
|
NewName: "apache",
|
||||||
|
NewTag: "3.2.1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fsSlice: []types.FieldSpec{
|
||||||
|
{
|
||||||
|
Path: "spec/containers/image",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Path: "spec/template/spec/initContainers/image",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
"update with digest": {
|
"update with digest": {
|
||||||
input: `
|
input: `
|
||||||
apiVersion: example.com/v1
|
apiVersion: example.com/v1
|
||||||
@@ -49,6 +205,7 @@ spec:
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"multiple matches in sequence": {
|
"multiple matches in sequence": {
|
||||||
input: `
|
input: `
|
||||||
apiVersion: example.com/v1
|
apiVersion: example.com/v1
|
||||||
@@ -85,6 +242,422 @@ spec:
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"new Tag": {
|
||||||
|
input: `
|
||||||
|
group: apps
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: deploy1
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: nginx:1.7.9
|
||||||
|
name: nginx-tagged
|
||||||
|
- image: nginx:latest
|
||||||
|
name: nginx-latest
|
||||||
|
- image: foobar:1
|
||||||
|
name: replaced-with-digest
|
||||||
|
- image: postgres:1.8.0
|
||||||
|
name: postgresdb
|
||||||
|
initContainers:
|
||||||
|
- image: nginx
|
||||||
|
name: nginx-notag
|
||||||
|
- image: nginx@sha256:111111111111111111
|
||||||
|
name: nginx-sha256
|
||||||
|
- image: alpine:1.8.0
|
||||||
|
name: init-alpine`,
|
||||||
|
expectedOutput: `
|
||||||
|
group: apps
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: deploy1
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: nginx:v2
|
||||||
|
name: nginx-tagged
|
||||||
|
- image: nginx:v2
|
||||||
|
name: nginx-latest
|
||||||
|
- image: foobar:1
|
||||||
|
name: replaced-with-digest
|
||||||
|
- image: postgres:1.8.0
|
||||||
|
name: postgresdb
|
||||||
|
initContainers:
|
||||||
|
- image: nginx:v2
|
||||||
|
name: nginx-notag
|
||||||
|
- image: nginx:v2
|
||||||
|
name: nginx-sha256
|
||||||
|
- image: alpine:1.8.0
|
||||||
|
name: init-alpine
|
||||||
|
`,
|
||||||
|
filter: Filter{
|
||||||
|
ImageTag: types.Image{
|
||||||
|
Name: "nginx",
|
||||||
|
NewTag: "v2",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fsSlice: []types.FieldSpec{
|
||||||
|
{
|
||||||
|
Path: "spec/template/spec/containers[]/image",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Path: "spec/template/spec/initContainers[]/image",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"newImage": {
|
||||||
|
input: `
|
||||||
|
group: apps
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: deploy1
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: nginx:1.7.9
|
||||||
|
name: nginx-tagged
|
||||||
|
- image: nginx:latest
|
||||||
|
name: nginx-latest
|
||||||
|
- image: foobar:1
|
||||||
|
name: replaced-with-digest
|
||||||
|
- image: postgres:1.8.0
|
||||||
|
name: postgresdb
|
||||||
|
initContainers:
|
||||||
|
- image: nginx
|
||||||
|
name: nginx-notag
|
||||||
|
- image: nginx@sha256:111111111111111111
|
||||||
|
name: nginx-sha256
|
||||||
|
- image: alpine:1.8.0
|
||||||
|
name: init-alpine
|
||||||
|
`,
|
||||||
|
expectedOutput: `
|
||||||
|
group: apps
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: deploy1
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: busybox:1.7.9
|
||||||
|
name: nginx-tagged
|
||||||
|
- image: busybox:latest
|
||||||
|
name: nginx-latest
|
||||||
|
- image: foobar:1
|
||||||
|
name: replaced-with-digest
|
||||||
|
- image: postgres:1.8.0
|
||||||
|
name: postgresdb
|
||||||
|
initContainers:
|
||||||
|
- image: busybox
|
||||||
|
name: nginx-notag
|
||||||
|
- image: busybox@sha256:111111111111111111
|
||||||
|
name: nginx-sha256
|
||||||
|
- image: alpine:1.8.0
|
||||||
|
name: init-alpine
|
||||||
|
`,
|
||||||
|
filter: Filter{
|
||||||
|
ImageTag: types.Image{
|
||||||
|
Name: "nginx",
|
||||||
|
NewName: "busybox",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fsSlice: []types.FieldSpec{
|
||||||
|
{
|
||||||
|
Path: "spec/template/spec/containers[]/image",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Path: "spec/template/spec/initContainers[]/image",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"newImageAndTag": {
|
||||||
|
input: `
|
||||||
|
group: apps
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: deploy1
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: nginx:1.7.9
|
||||||
|
name: nginx-tagged
|
||||||
|
- image: nginx:latest
|
||||||
|
name: nginx-latest
|
||||||
|
- image: foobar:1
|
||||||
|
name: replaced-with-digest
|
||||||
|
- image: postgres:1.8.0
|
||||||
|
name: postgresdb
|
||||||
|
initContainers:
|
||||||
|
- image: nginx
|
||||||
|
name: nginx-notag
|
||||||
|
- image: nginx@sha256:111111111111111111
|
||||||
|
name: nginx-sha256
|
||||||
|
- image: alpine:1.8.0
|
||||||
|
name: init-alpine
|
||||||
|
`,
|
||||||
|
expectedOutput: `
|
||||||
|
group: apps
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: deploy1
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: busybox:v3
|
||||||
|
name: nginx-tagged
|
||||||
|
- image: busybox:v3
|
||||||
|
name: nginx-latest
|
||||||
|
- image: foobar:1
|
||||||
|
name: replaced-with-digest
|
||||||
|
- image: postgres:1.8.0
|
||||||
|
name: postgresdb
|
||||||
|
initContainers:
|
||||||
|
- image: busybox:v3
|
||||||
|
name: nginx-notag
|
||||||
|
- image: busybox:v3
|
||||||
|
name: nginx-sha256
|
||||||
|
- image: alpine:1.8.0
|
||||||
|
name: init-alpine
|
||||||
|
`,
|
||||||
|
filter: Filter{
|
||||||
|
ImageTag: types.Image{
|
||||||
|
Name: "nginx",
|
||||||
|
NewName: "busybox",
|
||||||
|
NewTag: "v3",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fsSlice: []types.FieldSpec{
|
||||||
|
{
|
||||||
|
Path: "spec/template/spec/containers[]/image",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Path: "spec/template/spec/initContainers[]/image",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"newDigest": {
|
||||||
|
input: `
|
||||||
|
group: apps
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: deploy1
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: nginx:1.7.9
|
||||||
|
name: nginx-tagged
|
||||||
|
- image: nginx:latest
|
||||||
|
name: nginx-latest
|
||||||
|
- image: foobar:1
|
||||||
|
name: replaced-with-digest
|
||||||
|
- image: postgres:1.8.0
|
||||||
|
name: postgresdb
|
||||||
|
initContainers:
|
||||||
|
- image: nginx
|
||||||
|
name: nginx-notag
|
||||||
|
- image: nginx@sha256:111111111111111111
|
||||||
|
name: nginx-sha256
|
||||||
|
- image: alpine:1.8.0
|
||||||
|
name: init-alpine
|
||||||
|
`,
|
||||||
|
expectedOutput: `
|
||||||
|
group: apps
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: deploy1
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: nginx@sha256:222222222222222222
|
||||||
|
name: nginx-tagged
|
||||||
|
- image: nginx@sha256:222222222222222222
|
||||||
|
name: nginx-latest
|
||||||
|
- image: foobar:1
|
||||||
|
name: replaced-with-digest
|
||||||
|
- image: postgres:1.8.0
|
||||||
|
name: postgresdb
|
||||||
|
initContainers:
|
||||||
|
- image: nginx@sha256:222222222222222222
|
||||||
|
name: nginx-notag
|
||||||
|
- image: nginx@sha256:222222222222222222
|
||||||
|
name: nginx-sha256
|
||||||
|
- image: alpine:1.8.0
|
||||||
|
name: init-alpine
|
||||||
|
`,
|
||||||
|
filter: Filter{
|
||||||
|
ImageTag: types.Image{
|
||||||
|
Name: "nginx",
|
||||||
|
Digest: "sha256:222222222222222222",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fsSlice: []types.FieldSpec{
|
||||||
|
{
|
||||||
|
Path: "spec/template/spec/containers/image",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Path: "spec/template/spec/initContainers/image",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"newImageAndDigest": {
|
||||||
|
input: `
|
||||||
|
group: apps
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: deploy1
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: nginx:1.7.9
|
||||||
|
name: nginx-tagged
|
||||||
|
- image: nginx:latest
|
||||||
|
name: nginx-latest
|
||||||
|
- image: foobar:1
|
||||||
|
name: replaced-with-digest
|
||||||
|
- image: postgres:1.8.0
|
||||||
|
name: postgresdb
|
||||||
|
initContainers:
|
||||||
|
- image: nginx
|
||||||
|
name: nginx-notag
|
||||||
|
- image: nginx@sha256:111111111111111111
|
||||||
|
name: nginx-sha256
|
||||||
|
- image: alpine:1.8.0
|
||||||
|
name: init-alpine
|
||||||
|
`,
|
||||||
|
expectedOutput: `
|
||||||
|
group: apps
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: deploy1
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: busybox@sha256:222222222222222222
|
||||||
|
name: nginx-tagged
|
||||||
|
- image: busybox@sha256:222222222222222222
|
||||||
|
name: nginx-latest
|
||||||
|
- image: foobar:1
|
||||||
|
name: replaced-with-digest
|
||||||
|
- image: postgres:1.8.0
|
||||||
|
name: postgresdb
|
||||||
|
initContainers:
|
||||||
|
- image: busybox@sha256:222222222222222222
|
||||||
|
name: nginx-notag
|
||||||
|
- image: busybox@sha256:222222222222222222
|
||||||
|
name: nginx-sha256
|
||||||
|
- image: alpine:1.8.0
|
||||||
|
name: init-alpine
|
||||||
|
`,
|
||||||
|
filter: Filter{
|
||||||
|
ImageTag: types.Image{
|
||||||
|
Name: "nginx",
|
||||||
|
NewName: "busybox",
|
||||||
|
Digest: "sha256:222222222222222222",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fsSlice: []types.FieldSpec{
|
||||||
|
{
|
||||||
|
Path: "spec/template/spec/containers[]/image",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Path: "spec/template/spec/initContainers[]/image",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"emptyContainers": {
|
||||||
|
input: `
|
||||||
|
group: apps
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: deploy1
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
`,
|
||||||
|
expectedOutput: `
|
||||||
|
group: apps
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: deploy1
|
||||||
|
spec:
|
||||||
|
containers: []
|
||||||
|
`,
|
||||||
|
filter: Filter{
|
||||||
|
ImageTag: types.Image{
|
||||||
|
Name: "nginx",
|
||||||
|
NewTag: "v2",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fsSlice: []types.FieldSpec{
|
||||||
|
{
|
||||||
|
Path: "spec/containers[]/image",
|
||||||
|
// CreateIfNotPresent: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"tagWithBraces": {
|
||||||
|
input: `
|
||||||
|
group: apps
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: deploy1
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: some.registry.io/my-image:{GENERATED_TAG}
|
||||||
|
name: my-image
|
||||||
|
`,
|
||||||
|
expectedOutput: `
|
||||||
|
group: apps
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: deploy1
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: some.registry.io/my-image:my-fixed-tag
|
||||||
|
name: my-image
|
||||||
|
`,
|
||||||
|
filter: Filter{
|
||||||
|
ImageTag: types.Image{
|
||||||
|
Name: "some.registry.io/my-image",
|
||||||
|
NewTag: "my-fixed-tag",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fsSlice: []types.FieldSpec{
|
||||||
|
{
|
||||||
|
Path: "spec/template/spec/containers[]/image",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Path: "spec/template/spec/initContainers[]/image",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for tn, tc := range testCases {
|
for tn, tc := range testCases {
|
||||||
|
|||||||
@@ -30,10 +30,11 @@ func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
|
|||||||
func(node *yaml.RNode) (*yaml.RNode, error) {
|
func(node *yaml.RNode) (*yaml.RNode, error) {
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
if err := node.PipeE(fsslice.Filter{
|
if err := node.PipeE(fsslice.Filter{
|
||||||
FsSlice: f.FsSlice,
|
FsSlice: f.FsSlice,
|
||||||
SetValue: fsslice.SetEntry(k, f.Labels[k], yaml.StringTag),
|
SetValue: filtersutil.SetEntry(
|
||||||
|
k, f.Labels[k], yaml.NodeTagString),
|
||||||
CreateKind: yaml.MappingNode, // Labels are MappingNodes.
|
CreateKind: yaml.MappingNode, // Labels are MappingNodes.
|
||||||
CreateTag: "!!map",
|
CreateTag: yaml.NodeTagMap,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
3
api/filters/nameref/doc.go
Normal file
3
api/filters/nameref/doc.go
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
// Package nameref contains a kio.Filter implementation of the kustomize
|
||||||
|
// name reference transformer.
|
||||||
|
package nameref
|
||||||
241
api/filters/nameref/nameref.go
Normal file
241
api/filters/nameref/nameref.go
Normal file
@@ -0,0 +1,241 @@
|
|||||||
|
package nameref
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"sigs.k8s.io/kustomize/api/filters/fieldspec"
|
||||||
|
"sigs.k8s.io/kustomize/api/filters/filtersutil"
|
||||||
|
"sigs.k8s.io/kustomize/api/resid"
|
||||||
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
|
"sigs.k8s.io/kustomize/api/resource"
|
||||||
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Filter will update the name reference
|
||||||
|
type Filter struct {
|
||||||
|
FieldSpec types.FieldSpec `json:"fieldSpec,omitempty" yaml:"fieldSpec,omitempty"`
|
||||||
|
Referrer *resource.Resource
|
||||||
|
Target resid.Gvk
|
||||||
|
ReferralCandidates resmap.ResMap
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
|
||||||
|
return kio.FilterAll(yaml.FilterFunc(f.run)).Filter(nodes)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f Filter) run(node *yaml.RNode) (*yaml.RNode, error) {
|
||||||
|
err := node.PipeE(fieldspec.Filter{
|
||||||
|
FieldSpec: f.FieldSpec,
|
||||||
|
SetValue: f.set,
|
||||||
|
})
|
||||||
|
return node, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f Filter) set(node *yaml.RNode) error {
|
||||||
|
if yaml.IsMissingOrNull(node) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
switch node.YNode().Kind {
|
||||||
|
case yaml.ScalarNode:
|
||||||
|
return f.setScalar(node)
|
||||||
|
case yaml.MappingNode:
|
||||||
|
// Kind: ValidatingWebhookConfiguration
|
||||||
|
// FieldSpec is webhooks/clientConfig/service
|
||||||
|
return f.setMapping(node)
|
||||||
|
case yaml.SequenceNode:
|
||||||
|
return f.setSequence(node)
|
||||||
|
default:
|
||||||
|
return fmt.Errorf(
|
||||||
|
"node is expected to be either a string or a slice of string or a map of string")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f Filter) setSequence(node *yaml.RNode) error {
|
||||||
|
return applyFilterToSeq(seqFilter{
|
||||||
|
setScalarFn: f.setScalar,
|
||||||
|
setMappingFn: f.setMapping,
|
||||||
|
}, node)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f Filter) setMapping(node *yaml.RNode) error {
|
||||||
|
return setNameAndNs(
|
||||||
|
node,
|
||||||
|
f.Referrer,
|
||||||
|
f.Target,
|
||||||
|
f.ReferralCandidates,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f Filter) setScalar(node *yaml.RNode) error {
|
||||||
|
newValue, err := getSimpleNameField(
|
||||||
|
node.YNode().Value,
|
||||||
|
f.Referrer,
|
||||||
|
f.Target,
|
||||||
|
f.ReferralCandidates,
|
||||||
|
f.ReferralCandidates.Resources(),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = filtersutil.SetScalar(newValue)(node)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func filterReferralCandidates(
|
||||||
|
referrer *resource.Resource,
|
||||||
|
matches []*resource.Resource,
|
||||||
|
target resid.Gvk,
|
||||||
|
) []*resource.Resource {
|
||||||
|
var ret []*resource.Resource
|
||||||
|
for _, m := range matches {
|
||||||
|
// If target kind is not ServiceAccount, we shouldn't consider condidates which
|
||||||
|
// doesn't have same namespace.
|
||||||
|
if target.Kind != "ServiceAccount" && m.GetNamespace() != referrer.GetNamespace() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !referrer.PrefixesSuffixesEquals(m) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ret = append(ret, m)
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
// selectReferral picks the referral among a subset of candidates.
|
||||||
|
// It returns the current name and namespace of the selected candidate.
|
||||||
|
// Note that the content of the referricalCandidateSubset slice is most of the time
|
||||||
|
// identical to the referralCandidates resmap. Still in some cases, such
|
||||||
|
// as ClusterRoleBinding, the subset only contains the resources of a specific
|
||||||
|
// namespace.
|
||||||
|
func selectReferral(
|
||||||
|
oldName string,
|
||||||
|
referrer *resource.Resource,
|
||||||
|
target resid.Gvk,
|
||||||
|
referralCandidates resmap.ResMap,
|
||||||
|
referralCandidateSubset []*resource.Resource) (string, string, error) {
|
||||||
|
|
||||||
|
for _, res := range referralCandidateSubset {
|
||||||
|
id := res.OrgId()
|
||||||
|
if id.IsSelected(&target) && res.GetOriginalName() == oldName {
|
||||||
|
matches := referralCandidates.GetMatchingResourcesByOriginalId(id.Equals)
|
||||||
|
// If there's more than one match,
|
||||||
|
// filter the matches by prefix and suffix
|
||||||
|
if len(matches) > 1 {
|
||||||
|
filteredMatches := filterReferralCandidates(referrer, matches, target)
|
||||||
|
if len(filteredMatches) > 1 {
|
||||||
|
return "", "", fmt.Errorf(
|
||||||
|
"multiple matches for %s:\n %v",
|
||||||
|
id, getIds(filteredMatches))
|
||||||
|
}
|
||||||
|
// Check is the match the resource we are working on
|
||||||
|
if len(filteredMatches) == 0 || res != filteredMatches[0] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// In the resource, note that it is referenced
|
||||||
|
// by the referrer.
|
||||||
|
res.AppendRefBy(referrer.CurId())
|
||||||
|
// Return transformed name of the object,
|
||||||
|
// complete with prefixes, hashes, etc.
|
||||||
|
return res.GetName(), res.GetNamespace(), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return oldName, "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// utility function to replace a simple string by the new name
|
||||||
|
func getSimpleNameField(
|
||||||
|
oldName string,
|
||||||
|
referrer *resource.Resource,
|
||||||
|
target resid.Gvk,
|
||||||
|
referralCandidates resmap.ResMap,
|
||||||
|
referralCandidateSubset []*resource.Resource) (string, error) {
|
||||||
|
|
||||||
|
newName, _, err := selectReferral(oldName, referrer, target,
|
||||||
|
referralCandidates, referralCandidateSubset)
|
||||||
|
|
||||||
|
return newName, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func getIds(rs []*resource.Resource) []string {
|
||||||
|
var result []string
|
||||||
|
for _, r := range rs {
|
||||||
|
result = append(result, r.CurId().String()+"\n")
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// utility function to replace name field within a map RNode
|
||||||
|
// and leverage the namespace field.
|
||||||
|
func setNameAndNs(
|
||||||
|
in *yaml.RNode,
|
||||||
|
referrer *resource.Resource,
|
||||||
|
target resid.Gvk,
|
||||||
|
referralCandidates resmap.ResMap) error {
|
||||||
|
|
||||||
|
if in.YNode().Kind != yaml.MappingNode {
|
||||||
|
return fmt.Errorf("expect a mapping node")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get name field
|
||||||
|
nameNode, err := in.Pipe(yaml.FieldMatcher{
|
||||||
|
Name: "name",
|
||||||
|
})
|
||||||
|
if err != nil || nameNode == nil {
|
||||||
|
return fmt.Errorf("cannot find field 'name' in node")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get namespace field
|
||||||
|
namespaceNode, err := in.Pipe(yaml.FieldMatcher{
|
||||||
|
Name: "namespace",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error when find field 'namespace'")
|
||||||
|
}
|
||||||
|
|
||||||
|
// check is namespace matched
|
||||||
|
// name will bot be updated if the namespace doesn't match
|
||||||
|
subset := referralCandidates.Resources()
|
||||||
|
if namespaceNode != nil {
|
||||||
|
namespace := namespaceNode.YNode().Value
|
||||||
|
bynamespace := referralCandidates.GroupedByOriginalNamespace()
|
||||||
|
if _, ok := bynamespace[namespace]; !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
subset = bynamespace[namespace]
|
||||||
|
}
|
||||||
|
|
||||||
|
oldName := nameNode.YNode().Value
|
||||||
|
newname, newnamespace, err := selectReferral(oldName, referrer, target,
|
||||||
|
referralCandidates, subset)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newname == oldName) && (newnamespace == "") {
|
||||||
|
// no candidate found.
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// set name
|
||||||
|
in.Pipe(yaml.FieldSetter{
|
||||||
|
Name: "name",
|
||||||
|
StringValue: newname,
|
||||||
|
})
|
||||||
|
if newnamespace != "" {
|
||||||
|
// We don't want value "" to replace value "default" since
|
||||||
|
// the empty string is handled as a wild card here not default namespace
|
||||||
|
// by kubernetes.
|
||||||
|
in.Pipe(yaml.FieldSetter{
|
||||||
|
Name: "namespace",
|
||||||
|
StringValue: newnamespace,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
781
api/filters/nameref/nameref_test.go
Normal file
781
api/filters/nameref/nameref_test.go
Normal file
@@ -0,0 +1,781 @@
|
|||||||
|
package nameref
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"sigs.k8s.io/kustomize/api/k8sdeps/kunstruct"
|
||||||
|
"sigs.k8s.io/kustomize/api/resid"
|
||||||
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
|
"sigs.k8s.io/kustomize/api/resource"
|
||||||
|
filtertest_test "sigs.k8s.io/kustomize/api/testutils/filtertest"
|
||||||
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNamerefFilter(t *testing.T) {
|
||||||
|
testCases := map[string]struct {
|
||||||
|
input string
|
||||||
|
candidates string
|
||||||
|
expected string
|
||||||
|
filter Filter
|
||||||
|
originalNames []string
|
||||||
|
}{
|
||||||
|
"simple scalar": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
ref:
|
||||||
|
name: oldName
|
||||||
|
`,
|
||||||
|
candidates: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: NotSecret
|
||||||
|
metadata:
|
||||||
|
name: newName2
|
||||||
|
`,
|
||||||
|
originalNames: []string{"oldName", ""},
|
||||||
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
ref:
|
||||||
|
name: newName
|
||||||
|
`,
|
||||||
|
filter: Filter{
|
||||||
|
FieldSpec: types.FieldSpec{Path: "ref/name"},
|
||||||
|
Target: resid.Gvk{
|
||||||
|
Group: "apps",
|
||||||
|
Version: "v1",
|
||||||
|
Kind: "Secret",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"sequence": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
seq:
|
||||||
|
- oldName1
|
||||||
|
- oldName2
|
||||||
|
`,
|
||||||
|
candidates: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: NotSecret
|
||||||
|
metadata:
|
||||||
|
name: newName2
|
||||||
|
`,
|
||||||
|
originalNames: []string{"oldName1", ""},
|
||||||
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
seq:
|
||||||
|
- newName
|
||||||
|
- oldName2
|
||||||
|
`,
|
||||||
|
filter: Filter{
|
||||||
|
FieldSpec: types.FieldSpec{Path: "seq"},
|
||||||
|
Target: resid.Gvk{
|
||||||
|
Group: "apps",
|
||||||
|
Version: "v1",
|
||||||
|
Kind: "Secret",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"mapping": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
map:
|
||||||
|
name: oldName
|
||||||
|
`,
|
||||||
|
candidates: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: NotSecret
|
||||||
|
metadata:
|
||||||
|
name: newName2
|
||||||
|
`,
|
||||||
|
originalNames: []string{"oldName", ""},
|
||||||
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
map:
|
||||||
|
name: newName
|
||||||
|
`,
|
||||||
|
filter: Filter{
|
||||||
|
FieldSpec: types.FieldSpec{Path: "map"},
|
||||||
|
Target: resid.Gvk{
|
||||||
|
Group: "apps",
|
||||||
|
Version: "v1",
|
||||||
|
Kind: "Secret",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"mapping with namespace": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
map:
|
||||||
|
name: oldName
|
||||||
|
namespace: oldNs
|
||||||
|
`,
|
||||||
|
candidates: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName
|
||||||
|
namespace: oldNs
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: NotSecret
|
||||||
|
metadata:
|
||||||
|
name: newName2
|
||||||
|
`,
|
||||||
|
originalNames: []string{"oldName", ""},
|
||||||
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
map:
|
||||||
|
name: newName
|
||||||
|
namespace: oldNs
|
||||||
|
`,
|
||||||
|
filter: Filter{
|
||||||
|
FieldSpec: types.FieldSpec{Path: "map"},
|
||||||
|
Target: resid.Gvk{
|
||||||
|
Group: "apps",
|
||||||
|
Version: "v1",
|
||||||
|
Kind: "Secret",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"null value": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
map:
|
||||||
|
name: null
|
||||||
|
`,
|
||||||
|
candidates: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: NotSecret
|
||||||
|
metadata:
|
||||||
|
name: newName2
|
||||||
|
`,
|
||||||
|
originalNames: []string{"oldName", ""},
|
||||||
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
map:
|
||||||
|
name: null
|
||||||
|
`,
|
||||||
|
filter: Filter{
|
||||||
|
FieldSpec: types.FieldSpec{Path: "map"},
|
||||||
|
Target: resid.Gvk{
|
||||||
|
Group: "apps",
|
||||||
|
Version: "v1",
|
||||||
|
Kind: "Secret",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for tn, tc := range testCases {
|
||||||
|
t.Run(tn, func(t *testing.T) {
|
||||||
|
factory := resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())
|
||||||
|
referrer, err := factory.FromBytes([]byte(tc.input))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
tc.filter.Referrer = referrer
|
||||||
|
|
||||||
|
resMapFactory := resmap.NewFactory(factory, nil)
|
||||||
|
candidatesRes, err := factory.SliceFromBytesWithNames(
|
||||||
|
tc.originalNames, []byte(tc.candidates))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
candidates := resMapFactory.FromResourceSlice(candidatesRes)
|
||||||
|
tc.filter.ReferralCandidates = candidates
|
||||||
|
|
||||||
|
if !assert.Equal(t,
|
||||||
|
strings.TrimSpace(tc.expected),
|
||||||
|
strings.TrimSpace(
|
||||||
|
filtertest_test.RunFilter(t, tc.input, tc.filter))) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNamerefFilterUnhappy(t *testing.T) {
|
||||||
|
testCases := map[string]struct {
|
||||||
|
input string
|
||||||
|
candidates string
|
||||||
|
expected string
|
||||||
|
filter Filter
|
||||||
|
originalNames []string
|
||||||
|
}{
|
||||||
|
"multiple match": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
ref:
|
||||||
|
name: oldName
|
||||||
|
`,
|
||||||
|
candidates: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName2
|
||||||
|
`,
|
||||||
|
originalNames: []string{"oldName", "oldName"},
|
||||||
|
expected: "",
|
||||||
|
filter: Filter{
|
||||||
|
FieldSpec: types.FieldSpec{Path: "ref/name"},
|
||||||
|
Target: resid.Gvk{
|
||||||
|
Group: "apps",
|
||||||
|
Version: "v1",
|
||||||
|
Kind: "Secret",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"no name": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
ref:
|
||||||
|
notName: oldName
|
||||||
|
`,
|
||||||
|
candidates: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName2
|
||||||
|
`,
|
||||||
|
originalNames: []string{"oldName", "oldName"},
|
||||||
|
expected: "",
|
||||||
|
filter: Filter{
|
||||||
|
FieldSpec: types.FieldSpec{Path: "ref"},
|
||||||
|
Target: resid.Gvk{
|
||||||
|
Group: "apps",
|
||||||
|
Version: "v1",
|
||||||
|
Kind: "Secret",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for tn, tc := range testCases {
|
||||||
|
t.Run(tn, func(t *testing.T) {
|
||||||
|
factory := resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())
|
||||||
|
referrer, err := factory.FromBytes([]byte(tc.input))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
tc.filter.Referrer = referrer
|
||||||
|
|
||||||
|
resMapFactory := resmap.NewFactory(factory, nil)
|
||||||
|
candidatesRes, err := factory.SliceFromBytesWithNames(
|
||||||
|
tc.originalNames, []byte(tc.candidates))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
candidates := resMapFactory.FromResourceSlice(candidatesRes)
|
||||||
|
tc.filter.ReferralCandidates = candidates
|
||||||
|
|
||||||
|
_, err = filtertest_test.RunFilterE(t, tc.input, tc.filter)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("expect an error")
|
||||||
|
}
|
||||||
|
if tc.expected != "" && !assert.EqualError(t, err, tc.expected) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCandidatesWithDifferentPrefixSuffix(t *testing.T) {
|
||||||
|
testCases := map[string]struct {
|
||||||
|
input string
|
||||||
|
candidates string
|
||||||
|
expected string
|
||||||
|
filter Filter
|
||||||
|
originalNames []string
|
||||||
|
prefix []string
|
||||||
|
suffix []string
|
||||||
|
inputPrefix string
|
||||||
|
inputSuffix string
|
||||||
|
err bool
|
||||||
|
}{
|
||||||
|
"prefix match": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
ref:
|
||||||
|
name: oldName
|
||||||
|
`,
|
||||||
|
candidates: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName2
|
||||||
|
`,
|
||||||
|
originalNames: []string{"oldName", "oldName"},
|
||||||
|
prefix: []string{"prefix1", "prefix2"},
|
||||||
|
suffix: []string{"", "suffix2"},
|
||||||
|
inputPrefix: "prefix1",
|
||||||
|
inputSuffix: "",
|
||||||
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
ref:
|
||||||
|
name: newName
|
||||||
|
`,
|
||||||
|
filter: Filter{
|
||||||
|
FieldSpec: types.FieldSpec{Path: "ref/name"},
|
||||||
|
Target: resid.Gvk{
|
||||||
|
Group: "apps",
|
||||||
|
Version: "v1",
|
||||||
|
Kind: "Secret",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
err: false,
|
||||||
|
},
|
||||||
|
"suffix match": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
ref:
|
||||||
|
name: oldName
|
||||||
|
`,
|
||||||
|
candidates: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName2
|
||||||
|
`,
|
||||||
|
originalNames: []string{"oldName", "oldName"},
|
||||||
|
prefix: []string{"", "prefix2"},
|
||||||
|
suffix: []string{"suffix1", "suffix2"},
|
||||||
|
inputPrefix: "",
|
||||||
|
inputSuffix: "suffix1",
|
||||||
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
ref:
|
||||||
|
name: newName
|
||||||
|
`,
|
||||||
|
filter: Filter{
|
||||||
|
FieldSpec: types.FieldSpec{Path: "ref/name"},
|
||||||
|
Target: resid.Gvk{
|
||||||
|
Group: "apps",
|
||||||
|
Version: "v1",
|
||||||
|
Kind: "Secret",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
err: false,
|
||||||
|
},
|
||||||
|
"prefix suffix both match": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
ref:
|
||||||
|
name: oldName
|
||||||
|
`,
|
||||||
|
candidates: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName2
|
||||||
|
`,
|
||||||
|
originalNames: []string{"oldName", "oldName"},
|
||||||
|
prefix: []string{"prefix1", "prefix2"},
|
||||||
|
suffix: []string{"suffix1", "suffix2"},
|
||||||
|
inputPrefix: "prefix1",
|
||||||
|
inputSuffix: "suffix1",
|
||||||
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
ref:
|
||||||
|
name: newName
|
||||||
|
`,
|
||||||
|
filter: Filter{
|
||||||
|
FieldSpec: types.FieldSpec{Path: "ref/name"},
|
||||||
|
Target: resid.Gvk{
|
||||||
|
Group: "apps",
|
||||||
|
Version: "v1",
|
||||||
|
Kind: "Secret",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
err: false,
|
||||||
|
},
|
||||||
|
"multiple match: both": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
ref:
|
||||||
|
name: oldName
|
||||||
|
`,
|
||||||
|
candidates: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName2
|
||||||
|
`,
|
||||||
|
originalNames: []string{"oldName", "oldName"},
|
||||||
|
prefix: []string{"prefix", "prefix"},
|
||||||
|
suffix: []string{"suffix", "suffix"},
|
||||||
|
inputPrefix: "prefix",
|
||||||
|
inputSuffix: "suffix",
|
||||||
|
expected: "",
|
||||||
|
filter: Filter{
|
||||||
|
FieldSpec: types.FieldSpec{Path: "ref/name"},
|
||||||
|
Target: resid.Gvk{
|
||||||
|
Group: "apps",
|
||||||
|
Version: "v1",
|
||||||
|
Kind: "Secret",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
err: true,
|
||||||
|
},
|
||||||
|
"multiple match: only prefix": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
ref:
|
||||||
|
name: oldName
|
||||||
|
`,
|
||||||
|
candidates: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName2
|
||||||
|
`,
|
||||||
|
originalNames: []string{"oldName", "oldName"},
|
||||||
|
prefix: []string{"prefix", "prefix"},
|
||||||
|
suffix: []string{"", ""},
|
||||||
|
inputPrefix: "prefix",
|
||||||
|
inputSuffix: "",
|
||||||
|
expected: "",
|
||||||
|
filter: Filter{
|
||||||
|
FieldSpec: types.FieldSpec{Path: "ref/name"},
|
||||||
|
Target: resid.Gvk{
|
||||||
|
Group: "apps",
|
||||||
|
Version: "v1",
|
||||||
|
Kind: "Secret",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
err: true,
|
||||||
|
},
|
||||||
|
"multiple match: only suffix": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
ref:
|
||||||
|
name: oldName
|
||||||
|
`,
|
||||||
|
candidates: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName2
|
||||||
|
`,
|
||||||
|
originalNames: []string{"oldName", "oldName"},
|
||||||
|
prefix: []string{"", ""},
|
||||||
|
suffix: []string{"suffix", "suffix"},
|
||||||
|
inputPrefix: "",
|
||||||
|
inputSuffix: "suffix",
|
||||||
|
expected: "",
|
||||||
|
filter: Filter{
|
||||||
|
FieldSpec: types.FieldSpec{Path: "ref/name"},
|
||||||
|
Target: resid.Gvk{
|
||||||
|
Group: "apps",
|
||||||
|
Version: "v1",
|
||||||
|
Kind: "Secret",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
err: true,
|
||||||
|
},
|
||||||
|
"no match: neither match": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
ref:
|
||||||
|
name: oldName
|
||||||
|
`,
|
||||||
|
candidates: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName2
|
||||||
|
`,
|
||||||
|
originalNames: []string{"oldName", "oldName"},
|
||||||
|
prefix: []string{"prefix1", "prefix2"},
|
||||||
|
suffix: []string{"suffix1", "suffix2"},
|
||||||
|
inputPrefix: "prefix",
|
||||||
|
inputSuffix: "suffix",
|
||||||
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
ref:
|
||||||
|
name: oldName
|
||||||
|
`,
|
||||||
|
filter: Filter{
|
||||||
|
FieldSpec: types.FieldSpec{Path: "ref/name"},
|
||||||
|
Target: resid.Gvk{
|
||||||
|
Group: "apps",
|
||||||
|
Version: "v1",
|
||||||
|
Kind: "Secret",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
err: false,
|
||||||
|
},
|
||||||
|
"no match: prefix doesn't match": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
ref:
|
||||||
|
name: oldName
|
||||||
|
`,
|
||||||
|
candidates: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName2
|
||||||
|
`,
|
||||||
|
originalNames: []string{"oldName", "oldName"},
|
||||||
|
prefix: []string{"prefix1", "prefix2"},
|
||||||
|
suffix: []string{"suffix", "suffix"},
|
||||||
|
inputPrefix: "prefix",
|
||||||
|
inputSuffix: "suffix",
|
||||||
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
ref:
|
||||||
|
name: oldName
|
||||||
|
`,
|
||||||
|
filter: Filter{
|
||||||
|
FieldSpec: types.FieldSpec{Path: "ref/name"},
|
||||||
|
Target: resid.Gvk{
|
||||||
|
Group: "apps",
|
||||||
|
Version: "v1",
|
||||||
|
Kind: "Secret",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
err: false,
|
||||||
|
},
|
||||||
|
"no match: suffix doesn't match": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
ref:
|
||||||
|
name: oldName
|
||||||
|
`,
|
||||||
|
candidates: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName2
|
||||||
|
`,
|
||||||
|
originalNames: []string{"oldName", "oldName"},
|
||||||
|
prefix: []string{"prefix", "prefix"},
|
||||||
|
suffix: []string{"suffix1", "suffix2"},
|
||||||
|
inputPrefix: "prefix",
|
||||||
|
inputSuffix: "suffix",
|
||||||
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
ref:
|
||||||
|
name: oldName
|
||||||
|
`,
|
||||||
|
filter: Filter{
|
||||||
|
FieldSpec: types.FieldSpec{Path: "ref/name"},
|
||||||
|
Target: resid.Gvk{
|
||||||
|
Group: "apps",
|
||||||
|
Version: "v1",
|
||||||
|
Kind: "Secret",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
err: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for tn, tc := range testCases {
|
||||||
|
t.Run(tn, func(t *testing.T) {
|
||||||
|
factory := resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())
|
||||||
|
referrer, err := factory.FromBytes([]byte(tc.input))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if tc.inputPrefix != "" {
|
||||||
|
referrer.AddNamePrefix(tc.inputPrefix)
|
||||||
|
}
|
||||||
|
if tc.inputSuffix != "" {
|
||||||
|
referrer.AddNameSuffix(tc.inputSuffix)
|
||||||
|
}
|
||||||
|
tc.filter.Referrer = referrer
|
||||||
|
|
||||||
|
resMapFactory := resmap.NewFactory(factory, nil)
|
||||||
|
candidatesRes, err := factory.SliceFromBytesWithNames(
|
||||||
|
tc.originalNames, []byte(tc.candidates))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for i := range candidatesRes {
|
||||||
|
if tc.prefix[i] != "" {
|
||||||
|
candidatesRes[i].AddNamePrefix(tc.prefix[i])
|
||||||
|
}
|
||||||
|
if tc.suffix[i] != "" {
|
||||||
|
candidatesRes[i].AddNameSuffix(tc.suffix[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
candidates := resMapFactory.FromResourceSlice(candidatesRes)
|
||||||
|
tc.filter.ReferralCandidates = candidates
|
||||||
|
|
||||||
|
if !tc.err {
|
||||||
|
if !assert.Equal(t,
|
||||||
|
strings.TrimSpace(tc.expected),
|
||||||
|
strings.TrimSpace(
|
||||||
|
filtertest_test.RunFilter(t, tc.input, tc.filter))) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_, err := filtertest_test.RunFilterE(t, tc.input, tc.filter)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("an error is expected")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
57
api/filters/nameref/seqfilter.go
Normal file
57
api/filters/nameref/seqfilter.go
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
package nameref
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
|
)
|
||||||
|
|
||||||
|
type setFn func(*yaml.RNode) error
|
||||||
|
|
||||||
|
type seqFilter struct {
|
||||||
|
setScalarFn setFn
|
||||||
|
setMappingFn setFn
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sf seqFilter) Filter(node *yaml.RNode) (*yaml.RNode, error) {
|
||||||
|
if yaml.IsMissingOrNull(node) {
|
||||||
|
return node, nil
|
||||||
|
}
|
||||||
|
switch node.YNode().Kind {
|
||||||
|
case yaml.ScalarNode:
|
||||||
|
// Kind: Role/ClusterRole
|
||||||
|
// FieldSpec is rules.resourceNames
|
||||||
|
err := sf.setScalarFn(node)
|
||||||
|
return node, err
|
||||||
|
case yaml.MappingNode:
|
||||||
|
// Kind: RoleBinding/ClusterRoleBinding
|
||||||
|
// FieldSpec is subjects
|
||||||
|
// Note: The corresponding fieldSpec had been changed from
|
||||||
|
// from path: subjects/name to just path: subjects. This is
|
||||||
|
// what get mutatefield to request the mapping of the whole
|
||||||
|
// map containing namespace and name instead of just a simple
|
||||||
|
// string field containing the name
|
||||||
|
err := sf.setMappingFn(node)
|
||||||
|
return node, err
|
||||||
|
default:
|
||||||
|
return node, fmt.Errorf(
|
||||||
|
"%#v is expected to be either a string or a map of string", node)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// applyFilterToSeq will apply the filter to each element in the sequence node
|
||||||
|
func applyFilterToSeq(filter yaml.Filter, node *yaml.RNode) error {
|
||||||
|
if node.YNode().Kind != yaml.SequenceNode {
|
||||||
|
return fmt.Errorf("expect a sequence node but got %v", node.YNode().Kind)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, elem := range node.Content() {
|
||||||
|
rnode := yaml.NewRNode(elem)
|
||||||
|
err := rnode.PipeE(filter)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
80
api/filters/nameref/seqfilter_test.go
Normal file
80
api/filters/nameref/seqfilter_test.go
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
package nameref
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SeqFilter(node *yaml.RNode) (*yaml.RNode, error) {
|
||||||
|
if node.YNode().Value == "aaa" {
|
||||||
|
node.YNode().SetString("ccc")
|
||||||
|
}
|
||||||
|
return node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestApplyFilterToSeq(t *testing.T) {
|
||||||
|
fltr := yaml.FilterFunc(SeqFilter)
|
||||||
|
|
||||||
|
testCases := map[string]struct {
|
||||||
|
input string
|
||||||
|
expect string
|
||||||
|
}{
|
||||||
|
"replace in seq": {
|
||||||
|
input: `
|
||||||
|
- aaa
|
||||||
|
- bbb`,
|
||||||
|
expect: `
|
||||||
|
- ccc
|
||||||
|
- bbb`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for tn, tc := range testCases {
|
||||||
|
t.Run(tn, func(t *testing.T) {
|
||||||
|
node, err := yaml.Parse(tc.input)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
err = applyFilterToSeq(fltr, node)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if !assert.Equal(t,
|
||||||
|
strings.TrimSpace(tc.expect),
|
||||||
|
strings.TrimSpace(node.MustString())) {
|
||||||
|
t.Fatalf("expect:\n%s\nactual:\n%s",
|
||||||
|
strings.TrimSpace(tc.expect),
|
||||||
|
strings.TrimSpace(node.MustString()))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestApplyFilterToSeqUnhappy(t *testing.T) {
|
||||||
|
fltr := yaml.FilterFunc(SeqFilter)
|
||||||
|
|
||||||
|
testCases := map[string]struct {
|
||||||
|
input string
|
||||||
|
}{
|
||||||
|
"replace in seq": {
|
||||||
|
input: `
|
||||||
|
aaa`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for tn, tc := range testCases {
|
||||||
|
t.Run(tn, func(t *testing.T) {
|
||||||
|
node, err := yaml.Parse(tc.input)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
err = applyFilterToSeq(fltr, node)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("expect an error")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,8 @@
|
|||||||
package namespace
|
package namespace
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sigs.k8s.io/kustomize/api/filters/fieldspec"
|
||||||
|
"sigs.k8s.io/kustomize/api/filters/filtersutil"
|
||||||
"sigs.k8s.io/kustomize/api/filters/fsslice"
|
"sigs.k8s.io/kustomize/api/filters/fsslice"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
"sigs.k8s.io/kustomize/kyaml/kio"
|
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||||
@@ -42,9 +44,9 @@ func (ns Filter) run(node *yaml.RNode) (*yaml.RNode, error) {
|
|||||||
// transformations based on data -- :)
|
// transformations based on data -- :)
|
||||||
err := node.PipeE(fsslice.Filter{
|
err := node.PipeE(fsslice.Filter{
|
||||||
FsSlice: ns.FsSlice,
|
FsSlice: ns.FsSlice,
|
||||||
SetValue: fsslice.SetScalar(ns.Namespace),
|
SetValue: filtersutil.SetScalar(ns.Namespace),
|
||||||
CreateKind: yaml.ScalarNode, // Namespace is a ScalarNode
|
CreateKind: yaml.ScalarNode, // Namespace is a ScalarNode
|
||||||
CreateTag: yaml.StringTag,
|
CreateTag: yaml.NodeTagString,
|
||||||
})
|
})
|
||||||
return node, err
|
return node, err
|
||||||
}
|
}
|
||||||
@@ -67,13 +69,13 @@ func (ns Filter) hacks(obj *yaml.RNode) error {
|
|||||||
// metaNamespaceHack is a hack for implementing the namespace transform
|
// metaNamespaceHack is a hack for implementing the namespace transform
|
||||||
// for the metadata.namespace field on namespace scoped resources.
|
// for the metadata.namespace field on namespace scoped resources.
|
||||||
// namespace scoped resources are determined by NOT being present
|
// namespace scoped resources are determined by NOT being present
|
||||||
// in a blacklist of cluster-scoped resource types (by apiVersion and kind).
|
// in a hard-coded list of cluster-scoped resource types (by apiVersion and kind).
|
||||||
//
|
//
|
||||||
// This hack should be updated to allow individual resources to specify
|
// This hack should be updated to allow individual resources to specify
|
||||||
// if they are cluster scoped through either an annotation on the resources,
|
// if they are cluster scoped through either an annotation on the resources,
|
||||||
// or through inlined OpenAPI on the resource as a YAML comment.
|
// or through inlined OpenAPI on the resource as a YAML comment.
|
||||||
func (ns Filter) metaNamespaceHack(obj *yaml.RNode, meta yaml.ResourceMeta) error {
|
func (ns Filter) metaNamespaceHack(obj *yaml.RNode, meta yaml.ResourceMeta) error {
|
||||||
gvk := fsslice.GetGVK(meta)
|
gvk := fieldspec.GetGVK(meta)
|
||||||
if !gvk.IsNamespaceableKind() {
|
if !gvk.IsNamespaceableKind() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -81,7 +83,7 @@ func (ns Filter) metaNamespaceHack(obj *yaml.RNode, meta yaml.ResourceMeta) erro
|
|||||||
FsSlice: []types.FieldSpec{
|
FsSlice: []types.FieldSpec{
|
||||||
{Path: types.MetadataNamespacePath, CreateIfNotPresent: true},
|
{Path: types.MetadataNamespacePath, CreateIfNotPresent: true},
|
||||||
},
|
},
|
||||||
SetValue: fsslice.SetScalar(ns.Namespace),
|
SetValue: filtersutil.SetScalar(ns.Namespace),
|
||||||
CreateKind: yaml.ScalarNode, // Namespace is a ScalarNode
|
CreateKind: yaml.ScalarNode, // Namespace is a ScalarNode
|
||||||
}
|
}
|
||||||
_, err := f.Filter(obj)
|
_, err := f.Filter(obj)
|
||||||
@@ -110,7 +112,7 @@ func (ns Filter) roleBindingHack(obj *yaml.RNode, meta yaml.ResourceMeta) error
|
|||||||
// Lookup the namespace field on all elements.
|
// Lookup the namespace field on all elements.
|
||||||
// We should change the fieldspec so this isn't necessary.
|
// We should change the fieldspec so this isn't necessary.
|
||||||
obj, err := obj.Pipe(yaml.Lookup(subjectsField))
|
obj, err := obj.Pipe(yaml.Lookup(subjectsField))
|
||||||
if err != nil || yaml.IsEmpty(obj) {
|
if err != nil || yaml.IsMissingOrNull(obj) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +125,7 @@ func (ns Filter) roleBindingHack(obj *yaml.RNode, meta yaml.ResourceMeta) error
|
|||||||
name, err := o.Pipe(
|
name, err := o.Pipe(
|
||||||
yaml.Lookup("name"), yaml.Match("default"),
|
yaml.Lookup("name"), yaml.Match("default"),
|
||||||
)
|
)
|
||||||
if err != nil || yaml.IsEmpty(name) {
|
if err != nil || yaml.IsMissingOrNull(name) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
package patchstrategicmerge
|
package patchstrategicmerge
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -13,9 +16,18 @@ type Filter struct {
|
|||||||
var _ kio.Filter = Filter{}
|
var _ kio.Filter = Filter{}
|
||||||
|
|
||||||
func (pf Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
|
func (pf Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
|
||||||
return kio.FilterAll(yaml.FilterFunc(pf.run)).Filter(nodes)
|
var result []*yaml.RNode
|
||||||
}
|
for i := range nodes {
|
||||||
|
r, err := merge2.Merge(
|
||||||
func (pf Filter) run(node *yaml.RNode) (*yaml.RNode, error) {
|
pf.Patch, nodes[i],
|
||||||
return merge2.Merge(pf.Patch, node)
|
yaml.MergeOptions{
|
||||||
|
ListIncreaseDirection: yaml.MergeOptionsListPrepend,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result = append(result, r)
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,86 @@ apiVersion: apps/v1
|
|||||||
metadata:
|
metadata:
|
||||||
name: yourDeploy
|
name: yourDeploy
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
"container patch": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
metadata:
|
||||||
|
name: myDeploy
|
||||||
|
kind: Deployment
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: foo1
|
||||||
|
- name: foo2
|
||||||
|
- name: foo3
|
||||||
|
`,
|
||||||
|
patch: yaml.MustParse(`
|
||||||
|
apiVersion: apps/v1
|
||||||
|
metadata:
|
||||||
|
name: myDeploy
|
||||||
|
kind: Deployment
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: foo0
|
||||||
|
`),
|
||||||
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
metadata:
|
||||||
|
name: myDeploy
|
||||||
|
kind: Deployment
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: foo0
|
||||||
|
- name: foo1
|
||||||
|
- name: foo2
|
||||||
|
- name: foo3
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
"volumes patch": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
metadata:
|
||||||
|
name: myDeploy
|
||||||
|
kind: Deployment
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
volumes:
|
||||||
|
- name: foo1
|
||||||
|
- name: foo2
|
||||||
|
- name: foo3
|
||||||
|
`,
|
||||||
|
patch: yaml.MustParse(`
|
||||||
|
apiVersion: apps/v1
|
||||||
|
metadata:
|
||||||
|
name: myDeploy
|
||||||
|
kind: Deployment
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
volumes:
|
||||||
|
- name: foo0
|
||||||
|
`),
|
||||||
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
metadata:
|
||||||
|
name: myDeploy
|
||||||
|
kind: Deployment
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
volumes:
|
||||||
|
- name: foo0
|
||||||
|
- name: foo1
|
||||||
|
- name: foo2
|
||||||
|
- name: foo3
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
"nested patch": {
|
"nested patch": {
|
||||||
@@ -62,6 +142,234 @@ spec:
|
|||||||
- name: nginx
|
- name: nginx
|
||||||
args:
|
args:
|
||||||
- def
|
- def
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
"remove mapping - directive": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: myDeploy
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: test
|
||||||
|
image: test
|
||||||
|
`,
|
||||||
|
patch: yaml.MustParse(`
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: myDeploy
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: test
|
||||||
|
image: test
|
||||||
|
$patch: delete
|
||||||
|
`),
|
||||||
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: myDeploy
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers: []
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
"replace mapping - directive": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: myDeploy
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: test
|
||||||
|
image: test
|
||||||
|
`,
|
||||||
|
patch: yaml.MustParse(`
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: myDeploy
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
$patch: replace
|
||||||
|
containers:
|
||||||
|
- name: new
|
||||||
|
`),
|
||||||
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: myDeploy
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: new
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
"merge mapping - directive": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: myDeploy
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: test
|
||||||
|
image: test
|
||||||
|
`,
|
||||||
|
patch: yaml.MustParse(`
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: myDeploy
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: test
|
||||||
|
image: test1
|
||||||
|
$patch: merge
|
||||||
|
`),
|
||||||
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: myDeploy
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: test
|
||||||
|
image: test1
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
"remove list - directive": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: myDeploy
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: test
|
||||||
|
image: test
|
||||||
|
`,
|
||||||
|
patch: yaml.MustParse(`
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: myDeploy
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- whatever
|
||||||
|
- $patch: delete
|
||||||
|
`),
|
||||||
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: myDeploy
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec: {}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
"replace list - directive": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: myDeploy
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: test
|
||||||
|
image: test
|
||||||
|
`,
|
||||||
|
patch: yaml.MustParse(`
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: myDeploy
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: replace
|
||||||
|
image: replace
|
||||||
|
- $patch: replace
|
||||||
|
`),
|
||||||
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: myDeploy
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: replace
|
||||||
|
image: replace
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
"merge list - directive": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: myDeploy
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: test
|
||||||
|
image: test
|
||||||
|
`,
|
||||||
|
patch: yaml.MustParse(`
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: myDeploy
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: test2
|
||||||
|
image: test2
|
||||||
|
- $patch: merge
|
||||||
|
`),
|
||||||
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: myDeploy
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: test2
|
||||||
|
image: test2
|
||||||
|
- name: test
|
||||||
|
image: test
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,12 +9,11 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/filters/prefixsuffix"
|
"sigs.k8s.io/kustomize/api/filters/prefixsuffix"
|
||||||
"sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
"sigs.k8s.io/kustomize/kyaml/kio"
|
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ExampleFilter() {
|
func ExampleFilter() {
|
||||||
fss := builtinconfig.MakeDefaultConfig().NamePrefix
|
|
||||||
err := kio.Pipeline{
|
err := kio.Pipeline{
|
||||||
Inputs: []kio.Reader{&kio.ByteReader{Reader: bytes.NewBufferString(`
|
Inputs: []kio.Reader{&kio.ByteReader{Reader: bytes.NewBufferString(`
|
||||||
apiVersion: example.com/v1
|
apiVersion: example.com/v1
|
||||||
@@ -27,7 +26,8 @@ kind: Bar
|
|||||||
metadata:
|
metadata:
|
||||||
name: instance
|
name: instance
|
||||||
`)}},
|
`)}},
|
||||||
Filters: []kio.Filter{prefixsuffix.Filter{Prefix: "baz-", FsSlice: fss}},
|
Filters: []kio.Filter{prefixsuffix.Filter{
|
||||||
|
Prefix: "baz-", FieldSpec: types.FieldSpec{Path: "metadata/name"}}},
|
||||||
Outputs: []kio.Writer{kio.ByteWriter{Writer: os.Stdout}},
|
Outputs: []kio.Writer{kio.ByteWriter{Writer: os.Stdout}},
|
||||||
}.Execute()
|
}.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ package prefixsuffix
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/filters/fsslice"
|
"sigs.k8s.io/kustomize/api/filters/fieldspec"
|
||||||
|
"sigs.k8s.io/kustomize/api/filters/filtersutil"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
"sigs.k8s.io/kustomize/kyaml/kio"
|
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
@@ -17,28 +18,26 @@ type Filter struct {
|
|||||||
Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
|
Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
|
||||||
Suffix string `json:"suffix,omitempty" yaml:"suffix,omitempty"`
|
Suffix string `json:"suffix,omitempty" yaml:"suffix,omitempty"`
|
||||||
|
|
||||||
FsSlice types.FsSlice `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
FieldSpec types.FieldSpec `json:"fieldSpec,omitempty" yaml:"fieldSpec,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ kio.Filter = Filter{}
|
var _ kio.Filter = Filter{}
|
||||||
|
|
||||||
func (ns Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
|
func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
|
||||||
return kio.FilterAll(yaml.FilterFunc(ns.run)).Filter(nodes)
|
return kio.FilterAll(yaml.FilterFunc(f.run)).Filter(nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run runs the filter on a single node rather than a slice
|
func (f Filter) run(node *yaml.RNode) (*yaml.RNode, error) {
|
||||||
func (ns Filter) run(node *yaml.RNode) (*yaml.RNode, error) {
|
err := node.PipeE(fieldspec.Filter{
|
||||||
// transformations based on data -- :)
|
FieldSpec: f.FieldSpec,
|
||||||
err := node.PipeE(fsslice.Filter{
|
SetValue: f.evaluateField,
|
||||||
FsSlice: ns.FsSlice,
|
|
||||||
SetValue: ns.set,
|
|
||||||
CreateKind: yaml.ScalarNode, // Name is a ScalarNode
|
CreateKind: yaml.ScalarNode, // Name is a ScalarNode
|
||||||
CreateTag: yaml.StringTag,
|
CreateTag: yaml.NodeTagString,
|
||||||
})
|
})
|
||||||
return node, err
|
return node, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ns Filter) set(node *yaml.RNode) error {
|
func (f Filter) evaluateField(node *yaml.RNode) error {
|
||||||
return fsslice.SetScalar(fmt.Sprintf(
|
return filtersutil.SetScalar(fmt.Sprintf(
|
||||||
"%s%s%s", ns.Prefix, node.YNode().Value, ns.Suffix))(node)
|
"%s%s%s", f.Prefix, node.YNode().Value, f.Suffix))(node)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,14 +9,12 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"sigs.k8s.io/kustomize/api/filters/prefixsuffix"
|
"sigs.k8s.io/kustomize/api/filters/prefixsuffix"
|
||||||
"sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig"
|
|
||||||
filtertest_test "sigs.k8s.io/kustomize/api/testutils/filtertest"
|
filtertest_test "sigs.k8s.io/kustomize/api/testutils/filtertest"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var tests = []TestCase{
|
var tests = map[string]TestCase{
|
||||||
{
|
"prefix": {
|
||||||
name: "prefix",
|
|
||||||
input: `
|
input: `
|
||||||
apiVersion: example.com/v1
|
apiVersion: example.com/v1
|
||||||
kind: Foo
|
kind: Foo
|
||||||
@@ -40,10 +38,10 @@ metadata:
|
|||||||
name: foo-instance
|
name: foo-instance
|
||||||
`,
|
`,
|
||||||
filter: prefixsuffix.Filter{Prefix: "foo-"},
|
filter: prefixsuffix.Filter{Prefix: "foo-"},
|
||||||
|
fs: types.FieldSpec{Path: "metadata/name"},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
"suffix": {
|
||||||
name: "suffix",
|
|
||||||
input: `
|
input: `
|
||||||
apiVersion: example.com/v1
|
apiVersion: example.com/v1
|
||||||
kind: Foo
|
kind: Foo
|
||||||
@@ -67,10 +65,10 @@ metadata:
|
|||||||
name: instance-foo
|
name: instance-foo
|
||||||
`,
|
`,
|
||||||
filter: prefixsuffix.Filter{Suffix: "-foo"},
|
filter: prefixsuffix.Filter{Suffix: "-foo"},
|
||||||
|
fs: types.FieldSpec{Path: "metadata/name"},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
"prefix-suffix": {
|
||||||
name: "prefix-suffix",
|
|
||||||
input: `
|
input: `
|
||||||
apiVersion: example.com/v1
|
apiVersion: example.com/v1
|
||||||
kind: Foo
|
kind: Foo
|
||||||
@@ -94,10 +92,10 @@ metadata:
|
|||||||
name: bar-instance-foo
|
name: bar-instance-foo
|
||||||
`,
|
`,
|
||||||
filter: prefixsuffix.Filter{Prefix: "bar-", Suffix: "-foo"},
|
filter: prefixsuffix.Filter{Prefix: "bar-", Suffix: "-foo"},
|
||||||
|
fs: types.FieldSpec{Path: "metadata/name"},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
"data-fieldspecs": {
|
||||||
name: "data-fieldspecs",
|
|
||||||
input: `
|
input: `
|
||||||
apiVersion: example.com/v1
|
apiVersion: example.com/v1
|
||||||
kind: Foo
|
kind: Foo
|
||||||
@@ -119,7 +117,7 @@ a:
|
|||||||
apiVersion: example.com/v1
|
apiVersion: example.com/v1
|
||||||
kind: Foo
|
kind: Foo
|
||||||
metadata:
|
metadata:
|
||||||
name: foo-instance
|
name: instance
|
||||||
a:
|
a:
|
||||||
b:
|
b:
|
||||||
c: foo-d
|
c: foo-d
|
||||||
@@ -127,35 +125,28 @@ a:
|
|||||||
apiVersion: example.com/v1
|
apiVersion: example.com/v1
|
||||||
kind: Bar
|
kind: Bar
|
||||||
metadata:
|
metadata:
|
||||||
name: foo-instance
|
name: instance
|
||||||
a:
|
a:
|
||||||
b:
|
b:
|
||||||
c: foo-d
|
c: foo-d
|
||||||
`,
|
`,
|
||||||
filter: prefixsuffix.Filter{Prefix: "foo-"},
|
filter: prefixsuffix.Filter{Prefix: "foo-"},
|
||||||
fsslice: []types.FieldSpec{
|
fs: types.FieldSpec{Path: "a/b/c"},
|
||||||
{
|
|
||||||
Path: "a/b/c",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
type TestCase struct {
|
type TestCase struct {
|
||||||
name string
|
|
||||||
input string
|
input string
|
||||||
expected string
|
expected string
|
||||||
filter prefixsuffix.Filter
|
filter prefixsuffix.Filter
|
||||||
fsslice types.FsSlice
|
fs types.FieldSpec
|
||||||
}
|
}
|
||||||
|
|
||||||
var config = builtinconfig.MakeDefaultConfig()
|
|
||||||
|
|
||||||
func TestFilter(t *testing.T) {
|
func TestFilter(t *testing.T) {
|
||||||
for i := range tests {
|
for name := range tests {
|
||||||
test := tests[i]
|
test := tests[name]
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
test.filter.FsSlice = append(config.NamePrefix, test.fsslice...)
|
test.filter.FieldSpec = test.fs
|
||||||
if !assert.Equal(t,
|
if !assert.Equal(t,
|
||||||
strings.TrimSpace(test.expected),
|
strings.TrimSpace(test.expected),
|
||||||
strings.TrimSpace(
|
strings.TrimSpace(
|
||||||
|
|||||||
3
api/filters/refvar/doc.go
Normal file
3
api/filters/refvar/doc.go
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
// Package refvar contains a kio.Filter implementation of the kustomize
|
||||||
|
// refvar transformer.
|
||||||
|
package refvar
|
||||||
101
api/filters/refvar/refvar.go
Normal file
101
api/filters/refvar/refvar.go
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
package refvar
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"sigs.k8s.io/kustomize/api/filters/fieldspec"
|
||||||
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
|
|
||||||
|
expansion2 "sigs.k8s.io/kustomize/api/internal/accumulator/expansion"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Filter updates $(VAR) style variables with values.
|
||||||
|
// The fieldSpecs are the places to look for occurrences of $(VAR).
|
||||||
|
type Filter struct {
|
||||||
|
MappingFunc func(string) interface{} `json:"mappingFunc,omitempty" yaml:"mappingFunc,omitempty"`
|
||||||
|
FieldSpec types.FieldSpec `json:"fieldSpec,omitempty" yaml:"fieldSpec,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
|
||||||
|
return kio.FilterAll(yaml.FilterFunc(f.run)).Filter(nodes)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f Filter) run(node *yaml.RNode) (*yaml.RNode, error) {
|
||||||
|
err := node.PipeE(fieldspec.Filter{
|
||||||
|
FieldSpec: f.FieldSpec,
|
||||||
|
SetValue: f.set,
|
||||||
|
})
|
||||||
|
return node, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f Filter) set(node *yaml.RNode) error {
|
||||||
|
if yaml.IsMissingOrNull(node) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
switch node.YNode().Kind {
|
||||||
|
case yaml.ScalarNode:
|
||||||
|
return f.setScalar(node)
|
||||||
|
case yaml.MappingNode:
|
||||||
|
return f.setMap(node)
|
||||||
|
case yaml.SequenceNode:
|
||||||
|
return f.setSeq(node)
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("invalid type encountered %v", node.YNode().Kind)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateNodeValue(node *yaml.Node, newValue interface{}) {
|
||||||
|
switch newValue := newValue.(type) {
|
||||||
|
case int64:
|
||||||
|
node.Value = strconv.FormatInt(newValue, 10)
|
||||||
|
node.Tag = yaml.NodeTagInt
|
||||||
|
case bool:
|
||||||
|
node.SetString(strconv.FormatBool(newValue))
|
||||||
|
node.Tag = yaml.NodeTagBool
|
||||||
|
case float64:
|
||||||
|
node.SetString(strconv.FormatFloat(newValue, 'f', -1, 64))
|
||||||
|
node.Tag = yaml.NodeTagFloat
|
||||||
|
default:
|
||||||
|
node.SetString(newValue.(string))
|
||||||
|
node.Tag = yaml.NodeTagString
|
||||||
|
}
|
||||||
|
node.Style = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f Filter) setScalar(node *yaml.RNode) error {
|
||||||
|
if !yaml.IsYNodeString(node.YNode()) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
v := expansion2.Expand(node.YNode().Value, f.MappingFunc)
|
||||||
|
updateNodeValue(node.YNode(), v)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f Filter) setMap(node *yaml.RNode) error {
|
||||||
|
contents := node.YNode().Content
|
||||||
|
for i := 0; i < len(contents); i += 2 {
|
||||||
|
if !yaml.IsYNodeString(contents[i]) {
|
||||||
|
return fmt.Errorf("invalid map key: %s, type: %s", contents[i].Value, contents[i].Tag)
|
||||||
|
}
|
||||||
|
if !yaml.IsYNodeString(contents[i+1]) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
newValue := expansion2.Expand(contents[i+1].Value, f.MappingFunc)
|
||||||
|
updateNodeValue(contents[i+1], newValue)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f Filter) setSeq(node *yaml.RNode) error {
|
||||||
|
for _, item := range node.YNode().Content {
|
||||||
|
if !yaml.IsYNodeString(item) {
|
||||||
|
return fmt.Errorf("invalid value type expect a string")
|
||||||
|
}
|
||||||
|
newValue := expansion2.Expand(item.Value, f.MappingFunc)
|
||||||
|
updateNodeValue(item, newValue)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
293
api/filters/refvar/refvar_test.go
Normal file
293
api/filters/refvar/refvar_test.go
Normal file
@@ -0,0 +1,293 @@
|
|||||||
|
package refvar
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
expansion2 "sigs.k8s.io/kustomize/api/internal/accumulator/expansion"
|
||||||
|
filtertest_test "sigs.k8s.io/kustomize/api/testutils/filtertest"
|
||||||
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestFilter(t *testing.T) {
|
||||||
|
replacementCounts := make(map[string]int)
|
||||||
|
|
||||||
|
testCases := map[string]struct {
|
||||||
|
input string
|
||||||
|
expected string
|
||||||
|
filter Filter
|
||||||
|
}{
|
||||||
|
"simple scalar": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
spec:
|
||||||
|
replicas: $(VAR)`,
|
||||||
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
spec:
|
||||||
|
replicas: 5`,
|
||||||
|
filter: Filter{
|
||||||
|
MappingFunc: expansion2.MappingFuncFor(replacementCounts, map[string]interface{}{
|
||||||
|
"VAR": int64(5),
|
||||||
|
}),
|
||||||
|
FieldSpec: types.FieldSpec{Path: "spec/replicas"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"non-string scalar": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
spec:
|
||||||
|
replicas: 1`,
|
||||||
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
spec:
|
||||||
|
replicas: 1`,
|
||||||
|
filter: Filter{
|
||||||
|
MappingFunc: expansion2.MappingFuncFor(replacementCounts, map[string]interface{}{
|
||||||
|
"VAR": int64(5),
|
||||||
|
}),
|
||||||
|
FieldSpec: types.FieldSpec{Path: "spec/replicas"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"wrong path": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
spec:
|
||||||
|
replicas: 1`,
|
||||||
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
spec:
|
||||||
|
replicas: 1`,
|
||||||
|
filter: Filter{
|
||||||
|
MappingFunc: expansion2.MappingFuncFor(replacementCounts, map[string]interface{}{
|
||||||
|
"VAR": int64(5),
|
||||||
|
}),
|
||||||
|
FieldSpec: types.FieldSpec{Path: "a/b/c"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"sequence": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
data:
|
||||||
|
- $(FOO)
|
||||||
|
- $(BAR)
|
||||||
|
- $(BAZ)
|
||||||
|
- $(FOO)+$(BAR)
|
||||||
|
- $(BOOL)
|
||||||
|
- $(FLOAT)`,
|
||||||
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
data:
|
||||||
|
- foo
|
||||||
|
- bar
|
||||||
|
- $(BAZ)
|
||||||
|
- foo+bar
|
||||||
|
- false
|
||||||
|
- 1.23`,
|
||||||
|
filter: Filter{
|
||||||
|
MappingFunc: expansion2.MappingFuncFor(replacementCounts, map[string]interface{}{
|
||||||
|
"FOO": "foo",
|
||||||
|
"BAR": "bar",
|
||||||
|
"BOOL": false,
|
||||||
|
"FLOAT": 1.23,
|
||||||
|
}),
|
||||||
|
FieldSpec: types.FieldSpec{Path: "data"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"maps": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
data:
|
||||||
|
FOO: $(FOO)
|
||||||
|
BAR: $(BAR)
|
||||||
|
BAZ: $(BAZ)
|
||||||
|
PLUS: $(FOO)+$(BAR)`,
|
||||||
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
data:
|
||||||
|
FOO: foo
|
||||||
|
BAR: bar
|
||||||
|
BAZ: $(BAZ)
|
||||||
|
PLUS: foo+bar`,
|
||||||
|
filter: Filter{
|
||||||
|
MappingFunc: expansion2.MappingFuncFor(replacementCounts, map[string]interface{}{
|
||||||
|
"FOO": "foo",
|
||||||
|
"BAR": "bar",
|
||||||
|
}),
|
||||||
|
FieldSpec: types.FieldSpec{Path: "data"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"complicated case": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
data:
|
||||||
|
slice1:
|
||||||
|
- $(FOO)
|
||||||
|
slice2:
|
||||||
|
FOO: $(FOO)
|
||||||
|
BAR: $(BAR)
|
||||||
|
BOOL: false
|
||||||
|
INT: 0
|
||||||
|
SLICE:
|
||||||
|
- $(FOO)`,
|
||||||
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
data:
|
||||||
|
slice1:
|
||||||
|
- $(FOO)
|
||||||
|
slice2:
|
||||||
|
FOO: foo
|
||||||
|
BAR: bar
|
||||||
|
BOOL: false
|
||||||
|
INT: 0
|
||||||
|
SLICE:
|
||||||
|
- $(FOO)`,
|
||||||
|
filter: Filter{
|
||||||
|
MappingFunc: expansion2.MappingFuncFor(replacementCounts, map[string]interface{}{
|
||||||
|
"FOO": "foo",
|
||||||
|
"BAR": "bar",
|
||||||
|
}),
|
||||||
|
FieldSpec: types.FieldSpec{Path: "data/slice2"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"null value": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
data:
|
||||||
|
FOO: null`,
|
||||||
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
data:
|
||||||
|
FOO: null`,
|
||||||
|
filter: Filter{
|
||||||
|
MappingFunc: expansion2.MappingFuncFor(replacementCounts, map[string]interface{}{}),
|
||||||
|
FieldSpec: types.FieldSpec{Path: "data/FOO"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for tn, tc := range testCases {
|
||||||
|
t.Run(tn, func(t *testing.T) {
|
||||||
|
if !assert.Equal(t,
|
||||||
|
strings.TrimSpace(tc.expected),
|
||||||
|
strings.TrimSpace(
|
||||||
|
filtertest_test.RunFilter(t, tc.input, tc.filter))) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFilterUnhappy(t *testing.T) {
|
||||||
|
replacementCounts := make(map[string]int)
|
||||||
|
|
||||||
|
testCases := map[string]struct {
|
||||||
|
input string
|
||||||
|
expectedError string
|
||||||
|
filter Filter
|
||||||
|
}{
|
||||||
|
"non-string in sequence": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
data:
|
||||||
|
slice:
|
||||||
|
- false`,
|
||||||
|
expectedError: `obj 'apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
annotations:
|
||||||
|
config.kubernetes.io/index: '0'
|
||||||
|
data:
|
||||||
|
slice:
|
||||||
|
- false
|
||||||
|
' at path 'data/slice': invalid value type expect a string`,
|
||||||
|
filter: Filter{
|
||||||
|
MappingFunc: expansion2.MappingFuncFor(replacementCounts, map[string]interface{}{
|
||||||
|
"VAR": int64(5),
|
||||||
|
}),
|
||||||
|
FieldSpec: types.FieldSpec{Path: "data/slice"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"invalid key in map": {
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
data:
|
||||||
|
1: str`,
|
||||||
|
expectedError: `obj 'apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dep
|
||||||
|
annotations:
|
||||||
|
config.kubernetes.io/index: '0'
|
||||||
|
data:
|
||||||
|
1: str
|
||||||
|
' at path 'data': invalid map key: 1, type: ` + yaml.NodeTagInt,
|
||||||
|
filter: Filter{
|
||||||
|
MappingFunc: expansion2.MappingFuncFor(replacementCounts, map[string]interface{}{
|
||||||
|
"VAR": int64(5),
|
||||||
|
}),
|
||||||
|
FieldSpec: types.FieldSpec{Path: "data"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for tn, tc := range testCases {
|
||||||
|
t.Run(tn, func(t *testing.T) {
|
||||||
|
_, err := filtertest_test.RunFilterE(t, tc.input, tc.filter)
|
||||||
|
if !assert.EqualError(t, err, tc.expectedError) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,10 +33,8 @@ spec:
|
|||||||
Count: 42,
|
Count: 42,
|
||||||
Name: "instance",
|
Name: "instance",
|
||||||
},
|
},
|
||||||
FsSlice: types.FsSlice{
|
FieldSpec: types.FieldSpec{
|
||||||
{
|
Path: "spec/template/replicas",
|
||||||
Path: "spec/template/replicas",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
Outputs: []kio.Writer{kio.ByteWriter{Writer: os.Stdout}},
|
Outputs: []kio.Writer{kio.ByteWriter{Writer: os.Stdout}},
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ package replicacount
|
|||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/filters/fsslice"
|
"sigs.k8s.io/kustomize/api/filters/fieldspec"
|
||||||
|
"sigs.k8s.io/kustomize/api/filters/filtersutil"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
"sigs.k8s.io/kustomize/kyaml/kio"
|
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
@@ -11,10 +12,8 @@ import (
|
|||||||
|
|
||||||
// Filter updates/sets replicas fields using the fieldSpecs
|
// Filter updates/sets replicas fields using the fieldSpecs
|
||||||
type Filter struct {
|
type Filter struct {
|
||||||
Replica types.Replica `json:"replica,omitempty" yaml:"replica,omitempty"`
|
Replica types.Replica `json:"replica,omitempty" yaml:"replica,omitempty"`
|
||||||
|
FieldSpec types.FieldSpec `json:"fieldSpec,omitempty" yaml:"fieldSpec,omitempty"`
|
||||||
// FsSlice contains the FieldSpecs to locate the namespace field
|
|
||||||
FsSlice types.FsSlice `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ kio.Filter = Filter{}
|
var _ kio.Filter = Filter{}
|
||||||
@@ -23,27 +22,16 @@ func (rc Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
|
|||||||
return kio.FilterAll(yaml.FilterFunc(rc.run)).Filter(nodes)
|
return kio.FilterAll(yaml.FilterFunc(rc.run)).Filter(nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// run processes each node individually.
|
|
||||||
func (rc Filter) run(node *yaml.RNode) (*yaml.RNode, error) {
|
func (rc Filter) run(node *yaml.RNode) (*yaml.RNode, error) {
|
||||||
meta, err := node.GetMeta()
|
err := node.PipeE(fieldspec.Filter{
|
||||||
if err != nil {
|
FieldSpec: rc.FieldSpec,
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// only update resources where the name matches the Replica name.
|
|
||||||
if meta.Name != rc.Replica.Name {
|
|
||||||
return node, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
err = node.PipeE(fsslice.Filter{
|
|
||||||
FsSlice: rc.FsSlice,
|
|
||||||
SetValue: rc.set,
|
SetValue: rc.set,
|
||||||
CreateKind: yaml.ScalarNode, // replicas is a ScalarNode
|
CreateKind: yaml.ScalarNode, // replicas is a ScalarNode
|
||||||
CreateTag: yaml.IntTag,
|
CreateTag: yaml.NodeTagInt,
|
||||||
})
|
})
|
||||||
return node, err
|
return node, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc Filter) set(node *yaml.RNode) error {
|
func (rc Filter) set(node *yaml.RNode) error {
|
||||||
return fsslice.SetScalar(strconv.FormatInt(rc.Replica.Count, 10))(node)
|
return filtersutil.SetScalar(strconv.FormatInt(rc.Replica.Count, 10))(node)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,19 +5,16 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig"
|
|
||||||
filtertest_test "sigs.k8s.io/kustomize/api/testutils/filtertest"
|
filtertest_test "sigs.k8s.io/kustomize/api/testutils/filtertest"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFilter(t *testing.T) {
|
func TestFilter(t *testing.T) {
|
||||||
var config = builtinconfig.MakeDefaultConfig()
|
|
||||||
|
|
||||||
testCases := map[string]struct {
|
testCases := map[string]struct {
|
||||||
input string
|
input string
|
||||||
expected string
|
expected string
|
||||||
filter Filter
|
filter Filter
|
||||||
fsslice types.FsSlice
|
|
||||||
}{
|
}{
|
||||||
"update field": {
|
"update field": {
|
||||||
input: `
|
input: `
|
||||||
@@ -41,11 +38,7 @@ spec:
|
|||||||
Name: "dep",
|
Name: "dep",
|
||||||
Count: 42,
|
Count: 42,
|
||||||
},
|
},
|
||||||
},
|
FieldSpec: types.FieldSpec{Path: "spec/replicas"},
|
||||||
fsslice: types.FsSlice{
|
|
||||||
{
|
|
||||||
Path: "spec/replicas",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"add field": {
|
"add field": {
|
||||||
@@ -73,9 +66,7 @@ spec:
|
|||||||
Name: "cus",
|
Name: "cus",
|
||||||
Count: 42,
|
Count: 42,
|
||||||
},
|
},
|
||||||
},
|
FieldSpec: types.FieldSpec{
|
||||||
fsslice: types.FsSlice{
|
|
||||||
{
|
|
||||||
Path: "spec/template/replicas",
|
Path: "spec/template/replicas",
|
||||||
CreateIfNotPresent: true,
|
CreateIfNotPresent: true,
|
||||||
},
|
},
|
||||||
@@ -108,9 +99,7 @@ spec:
|
|||||||
Name: "cus",
|
Name: "cus",
|
||||||
Count: 42,
|
Count: 42,
|
||||||
},
|
},
|
||||||
},
|
FieldSpec: types.FieldSpec{
|
||||||
fsslice: types.FsSlice{
|
|
||||||
{
|
|
||||||
Path: "spec/template/replicas",
|
Path: "spec/template/replicas",
|
||||||
CreateIfNotPresent: true,
|
CreateIfNotPresent: true,
|
||||||
},
|
},
|
||||||
@@ -140,9 +129,7 @@ spec:
|
|||||||
Name: "cus",
|
Name: "cus",
|
||||||
Count: 42,
|
Count: 42,
|
||||||
},
|
},
|
||||||
},
|
FieldSpec: types.FieldSpec{
|
||||||
fsslice: types.FsSlice{
|
|
||||||
{
|
|
||||||
Path: "spec/template/replicas",
|
Path: "spec/template/replicas",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -154,7 +141,6 @@ kind: Custom
|
|||||||
metadata:
|
metadata:
|
||||||
name: cus
|
name: cus
|
||||||
spec:
|
spec:
|
||||||
replicas: 5
|
|
||||||
template:
|
template:
|
||||||
replicas: 5
|
replicas: 5
|
||||||
`,
|
`,
|
||||||
@@ -164,7 +150,6 @@ kind: Custom
|
|||||||
metadata:
|
metadata:
|
||||||
name: cus
|
name: cus
|
||||||
spec:
|
spec:
|
||||||
replicas: 42
|
|
||||||
template:
|
template:
|
||||||
replicas: 42
|
replicas: 42
|
||||||
`,
|
`,
|
||||||
@@ -173,21 +158,13 @@ spec:
|
|||||||
Name: "cus",
|
Name: "cus",
|
||||||
Count: 42,
|
Count: 42,
|
||||||
},
|
},
|
||||||
},
|
FieldSpec: types.FieldSpec{Path: "spec/template/replicas"},
|
||||||
fsslice: types.FsSlice{
|
|
||||||
{
|
|
||||||
Path: "spec/template/replicas",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Path: "spec/replicas",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for tn, tc := range testCases {
|
for tn, tc := range testCases {
|
||||||
t.Run(tn, func(t *testing.T) {
|
t.Run(tn, func(t *testing.T) {
|
||||||
tc.filter.FsSlice = append(config.Replicas, tc.fsslice...)
|
|
||||||
if !assert.Equal(t,
|
if !assert.Equal(t,
|
||||||
strings.TrimSpace(tc.expected),
|
strings.TrimSpace(tc.expected),
|
||||||
strings.TrimSpace(
|
strings.TrimSpace(
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
module sigs.k8s.io/kustomize/api
|
module sigs.k8s.io/kustomize/api
|
||||||
|
|
||||||
go 1.13
|
go 1.14
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/evanphx/json-patch v4.5.0+incompatible
|
github.com/evanphx/json-patch v4.5.0+incompatible
|
||||||
@@ -10,12 +10,13 @@ require (
|
|||||||
github.com/pkg/errors v0.8.1
|
github.com/pkg/errors v0.8.1
|
||||||
github.com/stretchr/testify v1.4.0
|
github.com/stretchr/testify v1.4.0
|
||||||
github.com/yujunz/go-getter v1.4.1-lite
|
github.com/yujunz/go-getter v1.4.1-lite
|
||||||
golang.org/x/tools v0.0.0-20191010075000-0337d82405ff
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e
|
||||||
gopkg.in/yaml.v2 v2.2.8
|
gopkg.in/yaml.v2 v2.3.0
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200121175148-a6ecf24a6d71
|
||||||
k8s.io/api v0.17.0
|
k8s.io/api v0.17.0
|
||||||
k8s.io/apimachinery v0.17.0
|
k8s.io/apimachinery v0.17.0
|
||||||
k8s.io/client-go v0.17.0
|
k8s.io/client-go v0.17.0
|
||||||
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a
|
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a
|
||||||
sigs.k8s.io/kustomize/kyaml v0.1.11
|
sigs.k8s.io/kustomize/kyaml v0.9.1
|
||||||
sigs.k8s.io/yaml v1.2.0
|
sigs.k8s.io/yaml v1.2.0
|
||||||
)
|
)
|
||||||
|
|||||||
32
api/go.sum
32
api/go.sum
@@ -104,7 +104,6 @@ github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34
|
|||||||
github.com/go-openapi/jsonreference v0.0.0-20160704190145-13c6e3589ad9/go.mod h1:W3Z9FmVs9qj+KR4zFKmDPGiLdk1D9Rlm7cyMvf57TTg=
|
github.com/go-openapi/jsonreference v0.0.0-20160704190145-13c6e3589ad9/go.mod h1:W3Z9FmVs9qj+KR4zFKmDPGiLdk1D9Rlm7cyMvf57TTg=
|
||||||
github.com/go-openapi/jsonreference v0.17.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I=
|
github.com/go-openapi/jsonreference v0.17.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I=
|
||||||
github.com/go-openapi/jsonreference v0.18.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I=
|
github.com/go-openapi/jsonreference v0.18.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I=
|
||||||
github.com/go-openapi/jsonreference v0.19.2 h1:o20suLFB4Ri0tuzpWtyHlh7E7HnkqTNLq6aR6WVNS1w=
|
|
||||||
github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwohSTlpa0o73RUL1owJc=
|
github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwohSTlpa0o73RUL1owJc=
|
||||||
github.com/go-openapi/jsonreference v0.19.3 h1:5cxNfTy0UVC3X8JL5ymxzyoUZmo8iZb+jeTWn7tUa8o=
|
github.com/go-openapi/jsonreference v0.19.3 h1:5cxNfTy0UVC3X8JL5ymxzyoUZmo8iZb+jeTWn7tUa8o=
|
||||||
github.com/go-openapi/jsonreference v0.19.3/go.mod h1:rjx6GuL8TTa9VaixXglHmQmIL98+wF9xc8zWvFonSJ8=
|
github.com/go-openapi/jsonreference v0.19.3/go.mod h1:rjx6GuL8TTa9VaixXglHmQmIL98+wF9xc8zWvFonSJ8=
|
||||||
@@ -167,7 +166,6 @@ github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a
|
|||||||
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
|
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
|
||||||
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d h1:3PaI8p3seN09VjbTYC/QWlUZdZ1qS1zGjy7LH2Wt07I=
|
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d h1:3PaI8p3seN09VjbTYC/QWlUZdZ1qS1zGjy7LH2Wt07I=
|
||||||
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
|
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
|
||||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
|
|
||||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||||
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||||
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||||
@@ -241,6 +239,7 @@ github.com/hashicorp/go-safetemp v1.0.0/go.mod h1:oaerMy3BhqiTbVye6QuFhFtIceqFoD
|
|||||||
github.com/hashicorp/go-version v1.1.0 h1:bPIoEKD27tNdebFGGxxYwcL4nepeY4j1QP23PFRGzg0=
|
github.com/hashicorp/go-version v1.1.0 h1:bPIoEKD27tNdebFGGxxYwcL4nepeY4j1QP23PFRGzg0=
|
||||||
github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
||||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||||
|
github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU=
|
||||||
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||||
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
|
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
|
||||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||||
@@ -281,7 +280,6 @@ github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN
|
|||||||
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||||
github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||||
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||||
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e h1:hB2xlXdHp/pmPZq0y3QnmWAArdw9PqbmotexnWx/FU8=
|
|
||||||
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||||
github.com/mailru/easyjson v0.7.0 h1:aizVhC/NAAcKWb+5QsU1iNOZb4Yws5UO2I+aIprQITM=
|
github.com/mailru/easyjson v0.7.0 h1:aizVhC/NAAcKWb+5QsU1iNOZb4Yws5UO2I+aIprQITM=
|
||||||
github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs=
|
github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs=
|
||||||
@@ -309,6 +307,8 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
|
|||||||
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
|
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
|
||||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||||
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
|
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
|
||||||
|
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0=
|
||||||
|
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4=
|
||||||
github.com/mozilla/tls-observatory v0.0.0-20190404164649-a3c1b6cfecfd/go.mod h1:SrKMQvPiws7F7iqYp8/TX+IhxCYhzr6N/1yb8cwHsGk=
|
github.com/mozilla/tls-observatory v0.0.0-20190404164649-a3c1b6cfecfd/go.mod h1:SrKMQvPiws7F7iqYp8/TX+IhxCYhzr6N/1yb8cwHsGk=
|
||||||
github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
||||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||||
@@ -343,6 +343,7 @@ github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y8
|
|||||||
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||||
github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
||||||
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
|
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
|
||||||
|
github.com/qri-io/starlib v0.4.2-0.20200213133954-ff2e8cd5ef8d h1:K6eOUihrFLdZjZnA4XlRp864fmWXv9YTIk7VPLhRacA=
|
||||||
github.com/qri-io/starlib v0.4.2-0.20200213133954-ff2e8cd5ef8d/go.mod h1:7DPO4domFU579Ga6E61sB9VFNaniPVwJP5C4bBCu3wA=
|
github.com/qri-io/starlib v0.4.2-0.20200213133954-ff2e8cd5ef8d/go.mod h1:7DPO4domFU579Ga6E61sB9VFNaniPVwJP5C4bBCu3wA=
|
||||||
github.com/quasilyte/go-consistent v0.0.0-20190521200055-c6f3937de18c/go.mod h1:5STLWrekHfjyYwxBRVRXNOSewLJ3PWfDJd1VyTS21fI=
|
github.com/quasilyte/go-consistent v0.0.0-20190521200055-c6f3937de18c/go.mod h1:5STLWrekHfjyYwxBRVRXNOSewLJ3PWfDJd1VyTS21fI=
|
||||||
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
|
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
|
||||||
@@ -373,7 +374,6 @@ github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc=
|
|||||||
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
|
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
|
||||||
github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
|
github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
|
||||||
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
|
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
|
||||||
github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s=
|
|
||||||
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
|
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
|
||||||
github.com/spf13/cobra v1.0.0 h1:6m/oheQuQ13N9ks4hubMG6BnvwOeaJrqSPLahSnczz8=
|
github.com/spf13/cobra v1.0.0 h1:6m/oheQuQ13N9ks4hubMG6BnvwOeaJrqSPLahSnczz8=
|
||||||
github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
|
github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
|
||||||
@@ -427,6 +427,7 @@ go.mongodb.org/mongo-driver v1.1.1/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qL
|
|||||||
go.mongodb.org/mongo-driver v1.1.2/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM=
|
go.mongodb.org/mongo-driver v1.1.2/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM=
|
||||||
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
||||||
go.starlark.net v0.0.0-20190528202925-30ae18b8564f/go.mod h1:c1/X6cHgvdXj6pUlmWKMkuqRnW4K8x2vwt6JAaaircg=
|
go.starlark.net v0.0.0-20190528202925-30ae18b8564f/go.mod h1:c1/X6cHgvdXj6pUlmWKMkuqRnW4K8x2vwt6JAaaircg=
|
||||||
|
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 h1:+FNtrFTmVw0YZGpBGX56XDee331t6JAXeK2bcyhLOOc=
|
||||||
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5/go.mod h1:nmDLcffg48OtT/PSW0Hg7FvpRQsQh5OSqIylirxKC7o=
|
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5/go.mod h1:nmDLcffg48OtT/PSW0Hg7FvpRQsQh5OSqIylirxKC7o=
|
||||||
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||||
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
|
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
|
||||||
@@ -440,6 +441,7 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U
|
|||||||
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20190617133340-57b3e21c3d56/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20190617133340-57b3e21c3d56/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
|
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392 h1:ACG4HJsFiNMf47Y4PeRoebLNy/2lXT9EtprMuTFWt1M=
|
||||||
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
|
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
|
||||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||||
@@ -468,10 +470,9 @@ golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLL
|
|||||||
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9 h1:rjwSpXsdiK0dV8/Naq3kAw9ymfAeJIyd0upUIElB+lI=
|
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9 h1:rjwSpXsdiK0dV8/Naq3kAw9ymfAeJIyd0upUIElB+lI=
|
||||||
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b h1:0mm1VjtFUOIlE1SbDlwjYaDxZVDP2S5ou6y0gSgXHu8=
|
|
||||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
|
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0=
|
||||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
@@ -493,7 +494,6 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69 h1:rOhMmluY6kLMhdnrivzec6lLgaVbMHMn2ISQXJeJ5EM=
|
|
||||||
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20191002063906-3421d5a6bb1c h1:Vco5b+cuG5NNfORVxZy6bYZQ7rsigisU1WQFkvQ0L5E=
|
golang.org/x/sys v0.0.0-20191002063906-3421d5a6bb1c h1:Vco5b+cuG5NNfORVxZy6bYZQ7rsigisU1WQFkvQ0L5E=
|
||||||
golang.org/x/sys v0.0.0-20191002063906-3421d5a6bb1c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20191002063906-3421d5a6bb1c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
@@ -503,6 +503,7 @@ golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3
|
|||||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
|
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZenJ2O330aBsf7JfSUXmQ=
|
||||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
@@ -527,6 +528,8 @@ golang.org/x/tools v0.0.0-20190910044552-dd2b5c81c578/go.mod h1:b+2E5dAYhXwXZwtn
|
|||||||
golang.org/x/tools v0.0.0-20190930201159-7c411dea38b0/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20190930201159-7c411dea38b0/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.0.0-20191010075000-0337d82405ff h1:XdBG6es/oFDr1HwaxkxgVve7NB281QhxgK/i4voubFs=
|
golang.org/x/tools v0.0.0-20191010075000-0337d82405ff h1:XdBG6es/oFDr1HwaxkxgVve7NB281QhxgK/i4voubFs=
|
||||||
golang.org/x/tools v0.0.0-20191010075000-0337d82405ff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191010075000-0337d82405ff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e h1:aZzprAO9/8oim3qStq3wc1Xuxx4QmAGriC4VU4ojemQ=
|
||||||
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
|
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
|
||||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||||
@@ -553,14 +556,13 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWD
|
|||||||
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
|
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
|
||||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
|
|
||||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
|
|
||||||
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
||||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2 h1:XZx7nhd5GMaZpmDaEHFVafUZC7ya0fuo7cSJ3UCKYmM=
|
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200121175148-a6ecf24a6d71 h1:Xe2gvTZUJpsvOWUnvmL/tmhVBZUmHSvLbMjRj6NUUKo=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200121175148-a6ecf24a6d71/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM=
|
honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM=
|
||||||
@@ -578,6 +580,7 @@ k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8=
|
|||||||
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
|
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
|
||||||
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a h1:UcxjrRMyNx/i/y8G7kPvLyy7rfbeuf1PYyBf973pgyU=
|
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a h1:UcxjrRMyNx/i/y8G7kPvLyy7rfbeuf1PYyBf973pgyU=
|
||||||
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E=
|
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E=
|
||||||
|
k8s.io/utils v0.0.0-20191114184206-e782cd3c129f h1:GiPwtSzdP43eI1hpPCbROQCCIgCuiMMNF8YUVLF3vJo=
|
||||||
k8s.io/utils v0.0.0-20191114184206-e782cd3c129f/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
|
k8s.io/utils v0.0.0-20191114184206-e782cd3c129f/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
|
||||||
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed h1:WX1yoOaKQfddO/mLzdV4wptyWgoH/6hwLs7QHTixo0I=
|
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed h1:WX1yoOaKQfddO/mLzdV4wptyWgoH/6hwLs7QHTixo0I=
|
||||||
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed/go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc=
|
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed/go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc=
|
||||||
@@ -585,10 +588,9 @@ mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b h1:DxJ5nJdkhDlLok9K6qO+5290kphD
|
|||||||
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4=
|
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4=
|
||||||
mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f h1:Cq7MalBHYACRd6EesksG1Q8EoIAKOsiZviGKbOLIej4=
|
mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f h1:Cq7MalBHYACRd6EesksG1Q8EoIAKOsiZviGKbOLIej4=
|
||||||
mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f/go.mod h1:4G1h5nDURzA3bwVMZIVpwbkw+04kSxk3rAtzlimaUJw=
|
mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f/go.mod h1:4G1h5nDURzA3bwVMZIVpwbkw+04kSxk3rAtzlimaUJw=
|
||||||
sigs.k8s.io/kustomize/kyaml v0.1.11 h1:/VvWxVIgH5gG1K4A7trgbyLgO3tRBiAWNhLFVU1HEmo=
|
sigs.k8s.io/kustomize/kyaml v0.9.1 h1:T7aNUraSioQp0NHJZtYjIhL/q8mqRzCiHcAKdvo09go=
|
||||||
sigs.k8s.io/kustomize/kyaml v0.1.11/go.mod h1:72/rLkSi+L/pHM1oCjwrf3ClU+tH5kZQvvdLSqIHwWU=
|
sigs.k8s.io/kustomize/kyaml v0.9.1/go.mod h1:UTm64bSWVdBUA8EQoYCxVOaBQxUdIOr5LKWxA4GNbkw=
|
||||||
sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
|
sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
|
||||||
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
|
|
||||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||||
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
||||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SortArrayAndComputeHash sorts a string array and
|
// SortArrayAndComputeHash sorts a string array and
|
||||||
@@ -50,3 +52,105 @@ func Encode(hex string) (string, error) {
|
|||||||
func Hash(data string) string {
|
func Hash(data string) string {
|
||||||
return fmt.Sprintf("%x", sha256.Sum256([]byte(data)))
|
return fmt.Sprintf("%x", sha256.Sum256([]byte(data)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HashRNode returns the hash value of input RNode
|
||||||
|
func HashRNode(node *yaml.RNode) (string, error) {
|
||||||
|
// get node kind
|
||||||
|
kindNode, err := node.Pipe(yaml.FieldMatcher{Name: "kind"})
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
kind := kindNode.YNode().Value
|
||||||
|
|
||||||
|
// calculate hash for different kinds
|
||||||
|
encoded := ""
|
||||||
|
switch kind {
|
||||||
|
case "ConfigMap":
|
||||||
|
encoded, err = encodeConfigMap(node)
|
||||||
|
case "Secret":
|
||||||
|
encoded, err = encodeSecret(node)
|
||||||
|
default:
|
||||||
|
var encodedBytes []byte
|
||||||
|
encodedBytes, err = json.Marshal(node.YNode())
|
||||||
|
encoded = string(encodedBytes)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return Encode(Hash(encoded))
|
||||||
|
}
|
||||||
|
|
||||||
|
func getNodeValues(node *yaml.RNode, paths []string) (map[string]interface{}, error) {
|
||||||
|
values := make(map[string]interface{})
|
||||||
|
for _, p := range paths {
|
||||||
|
vn, err := node.Pipe(yaml.Lookup(p))
|
||||||
|
if err != nil {
|
||||||
|
return map[string]interface{}{}, err
|
||||||
|
}
|
||||||
|
if vn == nil {
|
||||||
|
values[p] = ""
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if vn.YNode().Kind != yaml.ScalarNode {
|
||||||
|
vs, err := vn.MarshalJSON()
|
||||||
|
if err != nil {
|
||||||
|
return map[string]interface{}{}, err
|
||||||
|
}
|
||||||
|
// data, binaryData and stringData are all maps
|
||||||
|
var v map[string]interface{}
|
||||||
|
json.Unmarshal(vs, &v)
|
||||||
|
values[p] = v
|
||||||
|
} else {
|
||||||
|
values[p] = vn.YNode().Value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return values, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// encodeConfigMap encodes a ConfigMap.
|
||||||
|
// Data, Kind, and Name are taken into account.
|
||||||
|
// BinaryData is included if it's not empty to avoid useless key in output.
|
||||||
|
func encodeConfigMap(node *yaml.RNode) (string, error) {
|
||||||
|
// get fields
|
||||||
|
paths := []string{"metadata/name", "data", "binaryData"}
|
||||||
|
values, err := getNodeValues(node, paths)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
m := map[string]interface{}{"kind": "ConfigMap", "name": values["metadata/name"],
|
||||||
|
"data": values["data"]}
|
||||||
|
if _, ok := values["binaryData"].(map[string]interface{}); ok {
|
||||||
|
m["binaryData"] = values["binaryData"]
|
||||||
|
}
|
||||||
|
|
||||||
|
// json.Marshal sorts the keys in a stable order in the encoding
|
||||||
|
data, err := json.Marshal(m)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return string(data), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// encodeSecret encodes a Secret.
|
||||||
|
// Data, Kind, Name, and Type are taken into account.
|
||||||
|
// StringData is included if it's not empty to avoid useless key in output.
|
||||||
|
func encodeSecret(node *yaml.RNode) (string, error) {
|
||||||
|
// get fields
|
||||||
|
paths := []string{"type", "metadata/name", "data", "stringData"}
|
||||||
|
values, err := getNodeValues(node, paths)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
m := map[string]interface{}{"kind": "Secret", "type": values["type"],
|
||||||
|
"name": values["metadata/name"], "data": values["data"]}
|
||||||
|
if _, ok := values["stringData"].(map[string]interface{}); ok {
|
||||||
|
m["stringData"] = values["stringData"]
|
||||||
|
}
|
||||||
|
|
||||||
|
// json.Marshal sorts the keys in a stable order in the encoding
|
||||||
|
data, err := json.Marshal(m)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return string(data), nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
// Copyright 2019 The Kubernetes Authors.
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
package hasher_test
|
package hasher
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "sigs.k8s.io/kustomize/api/hasher"
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSortArrayAndComputeHash(t *testing.T) {
|
func TestSortArrayAndComputeHash(t *testing.T) {
|
||||||
@@ -39,3 +40,314 @@ func TestHash(t *testing.T) {
|
|||||||
t.Errorf("expected hash %q but got %q", expect, sum)
|
t.Errorf("expected hash %q but got %q", expect, sum)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConfigMapHash(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
desc string
|
||||||
|
cmYaml string
|
||||||
|
hash string
|
||||||
|
err string
|
||||||
|
}{
|
||||||
|
// empty map
|
||||||
|
{"empty data", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap`, "6ct58987ht", ""},
|
||||||
|
// one key
|
||||||
|
{"one key", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
data:
|
||||||
|
one: ""`, "9g67k2htb6", ""},
|
||||||
|
// three keys (tests sorting order)
|
||||||
|
{"three keys", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
data:
|
||||||
|
two: 2
|
||||||
|
one: ""
|
||||||
|
three: 3`, "7757f9kkct", ""},
|
||||||
|
// empty binary data map
|
||||||
|
{"empty binary data", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap`, "6ct58987ht", ""},
|
||||||
|
// one key with binary data
|
||||||
|
{"one key with binary data", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
binaryData:
|
||||||
|
one: ""`, "6mtk2m274t", ""},
|
||||||
|
// three keys with binary data (tests sorting order)
|
||||||
|
{"three keys with binary data", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
binaryData:
|
||||||
|
two: 2
|
||||||
|
one: ""
|
||||||
|
three: 3`, "9th7kc28dg", ""},
|
||||||
|
// two keys, one with string and another with binary data
|
||||||
|
{"two keys with one each", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
data:
|
||||||
|
one: ""
|
||||||
|
binaryData:
|
||||||
|
two: ""`, "698h7c7t9m", ""},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range cases {
|
||||||
|
node, err := yaml.Parse(c.cmYaml)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
h, err := HashRNode(node)
|
||||||
|
if SkipRest(t, c.desc, err, c.err) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if c.hash != h {
|
||||||
|
t.Errorf("case %q, expect hash %q but got %q", c.desc, c.hash, h)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSecretHash(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
desc string
|
||||||
|
secretYaml string
|
||||||
|
hash string
|
||||||
|
err string
|
||||||
|
}{
|
||||||
|
// empty map
|
||||||
|
{"empty data", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
type: my-type`, "5gmgkf8578", ""},
|
||||||
|
// one key
|
||||||
|
{"one key", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
type: my-type
|
||||||
|
data:
|
||||||
|
one: ""`, "74bd68bm66", ""},
|
||||||
|
// three keys (tests sorting order)
|
||||||
|
{"three keys", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
type: my-type
|
||||||
|
data:
|
||||||
|
two: 2
|
||||||
|
one: ""
|
||||||
|
three: 3`, "4gf75c7476", ""},
|
||||||
|
// with stringdata
|
||||||
|
{"stringdata", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
type: my-type
|
||||||
|
data:
|
||||||
|
one: ""
|
||||||
|
stringData:
|
||||||
|
two: 2`, "c4h4264gdb", ""},
|
||||||
|
// empty stringdata
|
||||||
|
{"empty stringdata", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
type: my-type
|
||||||
|
data:
|
||||||
|
one: ""`, "74bd68bm66", ""},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range cases {
|
||||||
|
node, err := yaml.Parse(c.secretYaml)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
h, err := HashRNode(node)
|
||||||
|
if SkipRest(t, c.desc, err, c.err) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if c.hash != h {
|
||||||
|
t.Errorf("case %q, expect hash %q but got %q", c.desc, c.hash, h)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUnstructuredHash(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
desc string
|
||||||
|
unstructured string
|
||||||
|
hash string
|
||||||
|
err string
|
||||||
|
}{
|
||||||
|
{"minimal", `
|
||||||
|
apiVersion: test/v1
|
||||||
|
kind: TestResource
|
||||||
|
metadata:
|
||||||
|
name: my-resource`, "244782mkb7", ""},
|
||||||
|
{"with spec", `
|
||||||
|
apiVersion: test/v1
|
||||||
|
kind: TestResource
|
||||||
|
metadata:
|
||||||
|
name: my-resource
|
||||||
|
spec:
|
||||||
|
foo: 1
|
||||||
|
bar: abc`, "59m2mdccg4", ""},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range cases {
|
||||||
|
node, err := yaml.Parse(c.unstructured)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
h, err := HashRNode(node)
|
||||||
|
if SkipRest(t, c.desc, err, c.err) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if c.hash != h {
|
||||||
|
t.Errorf("case %q, expect hash %q but got %q", c.desc, c.hash, h)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEncodeConfigMap(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
desc string
|
||||||
|
cmYaml string
|
||||||
|
expect string
|
||||||
|
err string
|
||||||
|
}{
|
||||||
|
// empty map
|
||||||
|
{"empty data", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap`, `{"data":"","kind":"ConfigMap","name":""}`, ""},
|
||||||
|
// one key
|
||||||
|
{"one key", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
data:
|
||||||
|
one: ""`, `{"data":{"one":""},"kind":"ConfigMap","name":""}`, ""},
|
||||||
|
// three keys (tests sorting order)
|
||||||
|
{"three keys", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
data:
|
||||||
|
two: 2
|
||||||
|
one: ""
|
||||||
|
three: 3`, `{"data":{"one":"","three":3,"two":2},"kind":"ConfigMap","name":""}`, ""},
|
||||||
|
// empty binary map
|
||||||
|
{"empty data", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap`, `{"data":"","kind":"ConfigMap","name":""}`, ""},
|
||||||
|
// one key with binary data
|
||||||
|
{"one key", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
binaryData:
|
||||||
|
one: ""`, `{"binaryData":{"one":""},"data":"","kind":"ConfigMap","name":""}`, ""},
|
||||||
|
// three keys with binary data (tests sorting order)
|
||||||
|
{"three keys", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
binaryData:
|
||||||
|
two: 2
|
||||||
|
one: ""
|
||||||
|
three: 3`, `{"binaryData":{"one":"","three":3,"two":2},"data":"","kind":"ConfigMap","name":""}`, ""},
|
||||||
|
// two keys, one string and one binary values
|
||||||
|
{"two keys with one each", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
data:
|
||||||
|
one: ""
|
||||||
|
binaryData:
|
||||||
|
two: ""`, `{"binaryData":{"two":""},"data":{"one":""},"kind":"ConfigMap","name":""}`, ""},
|
||||||
|
}
|
||||||
|
for _, c := range cases {
|
||||||
|
node, err := yaml.Parse(c.cmYaml)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
s, err := encodeConfigMap(node)
|
||||||
|
if SkipRest(t, c.desc, err, c.err) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if s != c.expect {
|
||||||
|
t.Errorf("case %q, expect %q but got %q from encode %#v", c.desc, c.expect, s, c.cmYaml)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEncodeSecret(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
desc string
|
||||||
|
secretYaml string
|
||||||
|
expect string
|
||||||
|
err string
|
||||||
|
}{
|
||||||
|
// empty map
|
||||||
|
{"empty data", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
type: my-type`, `{"data":"","kind":"Secret","name":"","type":"my-type"}`, ""},
|
||||||
|
// one key
|
||||||
|
{"one key", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
type: my-type
|
||||||
|
data:
|
||||||
|
one: ""`, `{"data":{"one":""},"kind":"Secret","name":"","type":"my-type"}`, ""},
|
||||||
|
// three keys (tests sorting order) - note json.Marshal base64 encodes the values because they come in as []byte
|
||||||
|
{"three keys", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
type: my-type
|
||||||
|
data:
|
||||||
|
two: 2
|
||||||
|
one: ""
|
||||||
|
three: 3`, `{"data":{"one":"","three":3,"two":2},"kind":"Secret","name":"","type":"my-type"}`, ""},
|
||||||
|
// with stringdata
|
||||||
|
{"stringdata", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
type: my-type
|
||||||
|
data:
|
||||||
|
one: ""
|
||||||
|
stringData:
|
||||||
|
two: 2`, `{"data":{"one":""},"kind":"Secret","name":"","stringData":{"two":2},"type":"my-type"}`, ""},
|
||||||
|
// empty stringdata
|
||||||
|
{"empty stringdata", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
type: my-type
|
||||||
|
data:
|
||||||
|
one: ""`, `{"data":{"one":""},"kind":"Secret","name":"","type":"my-type"}`, ""},
|
||||||
|
}
|
||||||
|
for _, c := range cases {
|
||||||
|
node, err := yaml.Parse(c.secretYaml)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
s, err := encodeSecret(node)
|
||||||
|
if SkipRest(t, c.desc, err, c.err) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if s != c.expect {
|
||||||
|
t.Errorf("case %q, expect %q but got %q from encode %#v", c.desc, c.expect, s, c.secretYaml)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SkipRest returns true if there was a non-nil error or if we expected an error that didn't happen,
|
||||||
|
// and logs the appropriate error on the test object.
|
||||||
|
// The return value indicates whether we should skip the rest of the test case due to the error result.
|
||||||
|
func SkipRest(t *testing.T, desc string, err error, contains string) bool {
|
||||||
|
if err != nil {
|
||||||
|
if len(contains) == 0 {
|
||||||
|
t.Errorf("case %q, expect nil error but got %q", desc, err.Error())
|
||||||
|
} else if !strings.Contains(err.Error(), contains) {
|
||||||
|
t.Errorf("case %q, expect error to contain %q but got %q", desc, contains, err.Error())
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
} else if len(contains) > 0 {
|
||||||
|
t.Errorf("case %q, expect error to contain %q but got nil error", desc, contains)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
@@ -38,36 +38,69 @@ type Loader interface {
|
|||||||
Cleanup() error
|
Cleanup() error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kunstructured allows manipulation of k8s objects
|
// Kunstructured represents a Kubernetes Resource Model object.
|
||||||
// that do not have Golang structs.
|
|
||||||
type Kunstructured interface {
|
type Kunstructured interface {
|
||||||
Map() map[string]interface{}
|
// Several uses.
|
||||||
SetMap(map[string]interface{})
|
|
||||||
Copy() Kunstructured
|
Copy() Kunstructured
|
||||||
GetFieldValue(string) (interface{}, error)
|
|
||||||
GetString(string) (string, error)
|
// Used by Resource.Replace, which in turn is used in many places, e.g.
|
||||||
GetStringSlice(string) ([]string, error)
|
// - resource.Resource.Merge
|
||||||
GetBool(path string) (bool, error)
|
// - resWrangler.appendReplaceOrMerge (AbsorbAll)
|
||||||
GetFloat64(path string) (float64, error)
|
// - api.internal.k8sdeps.transformer.patch.conflictdetector
|
||||||
GetInt64(path string) (int64, error)
|
|
||||||
GetSlice(path string) ([]interface{}, error)
|
|
||||||
GetStringMap(path string) (map[string]string, error)
|
|
||||||
GetMap(path string) (map[string]interface{}, error)
|
|
||||||
MarshalJSON() ([]byte, error)
|
|
||||||
UnmarshalJSON([]byte) error
|
|
||||||
GetGvk() resid.Gvk
|
|
||||||
SetGvk(resid.Gvk)
|
|
||||||
GetKind() string
|
|
||||||
GetName() string
|
|
||||||
SetName(string)
|
|
||||||
SetNamespace(string)
|
|
||||||
GetLabels() map[string]string
|
|
||||||
SetLabels(map[string]string)
|
|
||||||
GetAnnotations() map[string]string
|
GetAnnotations() map[string]string
|
||||||
SetAnnotations(map[string]string)
|
|
||||||
MatchesLabelSelector(selector string) (bool, error)
|
// Used by ResAccumulator and ReplacementTransformer.
|
||||||
|
GetFieldValue(string) (interface{}, error)
|
||||||
|
|
||||||
|
// Used by Resource.OrgId
|
||||||
|
GetGvk() resid.Gvk
|
||||||
|
|
||||||
|
// Used by resource.Factory.SliceFromBytes
|
||||||
|
GetKind() string
|
||||||
|
|
||||||
|
// Used by Resource.Replace
|
||||||
|
GetLabels() map[string]string
|
||||||
|
|
||||||
|
// Used by Resource.CurId and resource factory.
|
||||||
|
GetName() string
|
||||||
|
|
||||||
|
// Used by special case code in
|
||||||
|
// ResMap.SubsetThatCouldBeReferencedByResource
|
||||||
|
GetSlice(path string) ([]interface{}, error)
|
||||||
|
|
||||||
|
// GetString returns the value of a string field.
|
||||||
|
// Used by Resource.GetNamespace
|
||||||
|
GetString(string) (string, error)
|
||||||
|
|
||||||
|
// Several uses.
|
||||||
|
Map() map[string]interface{}
|
||||||
|
|
||||||
|
// Used by Resource.AsYAML and Resource.String
|
||||||
|
MarshalJSON() ([]byte, error)
|
||||||
|
|
||||||
|
// Used by resWrangler.Select
|
||||||
MatchesAnnotationSelector(selector string) (bool, error)
|
MatchesAnnotationSelector(selector string) (bool, error)
|
||||||
Patch(Kunstructured) error
|
|
||||||
|
// Used by resWrangler.Select
|
||||||
|
MatchesLabelSelector(selector string) (bool, error)
|
||||||
|
|
||||||
|
// Used by Resource.Replace.
|
||||||
|
SetAnnotations(map[string]string)
|
||||||
|
|
||||||
|
// Used by PatchStrategicMergeTransformer.
|
||||||
|
SetGvk(resid.Gvk)
|
||||||
|
|
||||||
|
// Used by Resource.Replace and used to remove "validated by" labels.
|
||||||
|
SetLabels(map[string]string)
|
||||||
|
|
||||||
|
// Used by Resource.Replace.
|
||||||
|
SetName(string)
|
||||||
|
|
||||||
|
// Used by Resource.Replace.
|
||||||
|
SetNamespace(string)
|
||||||
|
|
||||||
|
// Needed, for now, by kyaml/filtersutil.ApplyToJSON.
|
||||||
|
UnmarshalJSON([]byte) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// KunstructuredFactory makes instances of Kunstructured.
|
// KunstructuredFactory makes instances of Kunstructured.
|
||||||
|
|||||||
@@ -4,14 +4,12 @@
|
|||||||
package accumulator
|
package accumulator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
|
"sigs.k8s.io/kustomize/api/filters/nameref"
|
||||||
"sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig"
|
"sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig"
|
||||||
"sigs.k8s.io/kustomize/api/resid"
|
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
"sigs.k8s.io/kustomize/api/resource"
|
"sigs.k8s.io/kustomize/kyaml/filtersutil"
|
||||||
"sigs.k8s.io/kustomize/api/transform"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type nameReferenceTransformer struct {
|
type nameReferenceTransformer struct {
|
||||||
@@ -86,16 +84,12 @@ func (o *nameReferenceTransformer) Transform(m resmap.ResMap) error {
|
|||||||
if candidates == nil {
|
if candidates == nil {
|
||||||
candidates = m.SubsetThatCouldBeReferencedByResource(referrer)
|
candidates = m.SubsetThatCouldBeReferencedByResource(referrer)
|
||||||
}
|
}
|
||||||
err := transform.MutateField(
|
err := filtersutil.ApplyToJSON(nameref.Filter{
|
||||||
referrer.Map(),
|
FieldSpec: fSpec,
|
||||||
fSpec.PathSlice(),
|
Referrer: referrer,
|
||||||
fSpec.CreateIfNotPresent,
|
Target: target.Gvk,
|
||||||
o.getNewNameFunc(
|
ReferralCandidates: candidates,
|
||||||
// referrer could be an HPA instance,
|
}, referrer)
|
||||||
// target could be Gvk for Deployment,
|
|
||||||
// candidate a list of resources "reachable"
|
|
||||||
// from the HPA.
|
|
||||||
referrer, target.Gvk, candidates))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -105,165 +99,3 @@ func (o *nameReferenceTransformer) Transform(m resmap.ResMap) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// selectReferral picks the referral among a subset of candidates.
|
|
||||||
// It returns the current name and namespace of the selected candidate.
|
|
||||||
// Note that the content of the referricalCandidateSubset slice is most of the time
|
|
||||||
// identical to the referralCandidates resmap. Still in some cases, such
|
|
||||||
// as ClusterRoleBinding, the subset only contains the resources of a specific
|
|
||||||
// namespace.
|
|
||||||
func (o *nameReferenceTransformer) selectReferral(
|
|
||||||
oldName string,
|
|
||||||
referrer *resource.Resource,
|
|
||||||
target resid.Gvk,
|
|
||||||
referralCandidates resmap.ResMap,
|
|
||||||
referralCandidateSubset []*resource.Resource) (interface{}, interface{}, error) {
|
|
||||||
|
|
||||||
for _, res := range referralCandidateSubset {
|
|
||||||
id := res.OrgId()
|
|
||||||
if id.IsSelected(&target) && res.GetOriginalName() == oldName {
|
|
||||||
matches := referralCandidates.GetMatchingResourcesByOriginalId(id.Equals)
|
|
||||||
// If there's more than one match, there's no way
|
|
||||||
// to know which one to pick, so emit error.
|
|
||||||
if len(matches) > 1 {
|
|
||||||
return nil, nil, fmt.Errorf(
|
|
||||||
"multiple matches for %s:\n %v",
|
|
||||||
id, getIds(matches))
|
|
||||||
}
|
|
||||||
// In the resource, note that it is referenced
|
|
||||||
// by the referrer.
|
|
||||||
res.AppendRefBy(referrer.CurId())
|
|
||||||
// Return transformed name of the object,
|
|
||||||
// complete with prefixes, hashes, etc.
|
|
||||||
return res.GetName(), res.GetNamespace(), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return oldName, nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// utility function to replace a simple string by the new name
|
|
||||||
func (o *nameReferenceTransformer) getSimpleNameField(
|
|
||||||
oldName string,
|
|
||||||
referrer *resource.Resource,
|
|
||||||
target resid.Gvk,
|
|
||||||
referralCandidates resmap.ResMap,
|
|
||||||
referralCandidateSubset []*resource.Resource) (interface{}, error) {
|
|
||||||
|
|
||||||
newName, _, err := o.selectReferral(oldName, referrer, target,
|
|
||||||
referralCandidates, referralCandidateSubset)
|
|
||||||
|
|
||||||
return newName, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// utility function to replace name field within a map[string]interface{}
|
|
||||||
// and leverage the namespace field.
|
|
||||||
func (o *nameReferenceTransformer) getNameAndNsStruct(
|
|
||||||
inMap map[string]interface{},
|
|
||||||
referrer *resource.Resource,
|
|
||||||
target resid.Gvk,
|
|
||||||
referralCandidates resmap.ResMap) (interface{}, error) {
|
|
||||||
|
|
||||||
// Example:
|
|
||||||
if _, ok := inMap["name"]; !ok {
|
|
||||||
return nil, fmt.Errorf(
|
|
||||||
"%#v is expected to contain a name field", inMap)
|
|
||||||
}
|
|
||||||
oldName, ok := inMap["name"].(string)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf(
|
|
||||||
"%#v is expected to contain a name field of type string", oldName)
|
|
||||||
}
|
|
||||||
|
|
||||||
subset := referralCandidates.Resources()
|
|
||||||
if namespacevalue, ok := inMap["namespace"]; ok {
|
|
||||||
namespace := namespacevalue.(string)
|
|
||||||
bynamespace := referralCandidates.GroupedByOriginalNamespace()
|
|
||||||
if _, ok := bynamespace[namespace]; !ok {
|
|
||||||
return inMap, nil
|
|
||||||
}
|
|
||||||
subset = bynamespace[namespace]
|
|
||||||
}
|
|
||||||
|
|
||||||
newname, newnamespace, err := o.selectReferral(oldName, referrer, target,
|
|
||||||
referralCandidates, subset)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newname == oldName) && (newnamespace == nil) {
|
|
||||||
// no candidate found.
|
|
||||||
return inMap, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
inMap["name"] = newname
|
|
||||||
if newnamespace != "" {
|
|
||||||
// We don't want value "" to replace value "default" since
|
|
||||||
// the empty string is handled as a wild card here not default namespace
|
|
||||||
// by kubernetes.
|
|
||||||
inMap["namespace"] = newnamespace
|
|
||||||
}
|
|
||||||
return inMap, nil
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *nameReferenceTransformer) getNewNameFunc(
|
|
||||||
referrer *resource.Resource,
|
|
||||||
target resid.Gvk,
|
|
||||||
referralCandidates resmap.ResMap) func(in interface{}) (interface{}, error) {
|
|
||||||
return func(in interface{}) (interface{}, error) {
|
|
||||||
switch thing := in.(type) {
|
|
||||||
case string:
|
|
||||||
return o.getSimpleNameField(thing, referrer, target,
|
|
||||||
referralCandidates, referralCandidates.Resources())
|
|
||||||
case map[string]interface{}:
|
|
||||||
// Kind: ValidatingWebhookConfiguration
|
|
||||||
// FieldSpec is webhooks/clientConfig/service
|
|
||||||
return o.getNameAndNsStruct(thing, referrer, target,
|
|
||||||
referralCandidates)
|
|
||||||
case []interface{}:
|
|
||||||
for idx, item := range thing {
|
|
||||||
switch value := item.(type) {
|
|
||||||
case string:
|
|
||||||
// Kind: Role/ClusterRole
|
|
||||||
// FieldSpec is rules.resourceNames
|
|
||||||
newName, err := o.getSimpleNameField(value, referrer, target,
|
|
||||||
referralCandidates, referralCandidates.Resources())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
thing[idx] = newName
|
|
||||||
case map[string]interface{}:
|
|
||||||
// Kind: RoleBinding/ClusterRoleBinding
|
|
||||||
// FieldSpec is subjects
|
|
||||||
// Note: The corresponding fieldSpec had been changed from
|
|
||||||
// from path: subjects/name to just path: subjects. This is
|
|
||||||
// what get mutatefield to request the mapping of the whole
|
|
||||||
// map containing namespace and name instead of just a simple
|
|
||||||
// string field containing the name
|
|
||||||
newMap, err := o.getNameAndNsStruct(value, referrer, target,
|
|
||||||
referralCandidates)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
thing[idx] = newMap
|
|
||||||
default:
|
|
||||||
return nil, fmt.Errorf(
|
|
||||||
"%#v is expected to be either a []string or a []map[string]interface{}", in)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return in, nil
|
|
||||||
default:
|
|
||||||
return nil, fmt.Errorf(
|
|
||||||
"%#v is expected to be either a string or a []interface{}", in)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func getIds(rs []*resource.Resource) []string {
|
|
||||||
var result []string
|
|
||||||
for _, r := range rs {
|
|
||||||
result = append(result, r.CurId().String()+"\n")
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -520,7 +520,7 @@ func TestNameReferenceUnhappyRun(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}).ResMap(),
|
}).ResMap(),
|
||||||
expectedErr: "is expected to contain a name field"},
|
expectedErr: "cannot find field 'name' in node"},
|
||||||
}
|
}
|
||||||
|
|
||||||
nrt := newNameReferenceTransformer(builtinconfig.MakeDefaultConfig().NameReference)
|
nrt := newNameReferenceTransformer(builtinconfig.MakeDefaultConfig().NameReference)
|
||||||
|
|||||||
@@ -4,13 +4,12 @@
|
|||||||
package accumulator
|
package accumulator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
expansion2 "sigs.k8s.io/kustomize/api/internal/accumulator/expansion"
|
expansion2 "sigs.k8s.io/kustomize/api/internal/accumulator/expansion"
|
||||||
|
|
||||||
|
"sigs.k8s.io/kustomize/api/filters/refvar"
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
"sigs.k8s.io/kustomize/api/transform"
|
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/filtersutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
type refVarTransformer struct {
|
type refVarTransformer struct {
|
||||||
@@ -31,59 +30,6 @@ func newRefVarTransformer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// replaceVars accepts as 'in' a string, or string array, which can have
|
|
||||||
// embedded instances of $VAR style variables, e.g. a container command string.
|
|
||||||
// The function returns the string with the variables expanded to their final
|
|
||||||
// values.
|
|
||||||
func (rv *refVarTransformer) replaceVars(in interface{}) (interface{}, error) {
|
|
||||||
switch vt := in.(type) {
|
|
||||||
case []interface{}:
|
|
||||||
var xs []interface{}
|
|
||||||
for _, a := range in.([]interface{}) {
|
|
||||||
x, ok := a.(string)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("expected array of strings, found %v", in)
|
|
||||||
}
|
|
||||||
xs = append(xs, expansion2.Expand(x, rv.mappingFunc))
|
|
||||||
}
|
|
||||||
return xs, nil
|
|
||||||
case map[string]interface{}:
|
|
||||||
inMap := in.(map[string]interface{})
|
|
||||||
xs := make(map[string]interface{}, len(inMap))
|
|
||||||
for k, v := range inMap {
|
|
||||||
s, ok := v.(string)
|
|
||||||
if !ok {
|
|
||||||
// This field can not contain a $(VAR) since it is not
|
|
||||||
// of string type. For instance .spec.replicas: 3 in
|
|
||||||
// a Deployment object
|
|
||||||
xs[k] = v
|
|
||||||
} else {
|
|
||||||
// This field can potentially contains a $(VAR) since it is
|
|
||||||
// of string type. For instance .spec.replicas: $(REPLICAS)
|
|
||||||
// in a Deployment object
|
|
||||||
xs[k] = expansion2.Expand(s, rv.mappingFunc)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return xs, nil
|
|
||||||
case interface{}:
|
|
||||||
s, ok := in.(string)
|
|
||||||
if !ok {
|
|
||||||
// This field can not contain a $(VAR) since it is not of string type.
|
|
||||||
return in, nil
|
|
||||||
}
|
|
||||||
// This field can potentially contain a $(VAR) since it is
|
|
||||||
// of string type.
|
|
||||||
return expansion2.Expand(s, rv.mappingFunc), nil
|
|
||||||
// staticcheck erroneously claims that `case nil`
|
|
||||||
// is unreachable here, so suppressing it.
|
|
||||||
//nolint:staticcheck
|
|
||||||
case nil:
|
|
||||||
return nil, nil
|
|
||||||
default:
|
|
||||||
return "", fmt.Errorf("invalid type encountered %T", vt)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnusedVars returns slice of Var names that were unused
|
// UnusedVars returns slice of Var names that were unused
|
||||||
// after a Transform run.
|
// after a Transform run.
|
||||||
func (rv *refVarTransformer) UnusedVars() []string {
|
func (rv *refVarTransformer) UnusedVars() []string {
|
||||||
@@ -104,12 +50,12 @@ func (rv *refVarTransformer) Transform(m resmap.ResMap) error {
|
|||||||
rv.replacementCounts, rv.varMap)
|
rv.replacementCounts, rv.varMap)
|
||||||
for _, res := range m.Resources() {
|
for _, res := range m.Resources() {
|
||||||
for _, fieldSpec := range rv.fieldSpecs {
|
for _, fieldSpec := range rv.fieldSpecs {
|
||||||
if res.OrgId().IsSelected(&fieldSpec.Gvk) {
|
err := filtersutil.ApplyToJSON(refvar.Filter{
|
||||||
if err := transform.MutateField(
|
MappingFunc: rv.mappingFunc,
|
||||||
res.Map(), fieldSpec.PathSlice(),
|
FieldSpec: fieldSpec,
|
||||||
false, rv.replaceVars); err != nil {
|
}, res)
|
||||||
return err
|
if err != nil {
|
||||||
}
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ func TestRefVarTransformer(t *testing.T) {
|
|||||||
{Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/map"},
|
{Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/map"},
|
||||||
{Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/slice"},
|
{Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/slice"},
|
||||||
{Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/interface"},
|
{Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/interface"},
|
||||||
{Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/nil"},
|
|
||||||
{Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/num"},
|
{Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/num"},
|
||||||
},
|
},
|
||||||
res: resmaptest_test.NewRmBuilder(
|
res: resmaptest_test.NewRmBuilder(
|
||||||
@@ -63,7 +62,7 @@ func TestRefVarTransformer(t *testing.T) {
|
|||||||
"item4": "$(BAZ)+$(BAZ)",
|
"item4": "$(BAZ)+$(BAZ)",
|
||||||
"item5": "$(BOO)",
|
"item5": "$(BOO)",
|
||||||
"item6": "if $(BOO)",
|
"item6": "if $(BOO)",
|
||||||
"item7": 2019,
|
"item7": int64(2019),
|
||||||
},
|
},
|
||||||
"slice": []interface{}{
|
"slice": []interface{}{
|
||||||
"$(FOO)",
|
"$(FOO)",
|
||||||
@@ -74,8 +73,7 @@ func TestRefVarTransformer(t *testing.T) {
|
|||||||
"if $(BOO)",
|
"if $(BOO)",
|
||||||
},
|
},
|
||||||
"interface": "$(FOO)",
|
"interface": "$(FOO)",
|
||||||
"nil": nil,
|
"num": int64(2019),
|
||||||
"num": 2019,
|
|
||||||
}}).ResMap(),
|
}}).ResMap(),
|
||||||
},
|
},
|
||||||
expected: expected{
|
expected: expected{
|
||||||
@@ -95,7 +93,7 @@ func TestRefVarTransformer(t *testing.T) {
|
|||||||
"item4": "5+5",
|
"item4": "5+5",
|
||||||
"item5": true,
|
"item5": true,
|
||||||
"item6": "if true",
|
"item6": "if true",
|
||||||
"item7": 2019,
|
"item7": int64(2019),
|
||||||
},
|
},
|
||||||
"slice": []interface{}{
|
"slice": []interface{}{
|
||||||
"replacementForFoo",
|
"replacementForFoo",
|
||||||
@@ -106,8 +104,7 @@ func TestRefVarTransformer(t *testing.T) {
|
|||||||
"if true",
|
"if true",
|
||||||
},
|
},
|
||||||
"interface": "replacementForFoo",
|
"interface": "replacementForFoo",
|
||||||
"nil": nil,
|
"num": int64(2019),
|
||||||
"num": 2019,
|
|
||||||
}}).ResMap(),
|
}}).ResMap(),
|
||||||
unused: []string{"BAR"},
|
unused: []string{"BAR"},
|
||||||
},
|
},
|
||||||
@@ -131,7 +128,41 @@ func TestRefVarTransformer(t *testing.T) {
|
|||||||
"slice": []interface{}{5}, // noticeably *not* a []string
|
"slice": []interface{}{5}, // noticeably *not* a []string
|
||||||
}}).ResMap(),
|
}}).ResMap(),
|
||||||
},
|
},
|
||||||
errMessage: "expected array of strings, found [5]",
|
errMessage: `obj '{"apiVersion": "v1", "data": {"slice": [5]}, "kind": "ConfigMap", "metadata": {"name": "cm1"}}
|
||||||
|
' at path 'data/slice': invalid value type expect a string`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: "var replacement in nil",
|
||||||
|
given: given{
|
||||||
|
varMap: map[string]interface{}{},
|
||||||
|
fs: []types.FieldSpec{
|
||||||
|
{Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/nil"},
|
||||||
|
},
|
||||||
|
res: resmaptest_test.NewRmBuilder(
|
||||||
|
t, resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())).
|
||||||
|
Add(map[string]interface{}{
|
||||||
|
"apiVersion": "v1",
|
||||||
|
"kind": "ConfigMap",
|
||||||
|
"metadata": map[string]interface{}{
|
||||||
|
"name": "cm1",
|
||||||
|
},
|
||||||
|
"data": map[string]interface{}{
|
||||||
|
"nil": nil, // noticeably *not* a []string
|
||||||
|
}}).ResMap(),
|
||||||
|
},
|
||||||
|
expected: expected{
|
||||||
|
res: resmaptest_test.NewRmBuilder(
|
||||||
|
t, resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())).
|
||||||
|
Add(map[string]interface{}{
|
||||||
|
"apiVersion": "v1",
|
||||||
|
"kind": "ConfigMap",
|
||||||
|
"metadata": map[string]interface{}{
|
||||||
|
"name": "cm1",
|
||||||
|
},
|
||||||
|
"data": map[string]interface{}{
|
||||||
|
"nil": nil, // noticeably *not* a []string
|
||||||
|
}}).ResMap(),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ overview of each component with the following sections going into more details.
|
|||||||
|
|
||||||
The overall structure is outlined in the following figure:
|
The overall structure is outlined in the following figure:
|
||||||

|
https://github.com/kubernetes-sigs/kustomize/blob/master/api/internal/crawl/pictures/token_config.png)
|
||||||
|
|
||||||
#### Crawler
|
#### Crawler
|
||||||
The leftmost component consists of a crawler with an http cache of GitHub
|
The leftmost component consists of a crawler with an http cache of GitHub
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM golang:1.11 AS build
|
FROM golang:1.14 AS build
|
||||||
|
|
||||||
ARG GO111MODULE=on
|
ARG GO111MODULE=on
|
||||||
|
|
||||||
|
|||||||
@@ -159,40 +159,31 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
seedDocs := make(crawler.CrawlSeed, 0)
|
query := []byte(`{ "query":{ "match_all":{} } }`)
|
||||||
|
it := idx.IterateQuery(query, 10000, 60*time.Second)
|
||||||
// get all the documents in the index
|
|
||||||
getSeedDocsFunc := func() {
|
|
||||||
query := []byte(`{ "query":{ "match_all":{} } }`)
|
|
||||||
it := idx.IterateQuery(query, 10000, 60*time.Second)
|
|
||||||
for it.Next() {
|
|
||||||
for _, hit := range it.Value().Hits.Hits {
|
|
||||||
seedDocs = append(seedDocs, hit.Document.Document.Copy())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err := it.Err(); err != nil {
|
|
||||||
log.Fatalf("getSeedDocsFunc Error iterating: %v\n", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch mode {
|
switch mode {
|
||||||
case CrawlIndexAndGithub:
|
case CrawlIndexAndGithub:
|
||||||
getSeedDocsFunc()
|
|
||||||
crawlers := []crawler.Crawler{ghCrawlerConstructor("", "")}
|
crawlers := []crawler.Crawler{ghCrawlerConstructor("", "")}
|
||||||
crawler.CrawlFromSeed(ctx, seedDocs, crawlers, docConverter, indexFunc, seen)
|
crawler.CrawlFromSeedIterator(ctx, it, crawlers, docConverter, indexFunc, seen)
|
||||||
crawler.CrawlGithub(ctx, crawlers, docConverter, indexFunc, seen)
|
crawler.CrawlGithub(ctx, crawlers, docConverter, indexFunc, seen)
|
||||||
case CrawlIndex:
|
case CrawlIndex:
|
||||||
getSeedDocsFunc()
|
|
||||||
crawlers := []crawler.Crawler{ghCrawlerConstructor("", "")}
|
crawlers := []crawler.Crawler{ghCrawlerConstructor("", "")}
|
||||||
crawler.CrawlFromSeed(ctx, seedDocs, crawlers, docConverter, indexFunc, seen)
|
crawler.CrawlFromSeedIterator(ctx, it, crawlers, docConverter, indexFunc, seen)
|
||||||
case CrawlGithub:
|
case CrawlGithub:
|
||||||
crawlers := []crawler.Crawler{ghCrawlerConstructor("", "")}
|
crawlers := []crawler.Crawler{ghCrawlerConstructor("", "")}
|
||||||
// add all the documents in the index into seen.
|
// add all the documents in the index into seen.
|
||||||
// this greatly reduces the time overhead of CrawlGithub.
|
// this greatly reduces the time overhead of CrawlGithub.
|
||||||
getSeedDocsFunc()
|
for it.Next() {
|
||||||
for _, d := range seedDocs {
|
for _, hit := range it.Value().Hits.Hits {
|
||||||
seen[d.ID()] = d.FileType
|
d := hit.Document.Document
|
||||||
|
seen.Set(d.ID(), d.FileType)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if err := it.Err(); err != nil {
|
||||||
|
log.Fatalf("Error iterating the index: %v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
crawler.CrawlGithub(ctx, crawlers, docConverter, indexFunc, seen)
|
crawler.CrawlGithub(ctx, crawlers, docConverter, indexFunc, seen)
|
||||||
case CrawlUser:
|
case CrawlUser:
|
||||||
if *githubUserPtr == "" {
|
if *githubUserPtr == "" {
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
apiVersion: v1
|
|
||||||
kind: Service
|
|
||||||
metadata:
|
|
||||||
name: elasticsearch
|
|
||||||
spec:
|
|
||||||
selector:
|
|
||||||
custom-resource: v1alpha1.ESCluster
|
|
||||||
custom-resource-name: esbasic
|
|
||||||
custom-resource-namespace: default
|
|
||||||
es/data: "true"
|
|
||||||
using: escluster.Cluster
|
|
||||||
ports:
|
|
||||||
- protocol: "TCP"
|
|
||||||
port: 9200
|
|
||||||
type: LoadBalancer
|
|
||||||
loadBalancerIP: ""
|
|
||||||
@@ -213,21 +213,36 @@ func doCrawl(ctx context.Context, docsPtr *CrawlSeed, crawlers []Crawler, conv C
|
|||||||
logger.Printf("\t%d documents cannot be converted but still were inserted or updated in the index\n", convErrCount)
|
logger.Printf("\t%d documents cannot be converted but still were inserted or updated in the index\n", convErrCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CrawlFromSeedIterator iterates all the documents in the index and call CrawlFromSeed for each document.
|
||||||
|
func CrawlFromSeedIterator(ctx context.Context, it *index.KustomizeIterator, crawlers []Crawler,
|
||||||
|
conv Converter, indx IndexFunc, seen utils.SeenMap) {
|
||||||
|
docCount := 0
|
||||||
|
for it.Next() {
|
||||||
|
for _, hit := range it.Value().Hits.Hits {
|
||||||
|
docCount++
|
||||||
|
logger.Printf("updating document %d from seed\n", docCount)
|
||||||
|
|
||||||
|
singleSeed := CrawlSeed{&(hit.Document.Document)}
|
||||||
|
CrawlFromSeed(ctx, singleSeed, crawlers, conv, indx, seen)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := it.Err(); err != nil {
|
||||||
|
log.Fatalf("Error iterating the index: %v\n", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// CrawlFromSeed updates all the documents in seed, and crawls all the new
|
// CrawlFromSeed updates all the documents in seed, and crawls all the new
|
||||||
// documents referred in the seed.
|
// documents referred in the seed.
|
||||||
func CrawlFromSeed(ctx context.Context, seed CrawlSeed, crawlers []Crawler,
|
func CrawlFromSeed(ctx context.Context, seed CrawlSeed, crawlers []Crawler,
|
||||||
conv Converter, indx IndexFunc, seen utils.SeenMap) {
|
conv Converter, indx IndexFunc, seen utils.SeenMap) {
|
||||||
|
|
||||||
// stack tracks the documents directly referred in other documents.
|
// stack tracks the documents directly referred in the seed.
|
||||||
stack := make(CrawlSeed, 0)
|
stack := make(CrawlSeed, 0)
|
||||||
|
|
||||||
// Exploit seed to update bulk of corpus.
|
|
||||||
logger.Printf("updating %d documents from seed\n", len(seed))
|
|
||||||
// each unique document in seed will be crawled once.
|
// each unique document in seed will be crawled once.
|
||||||
doCrawl(ctx, &seed, crawlers, conv, indx, seen, &stack, true, false)
|
doCrawl(ctx, &seed, crawlers, conv, indx, seen, &stack, true, false)
|
||||||
|
|
||||||
// Traverse any new documents added while updating corpus.
|
logger.Printf("crawling %d new documents referred by doc\n", len(stack))
|
||||||
logger.Printf("crawling %d new documents found in the seed\n", len(stack))
|
|
||||||
// While crawling each document in stack, the documents directly referred in the document
|
// While crawling each document in stack, the documents directly referred in the document
|
||||||
// will be added into stack.
|
// will be added into stack.
|
||||||
// After this statement is done, stack will become empty.
|
// After this statement is done, stack will become empty.
|
||||||
@@ -297,8 +312,6 @@ func CrawlGithubRunner(ctx context.Context, output chan<- CrawledDocument,
|
|||||||
// CrawlGithub crawls all the kustomization files on Github.
|
// CrawlGithub crawls all the kustomization files on Github.
|
||||||
func CrawlGithub(ctx context.Context, crawlers []Crawler, conv Converter,
|
func CrawlGithub(ctx context.Context, crawlers []Crawler, conv Converter,
|
||||||
indx IndexFunc, seen utils.SeenMap) {
|
indx IndexFunc, seen utils.SeenMap) {
|
||||||
// stack tracks the documents directly referred in other documents.
|
|
||||||
stack := make(CrawlSeed, 0)
|
|
||||||
|
|
||||||
// ch is channel where all the crawlers sends the crawled documents to.
|
// ch is channel where all the crawlers sends the crawled documents to.
|
||||||
ch := make(chan CrawledDocument, 1<<10)
|
ch := make(chan CrawledDocument, 1<<10)
|
||||||
@@ -324,7 +337,20 @@ func CrawlGithub(ctx context.Context, crawlers []Crawler, conv Converter,
|
|||||||
"%v could not match any crawler", cdoc))
|
"%v could not match any crawler", cdoc))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// stack tracks the documents directly referred in the document.
|
||||||
|
stack := make(CrawlSeed, 0)
|
||||||
|
|
||||||
addBranches(cdoc, match, indx, seen, &stack)
|
addBranches(cdoc, match, indx, seen, &stack)
|
||||||
|
|
||||||
|
if len(stack) > 0 {
|
||||||
|
// here the documents referred in a kustomization file are crawled separately,
|
||||||
|
// to avoid accumulating all the referred documents into a single gigantic
|
||||||
|
// mem-inentive stack.
|
||||||
|
logger.Printf("crawling the %d new documents referred in doc %d",
|
||||||
|
len(stack), docCount)
|
||||||
|
doCrawl(ctx, &stack, crawlers, conv, indx, seen, &stack, false, true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -336,9 +362,4 @@ func CrawlGithub(ctx context.Context, crawlers []Crawler, conv Converter,
|
|||||||
}
|
}
|
||||||
close(ch)
|
close(ch)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
// Handle deps of newly discovered documents.
|
|
||||||
logger.Printf("crawling the %d new documents referred by other documents",
|
|
||||||
len(stack))
|
|
||||||
doCrawl(ctx, &stack, crawlers, conv, indx, seen, &stack, false, true)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,14 +82,15 @@ func (gc githubCrawler) Crawl(ctx context.Context,
|
|||||||
|
|
||||||
ranges := []RangeWithin{
|
ranges := []RangeWithin{
|
||||||
RangeWithin{
|
RangeWithin{
|
||||||
start: uint64(0),
|
start: uint64(0),
|
||||||
end: githubMaxFileSize,
|
end: githubMaxFileSize,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
errs := make(multiError, 0)
|
errs := make(multiError, 0)
|
||||||
for len(ranges) > 0 {
|
for len(ranges) > 0 {
|
||||||
tailRange := ranges[len(ranges) - 1]
|
logger.Printf("Current ranges: %v (len: %d)\n", ranges, len(ranges))
|
||||||
|
tailRange := ranges[len(ranges)-1]
|
||||||
ranges = ranges[:(len(ranges) - 1)]
|
ranges = ranges[:(len(ranges) - 1)]
|
||||||
reProcessQueryRanges, err := gc.CrawlSingleRange(ctx, output, seen, tailRange.start, tailRange.end)
|
reProcessQueryRanges, err := gc.CrawlSingleRange(ctx, output, seen, tailRange.start, tailRange.end)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -151,7 +152,15 @@ func (gc githubCrawler) CrawlSingleRange(ctx context.Context,
|
|||||||
}
|
}
|
||||||
queryResult.Add(rangeResult)
|
queryResult.Add(rangeResult)
|
||||||
if reProcessQuery {
|
if reProcessQuery {
|
||||||
reProcessQueryRanges = append(reProcessQueryRanges, RangeSizes(query))
|
// if the size of a range is 0, such as [245, 245], and reProcessQuery is true,
|
||||||
|
// it means that there are more than 1000 results for the query range.
|
||||||
|
// Reprocessing the query range will not help because the GitHub Search API
|
||||||
|
// only provides up to 1,000 results for each search.
|
||||||
|
if RangeSizes(query).Size() == 0 {
|
||||||
|
logger.Printf("range size is 0 includes more than 1000 results: %s", query)
|
||||||
|
} else {
|
||||||
|
reProcessQueryRanges = append(reProcessQueryRanges, RangeSizes(query))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -225,3 +225,7 @@ type RangeWithin struct {
|
|||||||
func (r RangeWithin) RangeString() string {
|
func (r RangeWithin) RangeString() string {
|
||||||
return fmt.Sprintf("%d..%d", r.start, r.end)
|
return fmt.Sprintf("%d..%d", r.start, r.end)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r RangeWithin) Size() uint64 {
|
||||||
|
return r.end - r.start
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
module sigs.k8s.io/kustomize/api/internal/crawl
|
module sigs.k8s.io/kustomize/api/internal/crawl
|
||||||
|
|
||||||
go 1.13
|
go 1.14
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/elastic/go-elasticsearch/v6 v6.8.5
|
github.com/elastic/go-elasticsearch/v6 v6.8.5
|
||||||
|
|||||||
@@ -16,8 +16,10 @@ github.com/OpenPeeDeeP/depguard v1.0.1/go.mod h1:xsIw86fROiiwelg+jB2uM9PiKihMMmU
|
|||||||
github.com/PuerkitoBio/goquery v1.5.0/go.mod h1:qD2PgZ9lccMbQlc7eEOjaeRlFQON7xY8kdmcsrnKqMg=
|
github.com/PuerkitoBio/goquery v1.5.0/go.mod h1:qD2PgZ9lccMbQlc7eEOjaeRlFQON7xY8kdmcsrnKqMg=
|
||||||
github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
||||||
github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
||||||
|
github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI=
|
||||||
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
||||||
github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
||||||
|
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
|
||||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
||||||
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
|
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
|
||||||
github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM=
|
github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM=
|
||||||
@@ -72,6 +74,7 @@ github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeME
|
|||||||
github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
|
github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
|
||||||
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
|
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
|
||||||
github.com/go-critic/go-critic v0.3.5-0.20190904082202-d79a9f0c64db/go.mod h1:+sE8vrLDS2M0pZkBk0wy6+nLdKexVDrl/jBqQOTDThA=
|
github.com/go-critic/go-critic v0.3.5-0.20190904082202-d79a9f0c64db/go.mod h1:+sE8vrLDS2M0pZkBk0wy6+nLdKexVDrl/jBqQOTDThA=
|
||||||
|
github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w=
|
||||||
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
|
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
|
||||||
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||||
github.com/go-lintpack/lintpack v0.5.2/go.mod h1:NwZuYi2nUHho8XEIZ6SIxihrnPoqBTDqfpXvXAN0sXM=
|
github.com/go-lintpack/lintpack v0.5.2/go.mod h1:NwZuYi2nUHho8XEIZ6SIxihrnPoqBTDqfpXvXAN0sXM=
|
||||||
@@ -91,11 +94,13 @@ github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+
|
|||||||
github.com/go-openapi/jsonpointer v0.17.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M=
|
github.com/go-openapi/jsonpointer v0.17.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M=
|
||||||
github.com/go-openapi/jsonpointer v0.18.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M=
|
github.com/go-openapi/jsonpointer v0.18.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M=
|
||||||
github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg=
|
github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg=
|
||||||
|
github.com/go-openapi/jsonpointer v0.19.3 h1:gihV7YNZK1iK6Tgwwsxo2rJbD1GTbdm72325Bq8FI3w=
|
||||||
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
|
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
|
||||||
github.com/go-openapi/jsonreference v0.0.0-20160704190145-13c6e3589ad9/go.mod h1:W3Z9FmVs9qj+KR4zFKmDPGiLdk1D9Rlm7cyMvf57TTg=
|
github.com/go-openapi/jsonreference v0.0.0-20160704190145-13c6e3589ad9/go.mod h1:W3Z9FmVs9qj+KR4zFKmDPGiLdk1D9Rlm7cyMvf57TTg=
|
||||||
github.com/go-openapi/jsonreference v0.17.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I=
|
github.com/go-openapi/jsonreference v0.17.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I=
|
||||||
github.com/go-openapi/jsonreference v0.18.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I=
|
github.com/go-openapi/jsonreference v0.18.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I=
|
||||||
github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwohSTlpa0o73RUL1owJc=
|
github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwohSTlpa0o73RUL1owJc=
|
||||||
|
github.com/go-openapi/jsonreference v0.19.3 h1:5cxNfTy0UVC3X8JL5ymxzyoUZmo8iZb+jeTWn7tUa8o=
|
||||||
github.com/go-openapi/jsonreference v0.19.3/go.mod h1:rjx6GuL8TTa9VaixXglHmQmIL98+wF9xc8zWvFonSJ8=
|
github.com/go-openapi/jsonreference v0.19.3/go.mod h1:rjx6GuL8TTa9VaixXglHmQmIL98+wF9xc8zWvFonSJ8=
|
||||||
github.com/go-openapi/loads v0.17.0/go.mod h1:72tmFy5wsWx89uEVddd0RjRWPZm92WRLhf7AC+0+OOU=
|
github.com/go-openapi/loads v0.17.0/go.mod h1:72tmFy5wsWx89uEVddd0RjRWPZm92WRLhf7AC+0+OOU=
|
||||||
github.com/go-openapi/loads v0.18.0/go.mod h1:72tmFy5wsWx89uEVddd0RjRWPZm92WRLhf7AC+0+OOU=
|
github.com/go-openapi/loads v0.18.0/go.mod h1:72tmFy5wsWx89uEVddd0RjRWPZm92WRLhf7AC+0+OOU=
|
||||||
@@ -110,6 +115,7 @@ github.com/go-openapi/spec v0.17.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsd
|
|||||||
github.com/go-openapi/spec v0.18.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI=
|
github.com/go-openapi/spec v0.18.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI=
|
||||||
github.com/go-openapi/spec v0.19.2/go.mod h1:sCxk3jxKgioEJikev4fgkNmwS+3kuYdJtcsZsD5zxMY=
|
github.com/go-openapi/spec v0.19.2/go.mod h1:sCxk3jxKgioEJikev4fgkNmwS+3kuYdJtcsZsD5zxMY=
|
||||||
github.com/go-openapi/spec v0.19.3/go.mod h1:FpwSN1ksY1eteniUU7X0N/BgJ7a4WvBFVA8Lj9mJglo=
|
github.com/go-openapi/spec v0.19.3/go.mod h1:FpwSN1ksY1eteniUU7X0N/BgJ7a4WvBFVA8Lj9mJglo=
|
||||||
|
github.com/go-openapi/spec v0.19.5 h1:Xm0Ao53uqnk9QE/LlYV5DEU09UAgpliA85QoT9LzqPw=
|
||||||
github.com/go-openapi/spec v0.19.5/go.mod h1:Hm2Jr4jv8G1ciIAo+frC/Ft+rR2kQDh8JHKHb3gWUSk=
|
github.com/go-openapi/spec v0.19.5/go.mod h1:Hm2Jr4jv8G1ciIAo+frC/Ft+rR2kQDh8JHKHb3gWUSk=
|
||||||
github.com/go-openapi/strfmt v0.17.0/go.mod h1:P82hnJI0CXkErkXi8IKjPbNBM6lV6+5pLP5l494TcyU=
|
github.com/go-openapi/strfmt v0.17.0/go.mod h1:P82hnJI0CXkErkXi8IKjPbNBM6lV6+5pLP5l494TcyU=
|
||||||
github.com/go-openapi/strfmt v0.18.0/go.mod h1:P82hnJI0CXkErkXi8IKjPbNBM6lV6+5pLP5l494TcyU=
|
github.com/go-openapi/strfmt v0.18.0/go.mod h1:P82hnJI0CXkErkXi8IKjPbNBM6lV6+5pLP5l494TcyU=
|
||||||
@@ -120,6 +126,7 @@ github.com/go-openapi/swag v0.0.0-20160704191624-1d0bd113de87/go.mod h1:DXUve3Dp
|
|||||||
github.com/go-openapi/swag v0.17.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg=
|
github.com/go-openapi/swag v0.17.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg=
|
||||||
github.com/go-openapi/swag v0.18.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg=
|
github.com/go-openapi/swag v0.18.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg=
|
||||||
github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
|
github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
|
||||||
|
github.com/go-openapi/swag v0.19.5 h1:lTz6Ys4CmqqCQmZPBlbQENR1/GucA2bzYTE12Pw4tFY=
|
||||||
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
|
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
|
||||||
github.com/go-openapi/validate v0.18.0/go.mod h1:Uh4HdOzKt19xGIGm1qHf/ofbX1YQ4Y+MYsct2VUrAJ4=
|
github.com/go-openapi/validate v0.18.0/go.mod h1:Uh4HdOzKt19xGIGm1qHf/ofbX1YQ4Y+MYsct2VUrAJ4=
|
||||||
github.com/go-openapi/validate v0.19.2/go.mod h1:1tRCw7m3jtI8eNWEEliiAqUIcBztB2KDnRCRMUi7GTA=
|
github.com/go-openapi/validate v0.19.2/go.mod h1:1tRCw7m3jtI8eNWEEliiAqUIcBztB2KDnRCRMUi7GTA=
|
||||||
@@ -242,6 +249,7 @@ github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN
|
|||||||
github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||||
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||||
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||||
|
github.com/mailru/easyjson v0.7.0 h1:aizVhC/NAAcKWb+5QsU1iNOZb4Yws5UO2I+aIprQITM=
|
||||||
github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs=
|
github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs=
|
||||||
github.com/matoous/godox v0.0.0-20190911065817-5d6d842e92eb/go.mod h1:1BELzlh859Sh1c6+90blK8lbYy0kwQf1bYlBhBysy1s=
|
github.com/matoous/godox v0.0.0-20190911065817-5d6d842e92eb/go.mod h1:1BELzlh859Sh1c6+90blK8lbYy0kwQf1bYlBhBysy1s=
|
||||||
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||||
@@ -263,6 +271,8 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
|
|||||||
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
|
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
|
||||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||||
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
|
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
|
||||||
|
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0=
|
||||||
|
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4=
|
||||||
github.com/mozilla/tls-observatory v0.0.0-20190404164649-a3c1b6cfecfd/go.mod h1:SrKMQvPiws7F7iqYp8/TX+IhxCYhzr6N/1yb8cwHsGk=
|
github.com/mozilla/tls-observatory v0.0.0-20190404164649-a3c1b6cfecfd/go.mod h1:SrKMQvPiws7F7iqYp8/TX+IhxCYhzr6N/1yb8cwHsGk=
|
||||||
github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
||||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||||
@@ -330,6 +340,7 @@ github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DM
|
|||||||
github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE=
|
github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=
|
||||||
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
|
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
|
||||||
github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
@@ -353,6 +364,7 @@ github.com/valyala/quicktemplate v1.2.0/go.mod h1:EH+4AkTd43SvgIbQHYu59/cJyxDoOV
|
|||||||
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
|
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
|
||||||
github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw=
|
github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw=
|
||||||
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
|
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
|
||||||
|
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca h1:1CFlNzQhALwjS9mBAUkycX616GzgsuYUOCHA5+HSlXI=
|
||||||
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg=
|
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg=
|
||||||
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
|
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
|
||||||
github.com/yujunz/go-getter v1.4.1-lite h1:FhvNc94AXMZkfqUwfMKhnQEC9phkphSGdPTL7tIdhOM=
|
github.com/yujunz/go-getter v1.4.1-lite h1:FhvNc94AXMZkfqUwfMKhnQEC9phkphSGdPTL7tIdhOM=
|
||||||
@@ -404,8 +416,6 @@ golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLL
|
|||||||
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9 h1:rjwSpXsdiK0dV8/Naq3kAw9ymfAeJIyd0upUIElB+lI=
|
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9 h1:rjwSpXsdiK0dV8/Naq3kAw9ymfAeJIyd0upUIElB+lI=
|
||||||
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b h1:0mm1VjtFUOIlE1SbDlwjYaDxZVDP2S5ou6y0gSgXHu8=
|
|
||||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
@@ -462,6 +472,7 @@ golang.org/x/tools v0.0.0-20190719005602-e377ae9d6386/go.mod h1:jcCCGcm9btYwXyDq
|
|||||||
golang.org/x/tools v0.0.0-20190910044552-dd2b5c81c578/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20190910044552-dd2b5c81c578/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.0.0-20190930201159-7c411dea38b0/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20190930201159-7c411dea38b0/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.0.0-20191010075000-0337d82405ff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191010075000-0337d82405ff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
|
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
|
||||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||||
@@ -490,10 +501,12 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
|
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
|
||||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
||||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
||||||
|
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200121175148-a6ecf24a6d71 h1:Xe2gvTZUJpsvOWUnvmL/tmhVBZUmHSvLbMjRj6NUUKo=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200121175148-a6ecf24a6d71/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||||
@@ -514,7 +527,8 @@ k8s.io/utils v0.0.0-20191114184206-e782cd3c129f/go.mod h1:sZAwmy6armz5eXlNoLmJcl
|
|||||||
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed/go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc=
|
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed/go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc=
|
||||||
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4=
|
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4=
|
||||||
mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f/go.mod h1:4G1h5nDURzA3bwVMZIVpwbkw+04kSxk3rAtzlimaUJw=
|
mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f/go.mod h1:4G1h5nDURzA3bwVMZIVpwbkw+04kSxk3rAtzlimaUJw=
|
||||||
sigs.k8s.io/kustomize/kyaml v0.1.11/go.mod h1:72/rLkSi+L/pHM1oCjwrf3ClU+tH5kZQvvdLSqIHwWU=
|
sigs.k8s.io/kustomize/kyaml v0.9.1 h1:T7aNUraSioQp0NHJZtYjIhL/q8mqRzCiHcAKdvo09go=
|
||||||
|
sigs.k8s.io/kustomize/kyaml v0.9.1/go.mod h1:UTm64bSWVdBUA8EQoYCxVOaBQxUdIOr5LKWxA4GNbkw=
|
||||||
sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
|
sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
|
||||||
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
|
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
|
||||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||||
|
|||||||
8102
api/internal/crawl/ui/package-lock.json
generated
8102
api/internal/crawl/ui/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,21 +1,37 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
type SeenMap map[string]string
|
import "sync"
|
||||||
|
|
||||||
|
type SeenMap struct {
|
||||||
|
data map[string]string
|
||||||
|
lock sync.RWMutex
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: add lock to avoid race condition
|
||||||
func (seen SeenMap) Seen(item string) bool {
|
func (seen SeenMap) Seen(item string) bool {
|
||||||
_, ok := seen[item]
|
seen.lock.RLock()
|
||||||
|
_, ok := seen.data[item]
|
||||||
|
seen.lock.RUnlock()
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
func (seen SeenMap) Set(k, v string) {
|
func (seen SeenMap) Set(k, v string) {
|
||||||
seen[k] = v
|
seen.lock.Lock()
|
||||||
|
seen.data[k] = v
|
||||||
|
seen.lock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// The caller should make sure that key is in the map.
|
// The caller should make sure that key is in the map.
|
||||||
func (seen SeenMap) Value(k string) string {
|
func (seen SeenMap) Value(k string) string {
|
||||||
return seen[k]
|
seen.lock.RLock()
|
||||||
|
v := seen.data[k]
|
||||||
|
seen.lock.RUnlock()
|
||||||
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSeenMap() SeenMap {
|
func NewSeenMap() SeenMap {
|
||||||
return make(map[string]string)
|
return SeenMap{
|
||||||
|
data: make(map[string]string),
|
||||||
|
lock: sync.RWMutex{},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
package git
|
package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"log"
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
@@ -28,40 +27,57 @@ func ClonerUsingGitExec(repoSpec *RepoSpec) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if repoSpec.Ref == "" {
|
|
||||||
repoSpec.Ref = "master"
|
|
||||||
}
|
|
||||||
cmd := exec.Command(
|
cmd := exec.Command(
|
||||||
gitProgram,
|
gitProgram,
|
||||||
"clone",
|
"clone",
|
||||||
"--depth=1",
|
"--depth=1",
|
||||||
repoSpec.CloneSpec(),
|
repoSpec.CloneSpec(),
|
||||||
"-b",
|
|
||||||
repoSpec.Ref,
|
|
||||||
repoSpec.Dir.String())
|
repoSpec.Dir.String())
|
||||||
var out bytes.Buffer
|
out, err := cmd.CombinedOutput()
|
||||||
cmd.Stdout = &out
|
|
||||||
cmd.Stderr = &out
|
|
||||||
err = cmd.Run()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error cloning git repo: %s", out.String())
|
log.Printf("Error cloning git repo: %s", out)
|
||||||
return errors.Wrapf(
|
return errors.Wrapf(
|
||||||
err,
|
err,
|
||||||
"trouble cloning git repo %v in %s",
|
"trouble cloning git repo %v in %s",
|
||||||
repoSpec.CloneSpec(), repoSpec.Dir.String())
|
repoSpec.CloneSpec(), repoSpec.Dir.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if repoSpec.Ref != "" {
|
||||||
|
cmd = exec.Command(
|
||||||
|
gitProgram,
|
||||||
|
"fetch",
|
||||||
|
"--depth=1",
|
||||||
|
"origin",
|
||||||
|
repoSpec.Ref)
|
||||||
|
cmd.Dir = repoSpec.Dir.String()
|
||||||
|
out, err = cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error fetching ref: %s", out)
|
||||||
|
return errors.Wrapf(err, "trouble fetching %s", repoSpec.Ref)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd = exec.Command(
|
||||||
|
gitProgram,
|
||||||
|
"checkout",
|
||||||
|
"FETCH_HEAD")
|
||||||
|
cmd.Dir = repoSpec.Dir.String()
|
||||||
|
out, err = cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error checking out ref: %s", out)
|
||||||
|
return errors.Wrapf(err, "trouble checking out %s", repoSpec.Ref)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cmd = exec.Command(
|
cmd = exec.Command(
|
||||||
gitProgram,
|
gitProgram,
|
||||||
"submodule",
|
"submodule",
|
||||||
"update",
|
"update",
|
||||||
"--init",
|
"--init",
|
||||||
"--recursive")
|
"--recursive")
|
||||||
cmd.Stdout = &out
|
|
||||||
cmd.Stderr = &out
|
|
||||||
cmd.Dir = repoSpec.Dir.String()
|
cmd.Dir = repoSpec.Dir.String()
|
||||||
err = cmd.Run()
|
out, err = cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("Error fetching submodules: %s", out)
|
||||||
return errors.Wrapf(err, "trouble fetching submodules for %s", repoSpec.CloneSpec())
|
return errors.Wrapf(err, "trouble fetching submodules for %s", repoSpec.CloneSpec())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Copyright 2019 The Kubernetes Authors.
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
package patch
|
package merge
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@@ -20,18 +20,20 @@ import (
|
|||||||
|
|
||||||
type conflictDetector interface {
|
type conflictDetector interface {
|
||||||
hasConflict(patch1, patch2 *resource.Resource) (bool, error)
|
hasConflict(patch1, patch2 *resource.Resource) (bool, error)
|
||||||
findConflict(conflictingPatchIdx int, patches []*resource.Resource) (*resource.Resource, error)
|
findConflict(
|
||||||
|
conflictingPatchIdx int,
|
||||||
|
patches []*resource.Resource) (*resource.Resource, error)
|
||||||
mergePatches(patch1, patch2 *resource.Resource) (*resource.Resource, error)
|
mergePatches(patch1, patch2 *resource.Resource) (*resource.Resource, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type jsonMergePatch struct {
|
type jsonMergePatch struct {
|
||||||
rf *resource.Factory
|
resourceFactory *resource.Factory
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ conflictDetector = &jsonMergePatch{}
|
var _ conflictDetector = &jsonMergePatch{}
|
||||||
|
|
||||||
func newJMPConflictDetector(rf *resource.Factory) conflictDetector {
|
func newJMPConflictDetector(rf *resource.Factory) conflictDetector {
|
||||||
return &jsonMergePatch{rf: rf}
|
return &jsonMergePatch{resourceFactory: rf}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (jmp *jsonMergePatch) hasConflict(
|
func (jmp *jsonMergePatch) hasConflict(
|
||||||
@@ -40,7 +42,8 @@ func (jmp *jsonMergePatch) hasConflict(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (jmp *jsonMergePatch) findConflict(
|
func (jmp *jsonMergePatch) findConflict(
|
||||||
conflictingPatchIdx int, patches []*resource.Resource) (*resource.Resource, error) {
|
conflictingPatchIdx int,
|
||||||
|
patches []*resource.Resource) (*resource.Resource, error) {
|
||||||
for i, patch := range patches {
|
for i, patch := range patches {
|
||||||
if i == conflictingPatchIdx {
|
if i == conflictingPatchIdx {
|
||||||
continue
|
continue
|
||||||
@@ -77,7 +80,7 @@ func (jmp *jsonMergePatch) mergePatches(
|
|||||||
}
|
}
|
||||||
mergedMap := make(map[string]interface{})
|
mergedMap := make(map[string]interface{})
|
||||||
err = json.Unmarshal(mergedBytes, &mergedMap)
|
err = json.Unmarshal(mergedBytes, &mergedMap)
|
||||||
return jmp.rf.FromMap(mergedMap), err
|
return jmp.resourceFactory.FromMap(mergedMap), err
|
||||||
}
|
}
|
||||||
|
|
||||||
type strategicMergePatch struct {
|
type strategicMergePatch struct {
|
||||||
@@ -94,13 +97,15 @@ func newSMPConflictDetector(
|
|||||||
return &strategicMergePatch{lookupPatchMeta: lookupPatchMeta, rf: rf}, err
|
return &strategicMergePatch{lookupPatchMeta: lookupPatchMeta, rf: rf}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (smp *strategicMergePatch) hasConflict(p1, p2 *resource.Resource) (bool, error) {
|
func (smp *strategicMergePatch) hasConflict(
|
||||||
|
p1, p2 *resource.Resource) (bool, error) {
|
||||||
return strategicpatch.MergingMapsHaveConflicts(
|
return strategicpatch.MergingMapsHaveConflicts(
|
||||||
p1.Map(), p2.Map(), smp.lookupPatchMeta)
|
p1.Map(), p2.Map(), smp.lookupPatchMeta)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (smp *strategicMergePatch) findConflict(
|
func (smp *strategicMergePatch) findConflict(
|
||||||
conflictingPatchIdx int, patches []*resource.Resource) (*resource.Resource, error) {
|
conflictingPatchIdx int,
|
||||||
|
patches []*resource.Resource) (*resource.Resource, error) {
|
||||||
for i, patch := range patches {
|
for i, patch := range patches {
|
||||||
if i == conflictingPatchIdx {
|
if i == conflictingPatchIdx {
|
||||||
continue
|
continue
|
||||||
@@ -122,10 +127,12 @@ func (smp *strategicMergePatch) findConflict(
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (smp *strategicMergePatch) mergePatches(patch1, patch2 *resource.Resource) (*resource.Resource, error) {
|
func (smp *strategicMergePatch) mergePatches(
|
||||||
|
patch1, patch2 *resource.Resource) (*resource.Resource, error) {
|
||||||
if hasDeleteDirectiveMarker(patch2.Map()) {
|
if hasDeleteDirectiveMarker(patch2.Map()) {
|
||||||
if hasDeleteDirectiveMarker(patch1.Map()) {
|
if hasDeleteDirectiveMarker(patch1.Map()) {
|
||||||
return nil, fmt.Errorf("cannot merge patches both containing '$patch: delete' directives")
|
return nil, fmt.Errorf(
|
||||||
|
"cannot merge patches both containing '$patch: delete' directives")
|
||||||
}
|
}
|
||||||
patch1, patch2 = patch2, patch1
|
patch1, patch2 = patch2, patch1
|
||||||
}
|
}
|
||||||
@@ -134,10 +141,21 @@ func (smp *strategicMergePatch) mergePatches(patch1, patch2 *resource.Resource)
|
|||||||
return smp.rf.FromMap(mergeJSONMap), err
|
return smp.rf.FromMap(mergeJSONMap), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// MergePatches merge and index patches by OrgId.
|
type merginatorImpl struct {
|
||||||
// It errors out if there is conflict between patches.
|
rf *resource.Factory
|
||||||
func MergePatches(patches []*resource.Resource,
|
}
|
||||||
rf *resource.Factory) (resmap.ResMap, error) {
|
|
||||||
|
// NewMerginator returns a new implementation of resmap.Merginator.
|
||||||
|
func NewMerginator(rf *resource.Factory) resmap.Merginator {
|
||||||
|
return &merginatorImpl{rf: rf}
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ resmap.Merginator = (*merginatorImpl)(nil)
|
||||||
|
|
||||||
|
// Merge merges the incoming resources into a new resmap.ResMap.
|
||||||
|
// Returns an error on conflict.
|
||||||
|
func (m *merginatorImpl) Merge(
|
||||||
|
patches []*resource.Resource) (resmap.ResMap, error) {
|
||||||
rc := resmap.New()
|
rc := resmap.New()
|
||||||
for ix, patch := range patches {
|
for ix, patch := range patches {
|
||||||
id := patch.OrgId()
|
id := patch.OrgId()
|
||||||
@@ -156,9 +174,9 @@ func MergePatches(patches []*resource.Resource,
|
|||||||
}
|
}
|
||||||
var cd conflictDetector
|
var cd conflictDetector
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cd = newJMPConflictDetector(rf)
|
cd = newJMPConflictDetector(m.rf)
|
||||||
} else {
|
} else {
|
||||||
cd, err = newSMPConflictDetector(versionedObj, rf)
|
cd, err = newSMPConflictDetector(versionedObj, m.rf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
// Copyright 2019 The Kubernetes Authors.
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
// Package transformer provides transformer factory
|
|
||||||
package transformer
|
|
||||||
|
|
||||||
import (
|
|
||||||
"sigs.k8s.io/kustomize/api/internal/k8sdeps/transformer/patch"
|
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
|
||||||
"sigs.k8s.io/kustomize/api/resource"
|
|
||||||
)
|
|
||||||
|
|
||||||
// FactoryImpl makes patch transformer and name hash transformer
|
|
||||||
type FactoryImpl struct{}
|
|
||||||
|
|
||||||
// NewFactoryImpl makes a new factoryImpl instance
|
|
||||||
func NewFactoryImpl() *FactoryImpl {
|
|
||||||
return &FactoryImpl{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *FactoryImpl) MergePatches(patches []*resource.Resource,
|
|
||||||
rf *resource.Factory) (
|
|
||||||
resmap.ResMap, error) {
|
|
||||||
return patch.MergePatches(patches, rf)
|
|
||||||
}
|
|
||||||
25
api/internal/merge/merginator.go
Normal file
25
api/internal/merge/merginator.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
// Copyright 2020 The Kubernetes Authors.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package merge
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
|
"sigs.k8s.io/kustomize/api/resource"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Merginator implements resmap.Merginator using kyaml libs.
|
||||||
|
type Merginator struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ resmap.Merginator = (*Merginator)(nil)
|
||||||
|
|
||||||
|
func NewMerginator(_ *resource.Factory) *Merginator {
|
||||||
|
return &Merginator{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merge implements resmap.Merginator
|
||||||
|
func (m Merginator) Merge(
|
||||||
|
resources []*resource.Resource) (resmap.ResMap, error) {
|
||||||
|
panic("TODO(#Merginator): implement Merge")
|
||||||
|
}
|
||||||
4
api/internal/merge/merginator_test.go
Normal file
4
api/internal/merge/merginator_test.go
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
// Copyright 2020 The Kubernetes Authors.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package merge_test
|
||||||
@@ -9,22 +9,18 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/google/shlex"
|
"github.com/google/shlex"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"sigs.k8s.io/kustomize/api/resid"
|
"sigs.k8s.io/kustomize/api/internal/plugins/utils"
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
idAnnotation = "kustomize.config.k8s.io/id"
|
|
||||||
HashAnnotation = "kustomize.config.k8s.io/needs-hash"
|
|
||||||
BehaviorAnnotation = "kustomize.config.k8s.io/behavior"
|
|
||||||
tmpConfigFilePrefix = "kust-plugin-config-"
|
tmpConfigFilePrefix = "kust-plugin-config-"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -55,7 +51,14 @@ func (p *ExecPlugin) ErrIfNotExecutable() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if f.Mode()&0111 == 0000 {
|
// In Windows, it is not possible to determine whether a
|
||||||
|
// file is executable through file mode.
|
||||||
|
// TODO: provide for setting the executable FileMode bit on Windows
|
||||||
|
// The (fs *fileStat) Mode() (m FileMode) {} function in
|
||||||
|
// https://golang.org/src/os/types_windows.go
|
||||||
|
// lacks the ability to set the FileMode executable bit in response
|
||||||
|
// to file data on Windows.
|
||||||
|
if f.Mode()&0111 == 0000 && runtime.GOOS != "windows" {
|
||||||
return fmt.Errorf("unexecutable plugin at: %s", p.path)
|
return fmt.Errorf("unexecutable plugin at: %s", p.path)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -114,12 +117,12 @@ func (p *ExecPlugin) Generate() (resmap.ResMap, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return p.UpdateResourceOptions(rm)
|
return utils.UpdateResourceOptions(rm)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ExecPlugin) Transform(rm resmap.ResMap) error {
|
func (p *ExecPlugin) Transform(rm resmap.ResMap) error {
|
||||||
// add ResIds as annotations to all objects so that we can add them back
|
// add ResIds as annotations to all objects so that we can add them back
|
||||||
inputRM, err := p.getResMapWithIdAnnotation(rm)
|
inputRM, err := utils.GetResMapWithIDAnnotation(rm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -137,7 +140,7 @@ func (p *ExecPlugin) Transform(rm resmap.ResMap) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update the original ResMap based on the output
|
// update the original ResMap based on the output
|
||||||
return p.updateResMapValues(output, rm)
|
return utils.UpdateResMapValues(p.path, p.h, output, rm)
|
||||||
}
|
}
|
||||||
|
|
||||||
// invokePlugin writes plugin config to a temp file, then
|
// invokePlugin writes plugin config to a temp file, then
|
||||||
@@ -184,91 +187,3 @@ func (p *ExecPlugin) getEnv() []string {
|
|||||||
"KUSTOMIZE_PLUGIN_CONFIG_ROOT="+p.h.Loader().Root())
|
"KUSTOMIZE_PLUGIN_CONFIG_ROOT="+p.h.Loader().Root())
|
||||||
return env
|
return env
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a new copy of the given ResMap with the ResIds annotated in each Resource
|
|
||||||
func (p *ExecPlugin) getResMapWithIdAnnotation(rm resmap.ResMap) (resmap.ResMap, error) {
|
|
||||||
inputRM := rm.DeepCopy()
|
|
||||||
for _, r := range inputRM.Resources() {
|
|
||||||
idString, err := yaml.Marshal(r.CurId())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
annotations := r.GetAnnotations()
|
|
||||||
if annotations == nil {
|
|
||||||
annotations = make(map[string]string)
|
|
||||||
}
|
|
||||||
annotations[idAnnotation] = string(idString)
|
|
||||||
r.SetAnnotations(annotations)
|
|
||||||
}
|
|
||||||
return inputRM, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// updateResMapValues updates the Resource value in the given ResMap
|
|
||||||
// with the emitted Resource values in output.
|
|
||||||
func (p *ExecPlugin) updateResMapValues(output []byte, rm resmap.ResMap) error {
|
|
||||||
outputRM, err := p.h.ResmapFactory().NewResMapFromBytes(output)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for _, r := range outputRM.Resources() {
|
|
||||||
// for each emitted Resource, find the matching Resource in the original ResMap
|
|
||||||
// using its id
|
|
||||||
annotations := r.GetAnnotations()
|
|
||||||
idString, ok := annotations[idAnnotation]
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("the transformer %s should not remove annotation %s",
|
|
||||||
p.path, idAnnotation)
|
|
||||||
}
|
|
||||||
id := resid.ResId{}
|
|
||||||
err := yaml.Unmarshal([]byte(idString), &id)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
res, err := rm.GetByCurrentId(id)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("unable to find unique match to %s", id.String())
|
|
||||||
}
|
|
||||||
// remove the annotation set by Kustomize to track the resource
|
|
||||||
delete(annotations, idAnnotation)
|
|
||||||
if len(annotations) == 0 {
|
|
||||||
annotations = nil
|
|
||||||
}
|
|
||||||
r.SetAnnotations(annotations)
|
|
||||||
|
|
||||||
// update the ResMap resource value with the transformed object
|
|
||||||
res.Kunstructured = r.Kunstructured
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// updateResourceOptions updates the generator options for each resource in the
|
|
||||||
// given ResMap based on plugin provided annotations.
|
|
||||||
func (p *ExecPlugin) UpdateResourceOptions(rm resmap.ResMap) (resmap.ResMap, error) {
|
|
||||||
for _, r := range rm.Resources() {
|
|
||||||
// Disable name hashing by default and require plugin to explicitly
|
|
||||||
// request it for each resource.
|
|
||||||
annotations := r.GetAnnotations()
|
|
||||||
behavior := annotations[BehaviorAnnotation]
|
|
||||||
var needsHash bool
|
|
||||||
if val, ok := annotations[HashAnnotation]; ok {
|
|
||||||
b, err := strconv.ParseBool(val)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf(
|
|
||||||
"the annotation %q contains an invalid value (%q)",
|
|
||||||
HashAnnotation, val)
|
|
||||||
}
|
|
||||||
needsHash = b
|
|
||||||
}
|
|
||||||
delete(annotations, HashAnnotation)
|
|
||||||
delete(annotations, BehaviorAnnotation)
|
|
||||||
if len(annotations) == 0 {
|
|
||||||
annotations = nil
|
|
||||||
}
|
|
||||||
r.SetAnnotations(annotations)
|
|
||||||
r.SetOptions(types.NewGenArgs(
|
|
||||||
&types.GeneratorArgs{
|
|
||||||
Behavior: behavior,
|
|
||||||
Options: &types.GeneratorOptions{DisableNameSuffixHash: !needsHash}}))
|
|
||||||
}
|
|
||||||
return rm, nil
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -4,20 +4,21 @@
|
|||||||
package execplugin_test
|
package execplugin_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/filesys"
|
"sigs.k8s.io/kustomize/api/filesys"
|
||||||
. "sigs.k8s.io/kustomize/api/internal/plugins/execplugin"
|
. "sigs.k8s.io/kustomize/api/internal/plugins/execplugin"
|
||||||
pLdr "sigs.k8s.io/kustomize/api/internal/plugins/loader"
|
pLdr "sigs.k8s.io/kustomize/api/internal/plugins/loader"
|
||||||
|
"sigs.k8s.io/kustomize/api/internal/plugins/utils"
|
||||||
"sigs.k8s.io/kustomize/api/k8sdeps/kunstruct"
|
"sigs.k8s.io/kustomize/api/k8sdeps/kunstruct"
|
||||||
"sigs.k8s.io/kustomize/api/konfig"
|
"sigs.k8s.io/kustomize/api/konfig"
|
||||||
fLdr "sigs.k8s.io/kustomize/api/loader"
|
fLdr "sigs.k8s.io/kustomize/api/loader"
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
"sigs.k8s.io/kustomize/api/resource"
|
"sigs.k8s.io/kustomize/api/resource"
|
||||||
valtest_test "sigs.k8s.io/kustomize/api/testutils/valtest"
|
valtest_test "sigs.k8s.io/kustomize/api/testutils/valtest"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestExecPluginConfig(t *testing.T) {
|
func TestExecPluginConfig(t *testing.T) {
|
||||||
@@ -92,106 +93,31 @@ metadata:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeConfigMap(rf *resource.Factory, name, behavior string, hashValue *string) *resource.Resource {
|
func TestExecPlugin_ErrIfNotExecutable(t *testing.T) {
|
||||||
r := rf.FromMap(map[string]interface{}{
|
if runtime.GOOS == "windows" {
|
||||||
"apiVersion": "v1",
|
t.Skipf("always returns nil on Windows")
|
||||||
"kind": "ConfigMap",
|
|
||||||
"metadata": map[string]interface{}{"name": name},
|
|
||||||
})
|
|
||||||
annotations := map[string]string{}
|
|
||||||
if behavior != "" {
|
|
||||||
annotations[BehaviorAnnotation] = behavior
|
|
||||||
}
|
}
|
||||||
if hashValue != nil {
|
|
||||||
annotations[HashAnnotation] = *hashValue
|
|
||||||
}
|
|
||||||
if len(annotations) > 0 {
|
|
||||||
r.SetAnnotations(annotations)
|
|
||||||
}
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeConfigMapOptions(rf *resource.Factory, name, behavior string, disableHash bool) *resource.Resource {
|
srcRoot, err := utils.DeterminePluginSrcRoot(filesys.MakeFsOnDisk())
|
||||||
return rf.FromMapAndOption(map[string]interface{}{
|
|
||||||
"apiVersion": "v1",
|
|
||||||
"kind": "ConfigMap",
|
|
||||||
"metadata": map[string]interface{}{"name": name},
|
|
||||||
}, &types.GeneratorArgs{
|
|
||||||
Behavior: behavior,
|
|
||||||
Options: &types.GeneratorOptions{DisableNameSuffixHash: disableHash}})
|
|
||||||
}
|
|
||||||
|
|
||||||
func strptr(s string) *string {
|
|
||||||
return &s
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestUpdateResourceOptions(t *testing.T) {
|
|
||||||
p := NewExecPlugin("")
|
|
||||||
if err := p.ErrIfNotExecutable(); err == nil {
|
|
||||||
t.Fatalf("expected unexecutable error")
|
|
||||||
}
|
|
||||||
rf := resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())
|
|
||||||
in := resmap.New()
|
|
||||||
expected := resmap.New()
|
|
||||||
cases := []struct {
|
|
||||||
behavior string
|
|
||||||
needsHash bool
|
|
||||||
hashValue *string
|
|
||||||
}{
|
|
||||||
{hashValue: strptr("false")},
|
|
||||||
{hashValue: strptr("true"), needsHash: true},
|
|
||||||
{behavior: "replace"},
|
|
||||||
{behavior: "merge"},
|
|
||||||
{behavior: "create"},
|
|
||||||
{behavior: "nonsense"},
|
|
||||||
{behavior: "merge", hashValue: strptr("false")},
|
|
||||||
{behavior: "merge", hashValue: strptr("true"), needsHash: true},
|
|
||||||
}
|
|
||||||
for i, c := range cases {
|
|
||||||
name := fmt.Sprintf("test%d", i)
|
|
||||||
in.Append(makeConfigMap(rf, name, c.behavior, c.hashValue))
|
|
||||||
expected.Append(makeConfigMapOptions(rf, name, c.behavior, !c.needsHash))
|
|
||||||
}
|
|
||||||
actual, err := p.UpdateResourceOptions(in)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err.Error())
|
t.Error(err)
|
||||||
}
|
}
|
||||||
for i, a := range expected.Resources() {
|
|
||||||
b := actual.GetByIndex(i)
|
|
||||||
if b == nil {
|
|
||||||
t.Fatalf("resource %d missing from processed map", i)
|
|
||||||
}
|
|
||||||
if !a.Equals(b) {
|
|
||||||
t.Errorf("expected %v got %v", a, b)
|
|
||||||
}
|
|
||||||
if a.NeedHashSuffix() != b.NeedHashSuffix() {
|
|
||||||
t.Errorf("")
|
|
||||||
}
|
|
||||||
if a.Behavior() != b.Behavior() {
|
|
||||||
t.Errorf("expected %v got %v", a.Behavior(), b.Behavior())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestUpdateResourceOptionsWithInvalidHashAnnotationValues(t *testing.T) {
|
// Test unexecutable plugin
|
||||||
p := NewExecPlugin("")
|
unexecutablePlugin := filepath.Join(
|
||||||
if err := p.ErrIfNotExecutable(); err == nil {
|
srcRoot, "builtin", "", "secretgenerator", "SecretGenerator.so")
|
||||||
t.Fatalf("expected unexecutable error")
|
p := NewExecPlugin(unexecutablePlugin)
|
||||||
|
err = p.ErrIfNotExecutable()
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("unexpected err: %v", err)
|
||||||
}
|
}
|
||||||
rf := resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())
|
|
||||||
cases := []string{
|
// Test executable plugin
|
||||||
"",
|
executablePlugin := filepath.Join(
|
||||||
"FaLsE",
|
srcRoot, "someteam.example.com", "v1", "bashedconfigmap", "BashedConfigMap")
|
||||||
"TrUe",
|
p = NewExecPlugin(executablePlugin)
|
||||||
"potato",
|
err = p.ErrIfNotExecutable()
|
||||||
}
|
if err != nil {
|
||||||
for i, c := range cases {
|
t.Fatalf("unexpected err: %v", err)
|
||||||
name := fmt.Sprintf("test%d", i)
|
|
||||||
in := resmap.New()
|
|
||||||
in.Append(makeConfigMap(rf, name, "", &c))
|
|
||||||
_, err := p.UpdateResourceOptions(in)
|
|
||||||
if err == nil {
|
|
||||||
t.Errorf("expected error from value %q", c)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
197
api/internal/plugins/fnplugin/fnplugin.go
Normal file
197
api/internal/plugins/fnplugin/fnplugin.go
Normal file
@@ -0,0 +1,197 @@
|
|||||||
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package fnplugin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
|
"sigs.k8s.io/kustomize/api/internal/plugins/utils"
|
||||||
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
|
"sigs.k8s.io/kustomize/api/resource"
|
||||||
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/fn/runtime/runtimeutil"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/runfn"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FnPlugin is the struct to hold function information
|
||||||
|
type FnPlugin struct {
|
||||||
|
// Function runner
|
||||||
|
runFns runfn.RunFns
|
||||||
|
|
||||||
|
// Plugin configuration data.
|
||||||
|
cfg []byte
|
||||||
|
|
||||||
|
// Plugin name cache for error output
|
||||||
|
pluginName string
|
||||||
|
|
||||||
|
// PluginHelpers
|
||||||
|
h *resmap.PluginHelpers
|
||||||
|
}
|
||||||
|
|
||||||
|
func bytesToRNode(yml []byte) (*yaml.RNode, error) {
|
||||||
|
rnode, err := yaml.Parse(string(yml))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return rnode, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func resourceToRNode(res *resource.Resource) (*yaml.RNode, error) {
|
||||||
|
yml, err := res.AsYAML()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return bytesToRNode(yml)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetFunctionSpec return function spec is there is. Otherwise return nil
|
||||||
|
func GetFunctionSpec(res *resource.Resource) *runtimeutil.FunctionSpec {
|
||||||
|
rnode, err := resourceToRNode(res)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return runtimeutil.GetFunctionSpec(rnode)
|
||||||
|
}
|
||||||
|
|
||||||
|
func toStorageMounts(mounts []string) []runtimeutil.StorageMount {
|
||||||
|
var sms []runtimeutil.StorageMount
|
||||||
|
for _, mount := range mounts {
|
||||||
|
sms = append(sms, runtimeutil.StringToStorageMount(mount))
|
||||||
|
}
|
||||||
|
return sms
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewFnPlugin creates a FnPlugin struct
|
||||||
|
func NewFnPlugin(o *types.FnPluginLoadingOptions) *FnPlugin {
|
||||||
|
return &FnPlugin{
|
||||||
|
runFns: runfn.RunFns{
|
||||||
|
Functions: []*yaml.RNode{},
|
||||||
|
Network: o.Network,
|
||||||
|
EnableStarlark: o.EnableStar,
|
||||||
|
EnableExec: o.EnableExec,
|
||||||
|
StorageMounts: toStorageMounts(o.Mounts),
|
||||||
|
Env: o.Env,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cfg returns function config
|
||||||
|
func (p *FnPlugin) Cfg() []byte {
|
||||||
|
return p.cfg
|
||||||
|
}
|
||||||
|
|
||||||
|
// Config is called by kustomize to pass-in config information
|
||||||
|
func (p *FnPlugin) Config(h *resmap.PluginHelpers, config []byte) error {
|
||||||
|
p.h = h
|
||||||
|
p.cfg = config
|
||||||
|
|
||||||
|
fn, err := bytesToRNode(p.cfg)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
meta, err := fn.GetMeta()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
p.pluginName = fmt.Sprintf("api: %s, kind: %s, name: %s",
|
||||||
|
meta.APIVersion, meta.Kind, meta.Name)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate is called when run as generator
|
||||||
|
func (p *FnPlugin) Generate() (resmap.ResMap, error) {
|
||||||
|
output, err := p.invokePlugin(nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
rm, err := p.h.ResmapFactory().NewResMapFromBytes(output)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return utils.UpdateResourceOptions(rm)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Transform is called when run as transformer
|
||||||
|
func (p *FnPlugin) Transform(rm resmap.ResMap) error {
|
||||||
|
// add ResIds as annotations to all objects so that we can add them back
|
||||||
|
inputRM, err := utils.GetResMapWithIDAnnotation(rm)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// encode the ResMap so it can be fed to the plugin
|
||||||
|
resources, err := inputRM.AsYaml()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// invoke the plugin with resources as the input
|
||||||
|
output, err := p.invokePlugin(resources)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("%v %s", err, string(output))
|
||||||
|
}
|
||||||
|
|
||||||
|
// update the original ResMap based on the output
|
||||||
|
return utils.UpdateResMapValues(p.pluginName, p.h, output, rm)
|
||||||
|
}
|
||||||
|
|
||||||
|
func injectAnnotation(input *yaml.RNode, k, v string) error {
|
||||||
|
err := input.PipeE(yaml.SetAnnotation(k, v))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// invokePlugin uses Function runner to run function as plugin
|
||||||
|
func (p *FnPlugin) invokePlugin(input []byte) ([]byte, error) {
|
||||||
|
// get function config rnode
|
||||||
|
functionConfig, err := bytesToRNode(p.cfg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// This annotation will let kustomize ingnore this item in output
|
||||||
|
err = injectAnnotation(functionConfig, "config.kubernetes.io/local-config", "true")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// we need to add config as input for generators. Some of them don't work with FunctionConfig
|
||||||
|
// and in addition kio.Pipeline won't create anything if there are no objects
|
||||||
|
// see https://github.com/kubernetes-sigs/kustomize/blob/master/kyaml/kio/kio.go#L93
|
||||||
|
// Since we added `local-config` annotation so it will be ignored in generator output
|
||||||
|
// TODO(donnyxia): This is actually not used by generator and only used to bypass a kio limitation.
|
||||||
|
// Need better solution.
|
||||||
|
if input == nil {
|
||||||
|
yml, err := functionConfig.String()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
input = []byte(yml)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configure and Execute Fn. We don't need to convert resources to ResourceList here
|
||||||
|
// because function runtime will do that. See kyaml/fn/runtime/runtimeutil/runtimeutil.go
|
||||||
|
var ouputBuffer bytes.Buffer
|
||||||
|
p.runFns.Input = bytes.NewReader(input)
|
||||||
|
p.runFns.Functions = append(p.runFns.Functions, functionConfig)
|
||||||
|
p.runFns.Output = &ouputBuffer
|
||||||
|
|
||||||
|
err = p.runFns.Execute()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(
|
||||||
|
err, "couldn't execute function")
|
||||||
|
}
|
||||||
|
|
||||||
|
return ouputBuffer.Bytes(), nil
|
||||||
|
}
|
||||||
@@ -16,6 +16,7 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/api/ifc"
|
"sigs.k8s.io/kustomize/api/ifc"
|
||||||
"sigs.k8s.io/kustomize/api/internal/plugins/builtinhelpers"
|
"sigs.k8s.io/kustomize/api/internal/plugins/builtinhelpers"
|
||||||
"sigs.k8s.io/kustomize/api/internal/plugins/execplugin"
|
"sigs.k8s.io/kustomize/api/internal/plugins/execplugin"
|
||||||
|
"sigs.k8s.io/kustomize/api/internal/plugins/fnplugin"
|
||||||
"sigs.k8s.io/kustomize/api/internal/plugins/utils"
|
"sigs.k8s.io/kustomize/api/internal/plugins/utils"
|
||||||
"sigs.k8s.io/kustomize/api/konfig"
|
"sigs.k8s.io/kustomize/api/konfig"
|
||||||
"sigs.k8s.io/kustomize/api/resid"
|
"sigs.k8s.io/kustomize/api/resid"
|
||||||
@@ -116,7 +117,7 @@ func (l *Loader) loadAndConfigurePlugin(
|
|||||||
if isBuiltinPlugin(res) {
|
if isBuiltinPlugin(res) {
|
||||||
switch l.pc.BpLoadingOptions {
|
switch l.pc.BpLoadingOptions {
|
||||||
case types.BploLoadFromFileSys:
|
case types.BploLoadFromFileSys:
|
||||||
c, err = l.loadPlugin(res.OrgId())
|
c, err = l.loadPlugin(res)
|
||||||
case types.BploUseStaticallyLinked:
|
case types.BploUseStaticallyLinked:
|
||||||
// Instead of looking for and loading a .so file,
|
// Instead of looking for and loading a .so file,
|
||||||
// instantiate the plugin from a generated factory
|
// instantiate the plugin from a generated factory
|
||||||
@@ -131,7 +132,7 @@ func (l *Loader) loadAndConfigurePlugin(
|
|||||||
} else {
|
} else {
|
||||||
switch l.pc.PluginRestrictions {
|
switch l.pc.PluginRestrictions {
|
||||||
case types.PluginRestrictionsNone:
|
case types.PluginRestrictionsNone:
|
||||||
c, err = l.loadPlugin(res.OrgId())
|
c, err = l.loadPlugin(res)
|
||||||
case types.PluginRestrictionsBuiltinsOnly:
|
case types.PluginRestrictionsBuiltinsOnly:
|
||||||
err = types.NewErrOnlyBuiltinPluginsAllowed(res.OrgId().Kind)
|
err = types.NewErrOnlyBuiltinPluginsAllowed(res.OrgId().Kind)
|
||||||
default:
|
default:
|
||||||
@@ -166,7 +167,15 @@ func (l *Loader) makeBuiltinPlugin(r resid.Gvk) (resmap.Configurable, error) {
|
|||||||
return nil, errors.Errorf("unable to load builtin %s", r)
|
return nil, errors.Errorf("unable to load builtin %s", r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Loader) loadPlugin(resId resid.ResId) (resmap.Configurable, error) {
|
func (l *Loader) loadPlugin(res *resource.Resource) (resmap.Configurable, error) {
|
||||||
|
spec := fnplugin.GetFunctionSpec(res)
|
||||||
|
if spec != nil {
|
||||||
|
return fnplugin.NewFnPlugin(&l.pc.FnpLoadingOptions), nil
|
||||||
|
}
|
||||||
|
return l.loadExecOrGoPlugin(res.OrgId())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *Loader) loadExecOrGoPlugin(resId resid.ResId) (resmap.Configurable, error) {
|
||||||
// First try to load the plugin as an executable.
|
// First try to load the plugin as an executable.
|
||||||
p := execplugin.NewExecPlugin(l.absolutePluginPath(resId))
|
p := execplugin.NewExecPlugin(l.absolutePluginPath(resId))
|
||||||
err := p.ErrIfNotExecutable()
|
err := p.ErrIfNotExecutable()
|
||||||
|
|||||||
@@ -65,8 +65,8 @@ func TestLoader(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
for _, behavior := range []types.BuiltinPluginLoadingOptions{
|
for _, behavior := range []types.BuiltinPluginLoadingOptions{
|
||||||
types.BploUseStaticallyLinked,
|
/* types.BploUseStaticallyLinked,
|
||||||
types.BploLoadFromFileSys} {
|
types.BploLoadFromFileSys */} {
|
||||||
c, err := konfig.EnabledPluginConfig(behavior)
|
c, err := konfig.EnabledPluginConfig(behavior)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
@@ -4,13 +4,25 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/filesys"
|
"sigs.k8s.io/kustomize/api/filesys"
|
||||||
"sigs.k8s.io/kustomize/api/konfig"
|
"sigs.k8s.io/kustomize/api/konfig"
|
||||||
|
"sigs.k8s.io/kustomize/api/resid"
|
||||||
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
|
"sigs.k8s.io/yaml"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
idAnnotation = "kustomize.config.k8s.io/id"
|
||||||
|
HashAnnotation = "kustomize.config.k8s.io/needs-hash"
|
||||||
|
BehaviorAnnotation = "kustomize.config.k8s.io/behavior"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GoBin() string {
|
func GoBin() string {
|
||||||
@@ -113,3 +125,91 @@ func FileExists(path string) bool {
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetResMapWithIDAnnotation returns a new copy of the given ResMap with the ResIds annotated in each Resource
|
||||||
|
func GetResMapWithIDAnnotation(rm resmap.ResMap) (resmap.ResMap, error) {
|
||||||
|
inputRM := rm.DeepCopy()
|
||||||
|
for _, r := range inputRM.Resources() {
|
||||||
|
idString, err := yaml.Marshal(r.CurId())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
annotations := r.GetAnnotations()
|
||||||
|
if annotations == nil {
|
||||||
|
annotations = make(map[string]string)
|
||||||
|
}
|
||||||
|
annotations[idAnnotation] = string(idString)
|
||||||
|
r.SetAnnotations(annotations)
|
||||||
|
}
|
||||||
|
return inputRM, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateResMapValues updates the Resource value in the given ResMap
|
||||||
|
// with the emitted Resource values in output.
|
||||||
|
func UpdateResMapValues(pluginName string, h *resmap.PluginHelpers, output []byte, rm resmap.ResMap) error {
|
||||||
|
outputRM, err := h.ResmapFactory().NewResMapFromBytes(output)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, r := range outputRM.Resources() {
|
||||||
|
// for each emitted Resource, find the matching Resource in the original ResMap
|
||||||
|
// using its id
|
||||||
|
annotations := r.GetAnnotations()
|
||||||
|
idString, ok := annotations[idAnnotation]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("the transformer %s should not remove annotation %s",
|
||||||
|
pluginName, idAnnotation)
|
||||||
|
}
|
||||||
|
id := resid.ResId{}
|
||||||
|
err := yaml.Unmarshal([]byte(idString), &id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
res, err := rm.GetByCurrentId(id)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to find unique match to %s", id.String())
|
||||||
|
}
|
||||||
|
// remove the annotation set by Kustomize to track the resource
|
||||||
|
delete(annotations, idAnnotation)
|
||||||
|
if len(annotations) == 0 {
|
||||||
|
annotations = nil
|
||||||
|
}
|
||||||
|
r.SetAnnotations(annotations)
|
||||||
|
|
||||||
|
// update the resource value with the transformed object
|
||||||
|
res.ResetPrimaryData(r)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateResourceOptions updates the generator options for each resource in the
|
||||||
|
// given ResMap based on plugin provided annotations.
|
||||||
|
func UpdateResourceOptions(rm resmap.ResMap) (resmap.ResMap, error) {
|
||||||
|
for _, r := range rm.Resources() {
|
||||||
|
// Disable name hashing by default and require plugin to explicitly
|
||||||
|
// request it for each resource.
|
||||||
|
annotations := r.GetAnnotations()
|
||||||
|
behavior := annotations[BehaviorAnnotation]
|
||||||
|
var needsHash bool
|
||||||
|
if val, ok := annotations[HashAnnotation]; ok {
|
||||||
|
b, err := strconv.ParseBool(val)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf(
|
||||||
|
"the annotation %q contains an invalid value (%q)",
|
||||||
|
HashAnnotation, val)
|
||||||
|
}
|
||||||
|
needsHash = b
|
||||||
|
}
|
||||||
|
delete(annotations, HashAnnotation)
|
||||||
|
delete(annotations, BehaviorAnnotation)
|
||||||
|
if len(annotations) == 0 {
|
||||||
|
annotations = nil
|
||||||
|
}
|
||||||
|
r.SetAnnotations(annotations)
|
||||||
|
r.SetOptions(types.NewGenArgs(
|
||||||
|
&types.GeneratorArgs{
|
||||||
|
Behavior: behavior,
|
||||||
|
Options: &types.GeneratorOptions{DisableNameSuffixHash: !needsHash}}))
|
||||||
|
}
|
||||||
|
return rm, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,12 +4,17 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/filesys"
|
"sigs.k8s.io/kustomize/api/filesys"
|
||||||
|
"sigs.k8s.io/kustomize/api/k8sdeps/kunstruct"
|
||||||
"sigs.k8s.io/kustomize/api/konfig"
|
"sigs.k8s.io/kustomize/api/konfig"
|
||||||
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
|
"sigs.k8s.io/kustomize/api/resource"
|
||||||
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDeterminePluginSrcRoot(t *testing.T) {
|
func TestDeterminePluginSrcRoot(t *testing.T) {
|
||||||
@@ -24,3 +29,99 @@ func TestDeterminePluginSrcRoot(t *testing.T) {
|
|||||||
t.Errorf("expected suffix '%s' in '%s'", konfig.RelPluginHome, actual)
|
t.Errorf("expected suffix '%s' in '%s'", konfig.RelPluginHome, actual)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func makeConfigMap(rf *resource.Factory, name, behavior string, hashValue *string) *resource.Resource {
|
||||||
|
r := rf.FromMap(map[string]interface{}{
|
||||||
|
"apiVersion": "v1",
|
||||||
|
"kind": "ConfigMap",
|
||||||
|
"metadata": map[string]interface{}{"name": name},
|
||||||
|
})
|
||||||
|
annotations := map[string]string{}
|
||||||
|
if behavior != "" {
|
||||||
|
annotations[BehaviorAnnotation] = behavior
|
||||||
|
}
|
||||||
|
if hashValue != nil {
|
||||||
|
annotations[HashAnnotation] = *hashValue
|
||||||
|
}
|
||||||
|
if len(annotations) > 0 {
|
||||||
|
r.SetAnnotations(annotations)
|
||||||
|
}
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeConfigMapOptions(rf *resource.Factory, name, behavior string, disableHash bool) *resource.Resource {
|
||||||
|
return rf.FromMapAndOption(map[string]interface{}{
|
||||||
|
"apiVersion": "v1",
|
||||||
|
"kind": "ConfigMap",
|
||||||
|
"metadata": map[string]interface{}{"name": name},
|
||||||
|
}, &types.GeneratorArgs{
|
||||||
|
Behavior: behavior,
|
||||||
|
Options: &types.GeneratorOptions{DisableNameSuffixHash: disableHash}})
|
||||||
|
}
|
||||||
|
|
||||||
|
func strptr(s string) *string {
|
||||||
|
return &s
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUpdateResourceOptions(t *testing.T) {
|
||||||
|
rf := resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())
|
||||||
|
in := resmap.New()
|
||||||
|
expected := resmap.New()
|
||||||
|
cases := []struct {
|
||||||
|
behavior string
|
||||||
|
needsHash bool
|
||||||
|
hashValue *string
|
||||||
|
}{
|
||||||
|
{hashValue: strptr("false")},
|
||||||
|
{hashValue: strptr("true"), needsHash: true},
|
||||||
|
{behavior: "replace"},
|
||||||
|
{behavior: "merge"},
|
||||||
|
{behavior: "create"},
|
||||||
|
{behavior: "nonsense"},
|
||||||
|
{behavior: "merge", hashValue: strptr("false")},
|
||||||
|
{behavior: "merge", hashValue: strptr("true"), needsHash: true},
|
||||||
|
}
|
||||||
|
for i, c := range cases {
|
||||||
|
name := fmt.Sprintf("test%d", i)
|
||||||
|
in.Append(makeConfigMap(rf, name, c.behavior, c.hashValue))
|
||||||
|
expected.Append(makeConfigMapOptions(rf, name, c.behavior, !c.needsHash))
|
||||||
|
}
|
||||||
|
actual, err := UpdateResourceOptions(in)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err.Error())
|
||||||
|
}
|
||||||
|
for i, a := range expected.Resources() {
|
||||||
|
b := actual.GetByIndex(i)
|
||||||
|
if b == nil {
|
||||||
|
t.Fatalf("resource %d missing from processed map", i)
|
||||||
|
}
|
||||||
|
if !a.Equals(b) {
|
||||||
|
t.Errorf("expected %v got %v", a, b)
|
||||||
|
}
|
||||||
|
if a.NeedHashSuffix() != b.NeedHashSuffix() {
|
||||||
|
t.Errorf("")
|
||||||
|
}
|
||||||
|
if a.Behavior() != b.Behavior() {
|
||||||
|
t.Errorf("expected %v got %v", a.Behavior(), b.Behavior())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUpdateResourceOptionsWithInvalidHashAnnotationValues(t *testing.T) {
|
||||||
|
rf := resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())
|
||||||
|
cases := []string{
|
||||||
|
"",
|
||||||
|
"FaLsE",
|
||||||
|
"TrUe",
|
||||||
|
"potato",
|
||||||
|
}
|
||||||
|
for i, c := range cases {
|
||||||
|
name := fmt.Sprintf("test%d", i)
|
||||||
|
in := resmap.New()
|
||||||
|
in.Append(makeConfigMap(rf, name, "", &c))
|
||||||
|
_, err := UpdateResourceOptions(in)
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("expected error from value %q", c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
package target
|
package target
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -18,7 +17,6 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/api/internal/plugins/loader"
|
"sigs.k8s.io/kustomize/api/internal/plugins/loader"
|
||||||
"sigs.k8s.io/kustomize/api/konfig"
|
"sigs.k8s.io/kustomize/api/konfig"
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
"sigs.k8s.io/kustomize/api/transform"
|
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
@@ -29,7 +27,6 @@ type KustTarget struct {
|
|||||||
ldr ifc.Loader
|
ldr ifc.Loader
|
||||||
validator ifc.Validator
|
validator ifc.Validator
|
||||||
rFactory *resmap.Factory
|
rFactory *resmap.Factory
|
||||||
tFactory resmap.PatchFactory
|
|
||||||
pLdr *loader.Loader
|
pLdr *loader.Loader
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,13 +35,11 @@ func NewKustTarget(
|
|||||||
ldr ifc.Loader,
|
ldr ifc.Loader,
|
||||||
validator ifc.Validator,
|
validator ifc.Validator,
|
||||||
rFactory *resmap.Factory,
|
rFactory *resmap.Factory,
|
||||||
tFactory resmap.PatchFactory,
|
|
||||||
pLdr *loader.Loader) *KustTarget {
|
pLdr *loader.Loader) *KustTarget {
|
||||||
return &KustTarget{
|
return &KustTarget{
|
||||||
ldr: ldr,
|
ldr: ldr,
|
||||||
validator: validator,
|
validator: validator,
|
||||||
rFactory: rFactory,
|
rFactory: rFactory,
|
||||||
tFactory: tFactory,
|
|
||||||
pLdr: pLdr,
|
pLdr: pLdr,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -60,7 +55,7 @@ func (kt *KustTarget) Load() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var k types.Kustomization
|
var k types.Kustomization
|
||||||
err = unmarshal(content, &k)
|
err = k.Unmarshal(content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -104,18 +99,8 @@ func loadKustFile(ldr ifc.Loader) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func unmarshal(y []byte, o interface{}) error {
|
|
||||||
j, err := yaml.YAMLToJSON(y)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
dec := json.NewDecoder(bytes.NewReader(j))
|
|
||||||
dec.DisallowUnknownFields()
|
|
||||||
return dec.Decode(o)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MakeCustomizedResMap creates a fully customized ResMap
|
// MakeCustomizedResMap creates a fully customized ResMap
|
||||||
// per the instructions contained in its kustomiztion instance.
|
// per the instructions contained in its kustomization instance.
|
||||||
func (kt *KustTarget) MakeCustomizedResMap() (resmap.ResMap, error) {
|
func (kt *KustTarget) MakeCustomizedResMap() (resmap.ResMap, error) {
|
||||||
return kt.makeCustomizedResMap()
|
return kt.makeCustomizedResMap()
|
||||||
}
|
}
|
||||||
@@ -166,11 +151,21 @@ func (kt *KustTarget) addHashesToNames(
|
|||||||
// not yet fixed.
|
// not yet fixed.
|
||||||
func (kt *KustTarget) AccumulateTarget() (
|
func (kt *KustTarget) AccumulateTarget() (
|
||||||
ra *accumulator.ResAccumulator, err error) {
|
ra *accumulator.ResAccumulator, err error) {
|
||||||
ra = accumulator.MakeEmptyAccumulator()
|
return kt.accumulateTarget(accumulator.MakeEmptyAccumulator())
|
||||||
err = kt.accumulateResources(ra, kt.kustomization.Resources)
|
}
|
||||||
|
|
||||||
|
// ra should be empty when this KustTarget is a Kustomization, or the ra of the parent if this KustTarget is a Component
|
||||||
|
// (or empty if the Component does not have a parent).
|
||||||
|
func (kt *KustTarget) accumulateTarget(ra *accumulator.ResAccumulator) (
|
||||||
|
resRa *accumulator.ResAccumulator, err error) {
|
||||||
|
ra, err = kt.accumulateResources(ra, kt.kustomization.Resources)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "accumulating resources")
|
return nil, errors.Wrap(err, "accumulating resources")
|
||||||
}
|
}
|
||||||
|
ra, err = kt.accumulateComponents(ra, kt.kustomization.Components)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "accumulating components")
|
||||||
|
}
|
||||||
tConfig, err := builtinconfig.MakeTransformerConfig(
|
tConfig, err := builtinconfig.MakeTransformerConfig(
|
||||||
kt.ldr, kt.kustomization.Configurations)
|
kt.ldr, kt.kustomization.Configurations)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -199,6 +194,10 @@ func (kt *KustTarget) AccumulateTarget() (
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
err = kt.runValidators(ra)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
err = ra.MergeVars(kt.kustomization.Vars)
|
err = ra.MergeVars(kt.kustomization.Vars)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(
|
return nil, errors.Wrapf(
|
||||||
@@ -235,7 +234,7 @@ func (kt *KustTarget) runGenerators(
|
|||||||
|
|
||||||
func (kt *KustTarget) configureExternalGenerators() ([]resmap.Generator, error) {
|
func (kt *KustTarget) configureExternalGenerators() ([]resmap.Generator, error) {
|
||||||
ra := accumulator.MakeEmptyAccumulator()
|
ra := accumulator.MakeEmptyAccumulator()
|
||||||
err := kt.accumulateResources(ra, kt.kustomization.Generators)
|
ra, err := kt.accumulateResources(ra, kt.kustomization.Generators)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -250,65 +249,138 @@ func (kt *KustTarget) runTransformers(ra *accumulator.ResAccumulator) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
r = append(r, lts...)
|
r = append(r, lts...)
|
||||||
lts, err = kt.configureExternalTransformers()
|
lts, err = kt.configureExternalTransformers(kt.kustomization.Transformers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
r = append(r, lts...)
|
r = append(r, lts...)
|
||||||
t := transform.NewMultiTransformer(r)
|
return ra.Transform(newMultiTransformer(r))
|
||||||
return ra.Transform(t)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (kt *KustTarget) configureExternalTransformers() ([]resmap.Transformer, error) {
|
func (kt *KustTarget) configureExternalTransformers(transformers []string) ([]resmap.Transformer, error) {
|
||||||
ra := accumulator.MakeEmptyAccumulator()
|
ra := accumulator.MakeEmptyAccumulator()
|
||||||
err := kt.accumulateResources(ra, kt.kustomization.Transformers)
|
ra, err := kt.accumulateResources(ra, transformers)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return kt.pLdr.LoadTransformers(kt.ldr, kt.validator, ra.ResMap())
|
return kt.pLdr.LoadTransformers(kt.ldr, kt.validator, ra.ResMap())
|
||||||
}
|
}
|
||||||
|
|
||||||
// accumulateResources fills the given resourceAccumulator
|
func (kt *KustTarget) runValidators(ra *accumulator.ResAccumulator) error {
|
||||||
// with resources read from the given list of paths.
|
validators, err := kt.configureExternalTransformers(kt.kustomization.Validators)
|
||||||
func (kt *KustTarget) accumulateResources(
|
if err != nil {
|
||||||
ra *accumulator.ResAccumulator, paths []string) error {
|
return err
|
||||||
for _, path := range paths {
|
}
|
||||||
// try loading resource as file then as base (directory or git repository)
|
for _, v := range validators {
|
||||||
if errF := kt.accumulateFile(ra, path); errF != nil {
|
// Validators shouldn't modify the resource map
|
||||||
ldr, errL := kt.ldr.New(path)
|
orignal := ra.ResMap().DeepCopy()
|
||||||
if errL != nil {
|
err = v.Transform(ra.ResMap())
|
||||||
return fmt.Errorf("accumulateFile %q, loader.New %q", errF, errL)
|
if err != nil {
|
||||||
}
|
return err
|
||||||
errD := kt.accumulateDirectory(ra, ldr)
|
}
|
||||||
if errD != nil {
|
new := ra.ResMap().DeepCopy()
|
||||||
return fmt.Errorf("accumulateFile %q, accumulateDirector: %q", errF, errD)
|
kt.removeValidatedByLabel(new)
|
||||||
}
|
if err = orignal.ErrorIfNotEqualSets(new); err != nil {
|
||||||
|
return fmt.Errorf("validator shouldn't modify the resource map: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (kt *KustTarget) removeValidatedByLabel(rm resmap.ResMap) {
|
||||||
|
resources := rm.Resources()
|
||||||
|
for _, r := range resources {
|
||||||
|
labels := r.GetLabels()
|
||||||
|
if _, found := labels[konfig.ValidatedByLabelKey]; !found {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
delete(labels, konfig.ValidatedByLabelKey)
|
||||||
|
if len(labels) == 0 {
|
||||||
|
r.SetLabels(nil)
|
||||||
|
} else {
|
||||||
|
r.SetLabels(labels)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// accumulateResources fills the given resourceAccumulator
|
||||||
|
// with resources read from the given list of paths.
|
||||||
|
func (kt *KustTarget) accumulateResources(
|
||||||
|
ra *accumulator.ResAccumulator, paths []string) (*accumulator.ResAccumulator, error) {
|
||||||
|
for _, path := range paths {
|
||||||
|
// try loading resource as file then as base (directory or git repository)
|
||||||
|
if errF := kt.accumulateFile(ra, path); errF != nil {
|
||||||
|
ldr, errL := kt.ldr.New(path)
|
||||||
|
if errL != nil {
|
||||||
|
return nil, fmt.Errorf("accumulateFile %q, loader.New %q", errF, errL)
|
||||||
|
}
|
||||||
|
var errD error
|
||||||
|
ra, errD = kt.accumulateDirectory(ra, ldr, false)
|
||||||
|
if errD != nil {
|
||||||
|
return nil, fmt.Errorf("accumulateFile %q, accumulateDirector: %q", errF, errD)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ra, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// accumulateResources fills the given resourceAccumulator
|
||||||
|
// with resources read from the given list of paths.
|
||||||
|
func (kt *KustTarget) accumulateComponents(
|
||||||
|
ra *accumulator.ResAccumulator, paths []string) (*accumulator.ResAccumulator, error) {
|
||||||
|
for _, path := range paths {
|
||||||
|
// Components always refer to directories
|
||||||
|
ldr, errL := kt.ldr.New(path)
|
||||||
|
if errL != nil {
|
||||||
|
return nil, fmt.Errorf("loader.New %q", errL)
|
||||||
|
}
|
||||||
|
var errD error
|
||||||
|
ra, errD = kt.accumulateDirectory(ra, ldr, true)
|
||||||
|
if errD != nil {
|
||||||
|
return nil, fmt.Errorf("accumulateDirectory: %q", errD)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ra, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (kt *KustTarget) accumulateDirectory(
|
func (kt *KustTarget) accumulateDirectory(
|
||||||
ra *accumulator.ResAccumulator, ldr ifc.Loader) error {
|
ra *accumulator.ResAccumulator, ldr ifc.Loader, isComponent bool) (*accumulator.ResAccumulator, error) {
|
||||||
defer ldr.Cleanup()
|
defer ldr.Cleanup()
|
||||||
subKt := NewKustTarget(
|
subKt := NewKustTarget(ldr, kt.validator, kt.rFactory, kt.pLdr)
|
||||||
ldr, kt.validator, kt.rFactory, kt.tFactory, kt.pLdr)
|
|
||||||
err := subKt.Load()
|
err := subKt.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(
|
return nil, errors.Wrapf(
|
||||||
err, "couldn't make target for path '%s'", ldr.Root())
|
err, "couldn't make target for path '%s'", ldr.Root())
|
||||||
}
|
}
|
||||||
subRa, err := subKt.AccumulateTarget()
|
if isComponent && subKt.kustomization.Kind != types.ComponentKind {
|
||||||
|
return nil, fmt.Errorf(
|
||||||
|
"expected kind '%s' for path '%s' but got '%s'", types.ComponentKind, ldr.Root(), subKt.kustomization.Kind)
|
||||||
|
} else if !isComponent && subKt.kustomization.Kind == types.ComponentKind {
|
||||||
|
return nil, fmt.Errorf(
|
||||||
|
"expected kind != '%s' for path '%s'", types.ComponentKind, ldr.Root())
|
||||||
|
}
|
||||||
|
|
||||||
|
var subRa *accumulator.ResAccumulator
|
||||||
|
if isComponent {
|
||||||
|
// Components don't create a new accumulator: the kustomization directives are added to the current accumulator
|
||||||
|
subRa, err = subKt.accumulateTarget(ra)
|
||||||
|
ra = accumulator.MakeEmptyAccumulator()
|
||||||
|
} else {
|
||||||
|
// Child Kustomizations create a new accumulator which resolves their kustomization directives, which will later
|
||||||
|
// be merged into the current accumulator.
|
||||||
|
subRa, err = subKt.AccumulateTarget()
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(
|
return nil, errors.Wrapf(
|
||||||
err, "recursed accumulation of path '%s'", ldr.Root())
|
err, "recursed accumulation of path '%s'", ldr.Root())
|
||||||
}
|
}
|
||||||
err = ra.MergeAccumulator(subRa)
|
err = ra.MergeAccumulator(subRa)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(
|
return nil, errors.Wrapf(
|
||||||
err, "recursed merging from path '%s'", ldr.Root())
|
err, "recursed merging from path '%s'", ldr.Root())
|
||||||
}
|
}
|
||||||
return nil
|
return ra, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (kt *KustTarget) accumulateFile(
|
func (kt *KustTarget) accumulateFile(
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ metadata:
|
|||||||
"apiVersion": "v1",
|
"apiVersion": "v1",
|
||||||
"kind": "Namespace",
|
"kind": "Namespace",
|
||||||
"metadata": map[string]interface{}{
|
"metadata": map[string]interface{}{
|
||||||
"name": "foo-ns1-bar",
|
"name": "ns1",
|
||||||
"labels": map[string]interface{}{
|
"labels": map[string]interface{}{
|
||||||
"app": "nginx",
|
"app": "nginx",
|
||||||
},
|
},
|
||||||
@@ -201,7 +201,7 @@ metadata:
|
|||||||
"apiVersion": "v1",
|
"apiVersion": "v1",
|
||||||
"kind": "ConfigMap",
|
"kind": "ConfigMap",
|
||||||
"metadata": map[string]interface{}{
|
"metadata": map[string]interface{}{
|
||||||
"name": "foo-literalConfigMap-bar-8d2dkb8k24",
|
"name": "foo-literalConfigMap-bar-g5f6t456f5",
|
||||||
"namespace": "ns1",
|
"namespace": "ns1",
|
||||||
"labels": map[string]interface{}{
|
"labels": map[string]interface{}{
|
||||||
"app": "nginx",
|
"app": "nginx",
|
||||||
@@ -220,7 +220,7 @@ metadata:
|
|||||||
"apiVersion": "v1",
|
"apiVersion": "v1",
|
||||||
"kind": "Secret",
|
"kind": "Secret",
|
||||||
"metadata": map[string]interface{}{
|
"metadata": map[string]interface{}{
|
||||||
"name": "foo-secret-bar-9btc7bt4kb",
|
"name": "foo-secret-bar-82c2g5f8f6",
|
||||||
"namespace": "ns1",
|
"namespace": "ns1",
|
||||||
"labels": map[string]interface{}{
|
"labels": map[string]interface{}{
|
||||||
"app": "nginx",
|
"app": "nginx",
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/filesys"
|
"sigs.k8s.io/kustomize/api/filesys"
|
||||||
"sigs.k8s.io/kustomize/api/internal/k8sdeps/transformer"
|
"sigs.k8s.io/kustomize/api/internal/k8sdeps/merge"
|
||||||
pLdr "sigs.k8s.io/kustomize/api/internal/plugins/loader"
|
pLdr "sigs.k8s.io/kustomize/api/internal/plugins/loader"
|
||||||
"sigs.k8s.io/kustomize/api/internal/target"
|
"sigs.k8s.io/kustomize/api/internal/target"
|
||||||
"sigs.k8s.io/kustomize/api/k8sdeps/kunstruct"
|
"sigs.k8s.io/kustomize/api/k8sdeps/kunstruct"
|
||||||
@@ -35,17 +35,17 @@ func makeKustTargetWithRf(
|
|||||||
t *testing.T,
|
t *testing.T,
|
||||||
fSys filesys.FileSystem,
|
fSys filesys.FileSystem,
|
||||||
root string,
|
root string,
|
||||||
resFact *resource.Factory) *target.KustTarget {
|
resourceFactory *resource.Factory) *target.KustTarget {
|
||||||
rf := resmap.NewFactory(resFact, transformer.NewFactoryImpl())
|
|
||||||
pc := konfig.DisabledPluginConfig()
|
|
||||||
ldr, err := fLdr.NewLoader(fLdr.RestrictionRootOnly, root, fSys)
|
ldr, err := fLdr.NewLoader(fLdr.RestrictionRootOnly, root, fSys)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
rf := resmap.NewFactory(
|
||||||
|
resourceFactory, merge.NewMerginator(resourceFactory))
|
||||||
|
pc := konfig.DisabledPluginConfig()
|
||||||
return target.NewKustTarget(
|
return target.NewKustTarget(
|
||||||
ldr,
|
ldr,
|
||||||
valtest_test.MakeFakeValidator(),
|
valtest_test.MakeFakeValidator(),
|
||||||
rf,
|
rf,
|
||||||
transformer.NewFactoryImpl(),
|
|
||||||
pLdr.NewLoader(pc, rf))
|
pLdr.NewLoader(pc, rf))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Copyright 2019 The Kubernetes Authors.
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
package transform
|
package target
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -17,8 +17,8 @@ type multiTransformer struct {
|
|||||||
|
|
||||||
var _ resmap.Transformer = &multiTransformer{}
|
var _ resmap.Transformer = &multiTransformer{}
|
||||||
|
|
||||||
// NewMultiTransformer constructs a multiTransformer.
|
// newMultiTransformer constructs a multiTransformer.
|
||||||
func NewMultiTransformer(t []resmap.Transformer) resmap.Transformer {
|
func newMultiTransformer(t []resmap.Transformer) resmap.Transformer {
|
||||||
r := &multiTransformer{
|
r := &multiTransformer{
|
||||||
transformers: make([]resmap.Transformer, len(t)),
|
transformers: make([]resmap.Transformer, len(t)),
|
||||||
checkConflictEnabled: false}
|
checkConflictEnabled: false}
|
||||||
64
api/internal/validate/fieldvalidator.go
Normal file
64
api/internal/validate/fieldvalidator.go
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
// Copyright 2020 The Kubernetes Authors.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package validate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sigs.k8s.io/kustomize/api/ifc"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FieldValidator implements ifc.Validator to check
|
||||||
|
// the values of various KRM string fields,
|
||||||
|
// e.g. labels, annotations, names, namespaces.
|
||||||
|
type FieldValidator struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ ifc.Validator = (*FieldValidator)(nil)
|
||||||
|
|
||||||
|
func NewFieldValidator() *FieldValidator {
|
||||||
|
return &FieldValidator{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(#FieldValidator): implement MakeAnnotationValidator
|
||||||
|
func (f FieldValidator) MakeAnnotationValidator() func(map[string]string) error {
|
||||||
|
return func(x map[string]string) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(#FieldValidator): implement MakeAnnotationNameValidator
|
||||||
|
func (f FieldValidator) MakeAnnotationNameValidator() func([]string) error {
|
||||||
|
return func(x []string) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(#FieldValidator): implement MakeLabelValidator
|
||||||
|
func (f FieldValidator) MakeLabelValidator() func(map[string]string) error {
|
||||||
|
return func(x map[string]string) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(#FieldValidator): implement MakeLabelNameValidator
|
||||||
|
func (f FieldValidator) MakeLabelNameValidator() func([]string) error {
|
||||||
|
return func(x []string) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(#FieldValidator): implement ValidateNamespace
|
||||||
|
func (f FieldValidator) ValidateNamespace(s string) []string {
|
||||||
|
var errs []string
|
||||||
|
return errs
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(#FieldValidator): implement ErrIfInvalidKey
|
||||||
|
func (f FieldValidator) ErrIfInvalidKey(s string) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(#FieldValidator): implement IsEnvVarName
|
||||||
|
func (f FieldValidator) IsEnvVarName(k string) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
4
api/internal/validate/fieldvalidator_test.go
Normal file
4
api/internal/validate/fieldvalidator_test.go
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
// Copyright 2020 The Kubernetes Authors.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package validate_test
|
||||||
41
api/internal/wrappy/factory.go
Normal file
41
api/internal/wrappy/factory.go
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
// Copyright 2020 The Kubernetes Authors.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package wrappy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sigs.k8s.io/kustomize/api/ifc"
|
||||||
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// WNodeFactory makes instances of WNode.
|
||||||
|
// These instances in turn adapt
|
||||||
|
// sigs.k8s.io/kustomize/kyaml/yaml.RNode
|
||||||
|
// to implement ifc.Unstructured.
|
||||||
|
// This factory is meant to implement ifc.KunstructuredFactory.
|
||||||
|
type WNodeFactory struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ ifc.KunstructuredFactory = (*WNodeFactory)(nil)
|
||||||
|
|
||||||
|
func (k *WNodeFactory) SliceFromBytes(bs []byte) ([]ifc.Kunstructured, error) {
|
||||||
|
panic("TODO(#WNodeFactory): implement SliceFromBytes")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *WNodeFactory) FromMap(m map[string]interface{}) ifc.Kunstructured {
|
||||||
|
panic("TODO(#WNodeFactory): implement FromMap")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *WNodeFactory) Hasher() ifc.KunstructuredHasher {
|
||||||
|
panic("TODO(#WNodeFactory): implement Hasher")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *WNodeFactory) MakeConfigMap(
|
||||||
|
kvLdr ifc.KvLoader, args *types.ConfigMapArgs) (ifc.Kunstructured, error) {
|
||||||
|
panic("TODO(#WNodeFactory): implement MakeConfigMap")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *WNodeFactory) MakeSecret(
|
||||||
|
kvLdr ifc.KvLoader, args *types.SecretArgs) (ifc.Kunstructured, error) {
|
||||||
|
panic("TODO(#WNodeFactory): implement MakeSecret")
|
||||||
|
}
|
||||||
4
api/internal/wrappy/factory_test.go
Normal file
4
api/internal/wrappy/factory_test.go
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
// Copyright 2020 The Kubernetes Authors.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package wrappy_test
|
||||||
143
api/internal/wrappy/wnode.go
Normal file
143
api/internal/wrappy/wnode.go
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
// Copyright 2020 The Kubernetes Authors.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package wrappy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"sigs.k8s.io/kustomize/api/ifc"
|
||||||
|
"sigs.k8s.io/kustomize/api/resid"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
|
)
|
||||||
|
|
||||||
|
// WNode implements ifc.Kunstructured using yaml.RNode.
|
||||||
|
//
|
||||||
|
// It exists only to help manage a switch from
|
||||||
|
// kunstruct.UnstructAdapter to yaml.RNode as the core
|
||||||
|
// representation of KRM objects in kustomize.
|
||||||
|
//
|
||||||
|
// It's got a silly name because we don't want it around for long,
|
||||||
|
// and want its use to be obvious.
|
||||||
|
type WNode struct {
|
||||||
|
node *yaml.RNode
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ ifc.Kunstructured = (*WNode)(nil)
|
||||||
|
|
||||||
|
func NewWNode() *WNode {
|
||||||
|
return FromRNode(yaml.NewRNode(nil))
|
||||||
|
}
|
||||||
|
|
||||||
|
func FromRNode(node *yaml.RNode) *WNode {
|
||||||
|
return &WNode{node: node}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (wn *WNode) demandMetaData(label string) yaml.ResourceMeta {
|
||||||
|
meta, err := wn.node.GetMeta()
|
||||||
|
if err != nil {
|
||||||
|
// Log and die since interface doesn't allow error.
|
||||||
|
log.Fatalf("for %s', expected valid resource: %v", label, err)
|
||||||
|
}
|
||||||
|
return meta
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy implements ifc.Kunstructured.
|
||||||
|
func (wn *WNode) Copy() ifc.Kunstructured {
|
||||||
|
return &WNode{node: wn.node.Copy()}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAnnotations implements ifc.Kunstructured.
|
||||||
|
func (wn *WNode) GetAnnotations() map[string]string {
|
||||||
|
return wn.demandMetaData("GetAnnotations").Annotations
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetFieldValue implements ifc.Kunstructured.
|
||||||
|
func (wn *WNode) GetFieldValue(path string) (interface{}, error) {
|
||||||
|
// The argument is a json path, e.g. "metadata.name"
|
||||||
|
// fields := strings.Split(path, ".")
|
||||||
|
// return wn.node.Pipe(yaml.Lookup(fields...))
|
||||||
|
panic("TODO(#WNode): GetFieldValue; implement or drop from API")
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGvk implements ifc.Kunstructured.
|
||||||
|
func (wn *WNode) GetGvk() resid.Gvk {
|
||||||
|
meta := wn.demandMetaData("GetGvk")
|
||||||
|
g, v := resid.ParseGroupVersion(meta.APIVersion)
|
||||||
|
return resid.Gvk{Group: g, Version: v, Kind: meta.Kind}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetKind implements ifc.Kunstructured.
|
||||||
|
func (wn *WNode) GetKind() string {
|
||||||
|
return wn.demandMetaData("GetKind").Kind
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetLabels implements ifc.Kunstructured.
|
||||||
|
func (wn *WNode) GetLabels() map[string]string {
|
||||||
|
return wn.demandMetaData("GetLabels").Labels
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetName implements ifc.Kunstructured.
|
||||||
|
func (wn *WNode) GetName() string {
|
||||||
|
return wn.demandMetaData("GetName").Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSlice implements ifc.Kunstructured.
|
||||||
|
func (wn *WNode) GetSlice(string) ([]interface{}, error) {
|
||||||
|
panic("TODO(#WNode) GetSlice; implement or drop from API")
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSlice implements ifc.Kunstructured.
|
||||||
|
func (wn *WNode) GetString(string) (string, error) {
|
||||||
|
panic("TODO(#WNode) GetString; implement or drop from API")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map implements ifc.Kunstructured.
|
||||||
|
func (wn *WNode) Map() map[string]interface{} {
|
||||||
|
panic("TODO(#WNode) Map; implement or drop from API")
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalJSON implements ifc.Kunstructured.
|
||||||
|
func (wn *WNode) MarshalJSON() ([]byte, error) {
|
||||||
|
return wn.node.MarshalJSON()
|
||||||
|
}
|
||||||
|
|
||||||
|
// MatchesAnnotationSelector implements ifc.Kunstructured.
|
||||||
|
func (wn *WNode) MatchesAnnotationSelector(string) (bool, error) {
|
||||||
|
panic("TODO(#WNode) MatchesAnnotationSelector; implement or drop from API")
|
||||||
|
}
|
||||||
|
|
||||||
|
// MatchesLabelSelector implements ifc.Kunstructured.
|
||||||
|
func (wn *WNode) MatchesLabelSelector(string) (bool, error) {
|
||||||
|
panic("TODO(#WNode) MatchesLabelSelector; implement or drop from API")
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAnnotations implements ifc.Kunstructured.
|
||||||
|
func (wn *WNode) SetAnnotations(map[string]string) {
|
||||||
|
panic("TODO(#WNode) SetAnnotations; implement or drop from API")
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGvk implements ifc.Kunstructured.
|
||||||
|
func (wn *WNode) SetGvk(resid.Gvk) {
|
||||||
|
panic("TODO(#WNode) SetGvk; implement or drop from API")
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLabels implements ifc.Kunstructured.
|
||||||
|
func (wn *WNode) SetLabels(map[string]string) {
|
||||||
|
panic("TODO(#WNode) SetLabels; implement or drop from API")
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetName implements ifc.Kunstructured.
|
||||||
|
func (wn *WNode) SetName(string) {
|
||||||
|
panic("TODO(#WNode) SetName; implement or drop from API")
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNamespace implements ifc.Kunstructured.
|
||||||
|
func (wn *WNode) SetNamespace(string) {
|
||||||
|
panic("TODO(#WNode) SetNamespace; implement or drop from API")
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON implements ifc.Kunstructured.
|
||||||
|
func (wn *WNode) UnmarshalJSON(data []byte) error {
|
||||||
|
return wn.node.UnmarshalJSON(data)
|
||||||
|
}
|
||||||
339
api/internal/wrappy/wnode_test.go
Normal file
339
api/internal/wrappy/wnode_test.go
Normal file
@@ -0,0 +1,339 @@
|
|||||||
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package wrappy_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
|
. "sigs.k8s.io/kustomize/api/internal/wrappy"
|
||||||
|
kyaml "sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
deploymentLittleJson = `{"apiVersion":"apps/v1","kind":"Deployment",` +
|
||||||
|
`"metadata":{"name":"homer","namespace":"simpsons"}}`
|
||||||
|
|
||||||
|
deploymentBiggerJson = `
|
||||||
|
{
|
||||||
|
"apiVersion": "apps/v1",
|
||||||
|
"kind": "Deployment",
|
||||||
|
"metadata": {
|
||||||
|
"name": "homer",
|
||||||
|
"namespace": "simpsons",
|
||||||
|
"labels": {
|
||||||
|
"fruit": "apple",
|
||||||
|
"veggie": "carrot"
|
||||||
|
},
|
||||||
|
"annotations": {
|
||||||
|
"area": "51",
|
||||||
|
"greeting": "Take me to your leader."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
bigMapYaml = `Kind: Service
|
||||||
|
complextree:
|
||||||
|
- field1:
|
||||||
|
- boolfield: true
|
||||||
|
floatsubfield: 1.01
|
||||||
|
intsubfield: 1010
|
||||||
|
stringsubfield: idx1010
|
||||||
|
- boolfield: false
|
||||||
|
floatsubfield: 1.011
|
||||||
|
intsubfield: 1011
|
||||||
|
stringsubfield: idx1011
|
||||||
|
field2:
|
||||||
|
- boolfield: true
|
||||||
|
floatsubfield: 1.02
|
||||||
|
intsubfield: 1020
|
||||||
|
stringsubfield: idx1020
|
||||||
|
- boolfield: false
|
||||||
|
floatsubfield: 1.021
|
||||||
|
intsubfield: 1021
|
||||||
|
stringsubfield: idx1021
|
||||||
|
- field1:
|
||||||
|
- boolfield: true
|
||||||
|
floatsubfield: 1.11
|
||||||
|
intsubfield: 1110
|
||||||
|
stringsubfield: idx1110
|
||||||
|
- boolfield: false
|
||||||
|
floatsubfield: 1.111
|
||||||
|
intsubfield: 1111
|
||||||
|
stringsubfield: idx1111
|
||||||
|
field2:
|
||||||
|
- boolfield: true
|
||||||
|
floatsubfield: 1.112
|
||||||
|
intsubfield: 1120
|
||||||
|
stringsubfield: idx1120
|
||||||
|
- boolfield: false
|
||||||
|
floatsubfield: 1.1121
|
||||||
|
intsubfield: 1121
|
||||||
|
stringsubfield: idx1121
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: application-name
|
||||||
|
name: service-name
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
port: 80
|
||||||
|
that:
|
||||||
|
- idx0
|
||||||
|
- idx1
|
||||||
|
- idx2
|
||||||
|
- idx3
|
||||||
|
these:
|
||||||
|
- field1:
|
||||||
|
- idx010
|
||||||
|
- idx011
|
||||||
|
field2:
|
||||||
|
- idx020
|
||||||
|
- idx021
|
||||||
|
- field1:
|
||||||
|
- idx110
|
||||||
|
- idx111
|
||||||
|
field2:
|
||||||
|
- idx120
|
||||||
|
- idx121
|
||||||
|
- field1:
|
||||||
|
- idx210
|
||||||
|
- idx211
|
||||||
|
field2:
|
||||||
|
- idx220
|
||||||
|
- idx221
|
||||||
|
this:
|
||||||
|
is:
|
||||||
|
aBool: true
|
||||||
|
aFloat: 1.001
|
||||||
|
aNilValue: null
|
||||||
|
aNumber: 1000
|
||||||
|
anEmptyMap: {}
|
||||||
|
anEmptySlice: []
|
||||||
|
those:
|
||||||
|
- field1: idx0foo
|
||||||
|
field2: idx0bar
|
||||||
|
- field1: idx1foo
|
||||||
|
field2: idx1bar
|
||||||
|
- field1: idx2foo
|
||||||
|
field2: idx2bar
|
||||||
|
`
|
||||||
|
)
|
||||||
|
|
||||||
|
func makeBigMap() map[string]interface{} {
|
||||||
|
return map[string]interface{}{
|
||||||
|
"Kind": "Service",
|
||||||
|
"metadata": map[string]interface{}{
|
||||||
|
"labels": map[string]interface{}{
|
||||||
|
"app": "application-name",
|
||||||
|
},
|
||||||
|
"name": "service-name",
|
||||||
|
},
|
||||||
|
"spec": map[string]interface{}{
|
||||||
|
"ports": map[string]interface{}{
|
||||||
|
"port": int64(80),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"this": map[string]interface{}{
|
||||||
|
"is": map[string]interface{}{
|
||||||
|
"aNumber": int64(1000),
|
||||||
|
"aFloat": float64(1.001),
|
||||||
|
"aNilValue": nil,
|
||||||
|
"aBool": true,
|
||||||
|
"anEmptyMap": map[string]interface{}{},
|
||||||
|
"anEmptySlice": []interface{}{},
|
||||||
|
/*
|
||||||
|
TODO: test for unrecognizable (e.g. a function)
|
||||||
|
"unrecognizable": testing.InternalExample{
|
||||||
|
Name: "fooBar",
|
||||||
|
},
|
||||||
|
*/
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"that": []interface{}{
|
||||||
|
"idx0",
|
||||||
|
"idx1",
|
||||||
|
"idx2",
|
||||||
|
"idx3",
|
||||||
|
},
|
||||||
|
"those": []interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"field1": "idx0foo",
|
||||||
|
"field2": "idx0bar",
|
||||||
|
},
|
||||||
|
map[string]interface{}{
|
||||||
|
"field1": "idx1foo",
|
||||||
|
"field2": "idx1bar",
|
||||||
|
},
|
||||||
|
map[string]interface{}{
|
||||||
|
"field1": "idx2foo",
|
||||||
|
"field2": "idx2bar",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"these": []interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"field1": []interface{}{"idx010", "idx011"},
|
||||||
|
"field2": []interface{}{"idx020", "idx021"},
|
||||||
|
},
|
||||||
|
map[string]interface{}{
|
||||||
|
"field1": []interface{}{"idx110", "idx111"},
|
||||||
|
"field2": []interface{}{"idx120", "idx121"},
|
||||||
|
},
|
||||||
|
map[string]interface{}{
|
||||||
|
"field1": []interface{}{"idx210", "idx211"},
|
||||||
|
"field2": []interface{}{"idx220", "idx221"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"complextree": []interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"field1": []interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"stringsubfield": "idx1010",
|
||||||
|
"intsubfield": int64(1010),
|
||||||
|
"floatsubfield": float64(1.010),
|
||||||
|
"boolfield": true,
|
||||||
|
},
|
||||||
|
map[string]interface{}{
|
||||||
|
"stringsubfield": "idx1011",
|
||||||
|
"intsubfield": int64(1011),
|
||||||
|
"floatsubfield": float64(1.011),
|
||||||
|
"boolfield": false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"field2": []interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"stringsubfield": "idx1020",
|
||||||
|
"intsubfield": int64(1020),
|
||||||
|
"floatsubfield": float64(1.020),
|
||||||
|
"boolfield": true,
|
||||||
|
},
|
||||||
|
map[string]interface{}{
|
||||||
|
"stringsubfield": "idx1021",
|
||||||
|
"intsubfield": int64(1021),
|
||||||
|
"floatsubfield": float64(1.021),
|
||||||
|
"boolfield": false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
map[string]interface{}{
|
||||||
|
"field1": []interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"stringsubfield": "idx1110",
|
||||||
|
"intsubfield": int64(1110),
|
||||||
|
"floatsubfield": float64(1.110),
|
||||||
|
"boolfield": true,
|
||||||
|
},
|
||||||
|
map[string]interface{}{
|
||||||
|
"stringsubfield": "idx1111",
|
||||||
|
"intsubfield": int64(1111),
|
||||||
|
"floatsubfield": float64(1.111),
|
||||||
|
"boolfield": false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"field2": []interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"stringsubfield": "idx1120",
|
||||||
|
"intsubfield": int64(1120),
|
||||||
|
"floatsubfield": float64(1.1120),
|
||||||
|
"boolfield": true,
|
||||||
|
},
|
||||||
|
map[string]interface{}{
|
||||||
|
"stringsubfield": "idx1121",
|
||||||
|
"intsubfield": int64(1121),
|
||||||
|
"floatsubfield": float64(1.1121),
|
||||||
|
"boolfield": false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBasicYamlOperationFromMap(t *testing.T) {
|
||||||
|
bytes, err := yaml.Marshal(makeBigMap())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected yaml.Marshal err: %v", err)
|
||||||
|
}
|
||||||
|
if string(bytes) != bigMapYaml {
|
||||||
|
t.Fatalf("unexpected string equality")
|
||||||
|
}
|
||||||
|
rNode, err := kyaml.Parse(string(bytes))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected yaml.Marshal err: %v", err)
|
||||||
|
}
|
||||||
|
rNodeString := rNode.MustString()
|
||||||
|
// The result from MustString has more indentation
|
||||||
|
// than bigMapYaml.
|
||||||
|
rNodeStrings := strings.Split(rNodeString, "\n")
|
||||||
|
bigMapStrings := strings.Split(bigMapYaml, "\n")
|
||||||
|
if len(rNodeStrings) != len(bigMapStrings) {
|
||||||
|
t.Fatalf("line count mismatch")
|
||||||
|
}
|
||||||
|
for i := range rNodeStrings {
|
||||||
|
s1 := strings.TrimSpace(rNodeStrings[i])
|
||||||
|
s2 := strings.TrimSpace(bigMapStrings[i])
|
||||||
|
if s1 != s2 {
|
||||||
|
t.Fatalf("expected '%s'=='%s'", s1, s2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRoundTripJSON(t *testing.T) {
|
||||||
|
wn := NewWNode()
|
||||||
|
err := wn.UnmarshalJSON([]byte(deploymentLittleJson))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected UnmarshalJSON err: %v", err)
|
||||||
|
}
|
||||||
|
data, err := wn.MarshalJSON()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected MarshalJSON err: %v", err)
|
||||||
|
}
|
||||||
|
actual := string(data)
|
||||||
|
if actual != deploymentLittleJson {
|
||||||
|
t.Fatalf("expected %s, got %s", deploymentLittleJson, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGettingFields(t *testing.T) {
|
||||||
|
wn := NewWNode()
|
||||||
|
err := wn.UnmarshalJSON([]byte(deploymentBiggerJson))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected unmarshaljson err: %v", err)
|
||||||
|
}
|
||||||
|
gvk := wn.GetGvk()
|
||||||
|
expected := "apps"
|
||||||
|
actual := gvk.Group
|
||||||
|
if expected != actual {
|
||||||
|
t.Fatalf("expected '%s', got '%s'", expected, actual)
|
||||||
|
}
|
||||||
|
expected = "v1"
|
||||||
|
actual = gvk.Version
|
||||||
|
if expected != actual {
|
||||||
|
t.Fatalf("expected '%s', got '%s'", expected, actual)
|
||||||
|
}
|
||||||
|
expected = "Deployment"
|
||||||
|
actual = gvk.Kind
|
||||||
|
if expected != actual {
|
||||||
|
t.Fatalf("expected '%s', got '%s'", expected, actual)
|
||||||
|
}
|
||||||
|
actual = wn.GetKind()
|
||||||
|
if expected != actual {
|
||||||
|
t.Fatalf("expected '%s', got '%s'", expected, actual)
|
||||||
|
}
|
||||||
|
expected = "homer"
|
||||||
|
actual = wn.GetName()
|
||||||
|
if expected != actual {
|
||||||
|
t.Fatalf("expected '%s', got '%s'", expected, actual)
|
||||||
|
}
|
||||||
|
actualMap := wn.GetLabels()
|
||||||
|
v, ok := actualMap["fruit"]
|
||||||
|
if !ok || v != "apple" {
|
||||||
|
t.Fatalf("unexpected labels '%v'", actualMap)
|
||||||
|
}
|
||||||
|
actualMap = wn.GetAnnotations()
|
||||||
|
v, ok = actualMap["greeting"]
|
||||||
|
if !ok || v != "Take me to your leader." {
|
||||||
|
t.Fatalf("unexpected annotations '%v'", actualMap)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,7 +17,11 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// KunstructuredFactoryImpl hides construction using apimachinery types.
|
// KunstructuredFactoryImpl makes instances of UnstructAdapter.
|
||||||
|
// These instances in turn adapt structs in
|
||||||
|
// k8s.io/apimachinery/pkg/apis/meta/v1/unstructured
|
||||||
|
// to implement ifc.Kunstructured.
|
||||||
|
// This factory is meant to implement ifc.KunstructuredFactory.
|
||||||
type KunstructuredFactoryImpl struct {
|
type KunstructuredFactoryImpl struct {
|
||||||
hasher *kustHash
|
hasher *kustHash
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,13 +4,9 @@
|
|||||||
package kunstruct
|
package kunstruct
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
|
||||||
"sigs.k8s.io/kustomize/api/hasher"
|
"sigs.k8s.io/kustomize/api/hasher"
|
||||||
"sigs.k8s.io/kustomize/api/ifc"
|
"sigs.k8s.io/kustomize/api/ifc"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/filtersutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
// kustHash computes a hash of an unstructured object.
|
// kustHash computes a hash of an unstructured object.
|
||||||
@@ -21,103 +17,11 @@ func NewKustHash() *kustHash {
|
|||||||
return &kustHash{}
|
return &kustHash{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hash returns a hash of either a ConfigMap or a Secret
|
// Hash returns a hash of the given object
|
||||||
func (h *kustHash) Hash(m ifc.Kunstructured) (string, error) {
|
func (h *kustHash) Hash(m ifc.Kunstructured) (string, error) {
|
||||||
u := unstructured.Unstructured{
|
node, err := filtersutil.GetRNode(m)
|
||||||
Object: m.Map(),
|
|
||||||
}
|
|
||||||
kind := u.GetKind()
|
|
||||||
switch kind {
|
|
||||||
case "ConfigMap":
|
|
||||||
cm, err := unstructuredToConfigmap(u)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return configMapHash(cm)
|
|
||||||
case "Secret":
|
|
||||||
sec, err := unstructuredToSecret(u)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return secretHash(sec)
|
|
||||||
default:
|
|
||||||
return "", fmt.Errorf(
|
|
||||||
"type %s is not supported for hashing in %v",
|
|
||||||
kind, m.Map())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// configMapHash returns a hash of the ConfigMap.
|
|
||||||
// The Data, Kind, and Name are taken into account.
|
|
||||||
func configMapHash(cm *corev1.ConfigMap) (string, error) {
|
|
||||||
encoded, err := encodeConfigMap(cm)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
h, err := hasher.Encode(hasher.Hash(encoded))
|
return hasher.HashRNode(node)
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return h, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SecretHash returns a hash of the Secret.
|
|
||||||
// The Data, Kind, Name, and Type are taken into account.
|
|
||||||
func secretHash(sec *corev1.Secret) (string, error) {
|
|
||||||
encoded, err := encodeSecret(sec)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
h, err := hasher.Encode(hasher.Hash(encoded))
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return h, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// encodeConfigMap encodes a ConfigMap.
|
|
||||||
// Data, Kind, and Name are taken into account.
|
|
||||||
func encodeConfigMap(cm *corev1.ConfigMap) (string, error) {
|
|
||||||
// json.Marshal sorts the keys in a stable order in the encoding
|
|
||||||
m := map[string]interface{}{"kind": "ConfigMap", "name": cm.Name, "data": cm.Data}
|
|
||||||
if len(cm.BinaryData) > 0 {
|
|
||||||
m["binaryData"] = cm.BinaryData
|
|
||||||
}
|
|
||||||
data, err := json.Marshal(m)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return string(data), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// encodeSecret encodes a Secret.
|
|
||||||
// Data, Kind, Name, and Type are taken into account.
|
|
||||||
func encodeSecret(sec *corev1.Secret) (string, error) {
|
|
||||||
// json.Marshal sorts the keys in a stable order in the encoding
|
|
||||||
data, err := json.Marshal(map[string]interface{}{"kind": "Secret", "type": sec.Type, "name": sec.Name, "data": sec.Data})
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return string(data), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func unstructuredToConfigmap(u unstructured.Unstructured) (*corev1.ConfigMap, error) {
|
|
||||||
marshaled, err := json.Marshal(u.Object)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var out corev1.ConfigMap
|
|
||||||
err = json.Unmarshal(marshaled, &out)
|
|
||||||
return &out, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func unstructuredToSecret(u unstructured.Unstructured) (*corev1.Secret, error) {
|
|
||||||
marshaled, err := json.Marshal(u.Object)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var out corev1.Secret
|
|
||||||
err = json.Unmarshal(marshaled, &out)
|
|
||||||
return &out, err
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,180 +1,34 @@
|
|||||||
// Copyright 2019 The Kubernetes Authors.
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
package kunstruct
|
package kunstruct
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConfigMapHash(t *testing.T) {
|
func TestHasher(t *testing.T) {
|
||||||
cases := []struct {
|
input := `
|
||||||
desc string
|
apiVersion: v1
|
||||||
cm *corev1.ConfigMap
|
kind: ConfigMap
|
||||||
hash string
|
metadata:
|
||||||
err string
|
name: foo
|
||||||
}{
|
data:
|
||||||
// empty map
|
one: ""
|
||||||
{"empty data", &corev1.ConfigMap{Data: map[string]string{}, BinaryData: map[string][]byte{}}, "42745tchd9", ""},
|
binaryData:
|
||||||
// one key
|
two: ""
|
||||||
{"one key", &corev1.ConfigMap{Data: map[string]string{"one": ""}}, "9g67k2htb6", ""},
|
|
||||||
// three keys (tests sorting order)
|
|
||||||
{"three keys", &corev1.ConfigMap{Data: map[string]string{"two": "2", "one": "", "three": "3"}}, "f5h7t85m9b", ""},
|
|
||||||
// empty binary data map
|
|
||||||
{"empty binary data", &corev1.ConfigMap{BinaryData: map[string][]byte{}}, "dk855m5d49", ""},
|
|
||||||
// one key with binary data
|
|
||||||
{"one key with binary data", &corev1.ConfigMap{BinaryData: map[string][]byte{"one": []byte("")}}, "mk79584b8c", ""},
|
|
||||||
// three keys with binary data (tests sorting order)
|
|
||||||
{"three keys with binary data", &corev1.ConfigMap{BinaryData: map[string][]byte{"two": []byte("2"), "one": []byte(""), "three": []byte("3")}}, "t458mc6db2", ""},
|
|
||||||
// two keys, one with string and another with binary data
|
|
||||||
{"two keys with one each", &corev1.ConfigMap{Data: map[string]string{"one": ""}, BinaryData: map[string][]byte{"two": []byte("")}}, "698h7c7t9m", ""},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, c := range cases {
|
|
||||||
h, err := configMapHash(c.cm)
|
|
||||||
if SkipRest(t, c.desc, err, c.err) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if c.hash != h {
|
|
||||||
t.Errorf("case %q, expect hash %q but got %q", c.desc, c.hash, h)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSecretHash(t *testing.T) {
|
|
||||||
cases := []struct {
|
|
||||||
desc string
|
|
||||||
secret *corev1.Secret
|
|
||||||
hash string
|
|
||||||
err string
|
|
||||||
}{
|
|
||||||
// empty map
|
|
||||||
{"empty data", &corev1.Secret{Type: "my-type", Data: map[string][]byte{}}, "t75bgf6ctb", ""},
|
|
||||||
// one key
|
|
||||||
{"one key", &corev1.Secret{Type: "my-type", Data: map[string][]byte{"one": []byte("")}}, "74bd68bm66", ""},
|
|
||||||
// three keys (tests sorting order)
|
|
||||||
{"three keys", &corev1.Secret{Type: "my-type", Data: map[string][]byte{"two": []byte("2"), "one": []byte(""), "three": []byte("3")}}, "dgcb6h9tmk", ""},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, c := range cases {
|
|
||||||
h, err := secretHash(c.secret)
|
|
||||||
if SkipRest(t, c.desc, err, c.err) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if c.hash != h {
|
|
||||||
t.Errorf("case %q, expect hash %q but got %q", c.desc, c.hash, h)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestEncodeConfigMap(t *testing.T) {
|
|
||||||
cases := []struct {
|
|
||||||
desc string
|
|
||||||
cm *corev1.ConfigMap
|
|
||||||
expect string
|
|
||||||
err string
|
|
||||||
}{
|
|
||||||
// empty map
|
|
||||||
{"empty data", &corev1.ConfigMap{Data: map[string]string{}}, `{"data":{},"kind":"ConfigMap","name":""}`, ""},
|
|
||||||
// one key
|
|
||||||
{"one key", &corev1.ConfigMap{Data: map[string]string{"one": ""}}, `{"data":{"one":""},"kind":"ConfigMap","name":""}`, ""},
|
|
||||||
// three keys (tests sorting order)
|
|
||||||
{"three keys", &corev1.ConfigMap{Data: map[string]string{"two": "2", "one": "", "three": "3"}},
|
|
||||||
`{"data":{"one":"","three":"3","two":"2"},"kind":"ConfigMap","name":""}`, ""},
|
|
||||||
// empty binary map
|
|
||||||
{"empty data", &corev1.ConfigMap{BinaryData: map[string][]byte{}}, `{"data":null,"kind":"ConfigMap","name":""}`, ""},
|
|
||||||
// one key with binary data
|
|
||||||
{"one key", &corev1.ConfigMap{BinaryData: map[string][]byte{"one": []byte("")}},
|
|
||||||
`{"binaryData":{"one":""},"data":null,"kind":"ConfigMap","name":""}`, ""},
|
|
||||||
// three keys with binary data (tests sorting order)
|
|
||||||
{"three keys", &corev1.ConfigMap{BinaryData: map[string][]byte{"two": []byte("2"), "one": []byte(""), "three": []byte("3")}},
|
|
||||||
`{"binaryData":{"one":"","three":"Mw==","two":"Mg=="},"data":null,"kind":"ConfigMap","name":""}`, ""},
|
|
||||||
// two keys, one string and one binary values
|
|
||||||
{"two keys with one each", &corev1.ConfigMap{Data: map[string]string{"one": ""}, BinaryData: map[string][]byte{"two": []byte("")}},
|
|
||||||
`{"binaryData":{"two":""},"data":{"one":""},"kind":"ConfigMap","name":""}`, ""},
|
|
||||||
}
|
|
||||||
for _, c := range cases {
|
|
||||||
s, err := encodeConfigMap(c.cm)
|
|
||||||
if SkipRest(t, c.desc, err, c.err) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if s != c.expect {
|
|
||||||
t.Errorf("case %q, expect %q but got %q from encode %#v", c.desc, c.expect, s, c.cm)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestEncodeSecret(t *testing.T) {
|
|
||||||
cases := []struct {
|
|
||||||
desc string
|
|
||||||
secret *corev1.Secret
|
|
||||||
expect string
|
|
||||||
err string
|
|
||||||
}{
|
|
||||||
// empty map
|
|
||||||
{"empty data", &corev1.Secret{Type: "my-type", Data: map[string][]byte{}}, `{"data":{},"kind":"Secret","name":"","type":"my-type"}`, ""},
|
|
||||||
// one key
|
|
||||||
{"one key", &corev1.Secret{Type: "my-type", Data: map[string][]byte{"one": []byte("")}}, `{"data":{"one":""},"kind":"Secret","name":"","type":"my-type"}`, ""},
|
|
||||||
// three keys (tests sorting order) - note json.Marshal base64 encodes the values because they come in as []byte
|
|
||||||
{"three keys", &corev1.Secret{
|
|
||||||
Type: "my-type",
|
|
||||||
Data: map[string][]byte{"two": []byte("2"), "one": []byte(""), "three": []byte("3")},
|
|
||||||
},
|
|
||||||
`{"data":{"one":"","three":"Mw==","two":"Mg=="},"kind":"Secret","name":"","type":"my-type"}`, ""},
|
|
||||||
}
|
|
||||||
for _, c := range cases {
|
|
||||||
s, err := encodeSecret(c.secret)
|
|
||||||
if SkipRest(t, c.desc, err, c.err) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if s != c.expect {
|
|
||||||
t.Errorf("case %q, expect %q but got %q from encode %#v", c.desc, c.expect, s, c.secret)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// warn devs who change types that they might have to update a hash function
|
|
||||||
// not perfect, as it only checks the number of top-level fields
|
|
||||||
func TestTypeStability(t *testing.T) {
|
|
||||||
errfmt := `case %q, expected %d fields but got %d
|
|
||||||
Depending on the field(s) you added, you may need to modify the hash function for this type.
|
|
||||||
To guide you: the hash function targets fields that comprise the contents of objects,
|
|
||||||
not their metadata (e.g. the Data of a ConfigMap, but nothing in ObjectMeta).
|
|
||||||
`
|
`
|
||||||
cases := []struct {
|
expect := "698h7c7t9m"
|
||||||
typeName string
|
|
||||||
obj interface{}
|
|
||||||
expect int
|
|
||||||
}{
|
|
||||||
{"ConfigMap", corev1.ConfigMap{}, 4},
|
|
||||||
{"Secret", corev1.Secret{}, 5},
|
|
||||||
}
|
|
||||||
for _, c := range cases {
|
|
||||||
val := reflect.ValueOf(c.obj)
|
|
||||||
if num := val.NumField(); c.expect != num {
|
|
||||||
t.Errorf(errfmt, c.typeName, c.expect, num)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SkipRest returns true if there was a non-nil error or if we expected an error that didn't happen,
|
factory := NewKunstructuredFactoryImpl()
|
||||||
// and logs the appropriate error on the test object.
|
k, err := factory.SliceFromBytes([]byte(input))
|
||||||
// The return value indicates whether we should skip the rest of the test case due to the error result.
|
|
||||||
func SkipRest(t *testing.T, desc string, err error, contains string) bool {
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if len(contains) == 0 {
|
t.Fatal(err)
|
||||||
t.Errorf("case %q, expect nil error but got %q", desc, err.Error())
|
}
|
||||||
} else if !strings.Contains(err.Error(), contains) {
|
|
||||||
t.Errorf("case %q, expect error to contain %q but got %q", desc, contains, err.Error())
|
hasher := NewKustHash()
|
||||||
}
|
result, err := hasher.Hash(k[0])
|
||||||
return true
|
if err != nil {
|
||||||
} else if len(contains) > 0 {
|
t.Fatal(err)
|
||||||
t.Errorf("case %q, expect error to contain %q but got nil error", desc, contains)
|
}
|
||||||
return true
|
if result != expect {
|
||||||
|
t.Fatalf("expect %s but got %s", expect, result)
|
||||||
}
|
}
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -466,278 +466,6 @@ func TestGetString(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetInt64(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
pathToField string
|
|
||||||
expectedValue int64
|
|
||||||
errorExpected bool
|
|
||||||
errorMsg string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "numberAsValue",
|
|
||||||
pathToField: "this.is.aNumber",
|
|
||||||
errorExpected: false,
|
|
||||||
expectedValue: int64(1000),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "validStructSubFieldIndexSubfield",
|
|
||||||
pathToField: "complextree[1].field2[1].intsubfield",
|
|
||||||
errorExpected: false,
|
|
||||||
expectedValue: int64(1121),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "twoFieldsOneMissing",
|
|
||||||
pathToField: "metadata.banana",
|
|
||||||
errorExpected: true,
|
|
||||||
errorMsg: "no field named 'metadata.banana'",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "validStructSubFieldOutOfBoundIndex",
|
|
||||||
pathToField: "these[1].field2[99]",
|
|
||||||
errorExpected: true,
|
|
||||||
errorMsg: "no field named 'these[1].field2[99]'",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "validDownwardAPISpecs",
|
|
||||||
pathToField: `spec.ports['port']`,
|
|
||||||
errorExpected: false,
|
|
||||||
expectedValue: int64(80),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, test := range tests {
|
|
||||||
s, err := kunstructured.GetInt64(test.pathToField)
|
|
||||||
if test.errorExpected {
|
|
||||||
compareExpectedError(t, test.name, test.pathToField, err, test.errorMsg)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
unExpectedError(t, test.name, test.pathToField, err)
|
|
||||||
}
|
|
||||||
compareValues(t, test.name, test.pathToField, test.expectedValue, s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetFloat64(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
pathToField string
|
|
||||||
expectedValue float64
|
|
||||||
errorExpected bool
|
|
||||||
errorMsg string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "floatAsValue",
|
|
||||||
pathToField: "this.is.aFloat",
|
|
||||||
errorExpected: false,
|
|
||||||
expectedValue: float64(1.001),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "validStructSubFieldIndexSubfield",
|
|
||||||
pathToField: "complextree[1].field2[1].floatsubfield",
|
|
||||||
errorExpected: false,
|
|
||||||
expectedValue: float64(1.1121),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "validDownwardAPIThis",
|
|
||||||
pathToField: `this.is[aFloat]`,
|
|
||||||
errorExpected: false,
|
|
||||||
expectedValue: float64(1.001),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "twoFieldsOneMissing",
|
|
||||||
pathToField: "metadata.banana",
|
|
||||||
errorExpected: true,
|
|
||||||
errorMsg: "no field named 'metadata.banana'",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "validStructSubFieldOutOfBoundIndex",
|
|
||||||
pathToField: "these[1].field2[99]",
|
|
||||||
errorExpected: true,
|
|
||||||
errorMsg: "index 99 is out of bounds",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, test := range tests {
|
|
||||||
s, err := kunstructured.GetFloat64(test.pathToField)
|
|
||||||
if test.errorExpected {
|
|
||||||
compareExpectedError(t, test.name, test.pathToField, err, test.errorMsg)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
unExpectedError(t, test.name, test.pathToField, err)
|
|
||||||
}
|
|
||||||
compareValues(t, test.name, test.pathToField, test.expectedValue, s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetBool(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
pathToField string
|
|
||||||
expectedValue bool
|
|
||||||
errorExpected bool
|
|
||||||
errorMsg string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "boolAsValue",
|
|
||||||
pathToField: "this.is.aBool",
|
|
||||||
errorExpected: false,
|
|
||||||
expectedValue: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "validStructSubFieldIndexSubfield",
|
|
||||||
pathToField: "complextree[1].field2[1].boolfield",
|
|
||||||
errorExpected: false,
|
|
||||||
expectedValue: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "twoFieldsOneMissing",
|
|
||||||
pathToField: "metadata.banana",
|
|
||||||
errorExpected: true,
|
|
||||||
errorMsg: "no field named 'metadata.banana'",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "validStructSubFieldOutOfBoundIndex",
|
|
||||||
pathToField: "these[1].field2[99]",
|
|
||||||
errorExpected: true,
|
|
||||||
errorMsg: "no field named 'these[1].field2[99]'",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, test := range tests {
|
|
||||||
s, err := kunstructured.GetBool(test.pathToField)
|
|
||||||
if test.errorExpected {
|
|
||||||
compareExpectedError(t, test.name, test.pathToField, err, test.errorMsg)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
unExpectedError(t, test.name, test.pathToField, err)
|
|
||||||
}
|
|
||||||
compareValues(t, test.name, test.pathToField, test.expectedValue, s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetStringMap(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
pathToField string
|
|
||||||
errorExpected bool
|
|
||||||
errorMsg string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "validStringMap",
|
|
||||||
pathToField: "those[2]",
|
|
||||||
errorExpected: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "twoFieldsOneMissing",
|
|
||||||
pathToField: "metadata.banana",
|
|
||||||
errorExpected: true,
|
|
||||||
errorMsg: "no field named 'metadata.banana'",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "validStructSubFieldOutOfBoundIndex",
|
|
||||||
pathToField: "these[1].field2[99]",
|
|
||||||
errorExpected: true,
|
|
||||||
errorMsg: "no field named 'these[1].field2[99]'",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, test := range tests {
|
|
||||||
_, err := kunstructured.GetStringMap(test.pathToField)
|
|
||||||
if test.errorExpected {
|
|
||||||
compareExpectedError(t, test.name, test.pathToField, err, test.errorMsg)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
unExpectedError(t, test.name, test.pathToField, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetMap(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
pathToField string
|
|
||||||
errorExpected bool
|
|
||||||
errorMsg string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "validMap",
|
|
||||||
pathToField: "those[2]",
|
|
||||||
errorExpected: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "validStructSubFieldIndexSubfield",
|
|
||||||
pathToField: "complextree[1].field2[1]",
|
|
||||||
errorExpected: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "twoFieldsOneMissing",
|
|
||||||
pathToField: "metadata.banana",
|
|
||||||
errorExpected: true,
|
|
||||||
errorMsg: "no field named 'metadata.banana'",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "validStructSubFieldOutOfBoundIndex",
|
|
||||||
pathToField: "these[1].field2[99]",
|
|
||||||
errorExpected: true,
|
|
||||||
errorMsg: "no field named 'these[1].field2[99]'",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, test := range tests {
|
|
||||||
_, err := kunstructured.GetMap(test.pathToField)
|
|
||||||
if test.errorExpected {
|
|
||||||
compareExpectedError(t, test.name, test.pathToField, err, test.errorMsg)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
unExpectedError(t, test.name, test.pathToField, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetStringSlice(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
pathToField string
|
|
||||||
errorExpected bool
|
|
||||||
errorMsg string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "validStringSlice",
|
|
||||||
pathToField: "that",
|
|
||||||
errorExpected: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "twoFieldsOneMissing",
|
|
||||||
pathToField: "metadata.banana",
|
|
||||||
errorExpected: true,
|
|
||||||
errorMsg: "no field named 'metadata.banana'",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "validStructSubFieldOutOfBoundIndex",
|
|
||||||
pathToField: "these[1].field2[99]",
|
|
||||||
errorExpected: true,
|
|
||||||
errorMsg: "no field named 'these[1].field2[99]'",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, test := range tests {
|
|
||||||
_, err := kunstructured.GetStringSlice(test.pathToField)
|
|
||||||
if test.errorExpected {
|
|
||||||
compareExpectedError(t, test.name, test.pathToField, err, test.errorMsg)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
unExpectedError(t, test.name, test.pathToField, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetSlice(t *testing.T) {
|
func TestGetSlice(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
|||||||
@@ -14,11 +14,14 @@ import (
|
|||||||
v1validation "k8s.io/apimachinery/pkg/apis/meta/v1/validation"
|
v1validation "k8s.io/apimachinery/pkg/apis/meta/v1/validation"
|
||||||
"k8s.io/apimachinery/pkg/util/validation"
|
"k8s.io/apimachinery/pkg/util/validation"
|
||||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||||
|
"sigs.k8s.io/kustomize/api/ifc"
|
||||||
)
|
)
|
||||||
|
|
||||||
// KustValidator validates Labels and annotations by apimachinery
|
// KustValidator validates Labels and annotations by apimachinery
|
||||||
type KustValidator struct{}
|
type KustValidator struct{}
|
||||||
|
|
||||||
|
var _ ifc.Validator = (*KustValidator)(nil)
|
||||||
|
|
||||||
// NewKustValidator returns a KustValidator object
|
// NewKustValidator returns a KustValidator object
|
||||||
func NewKustValidator() *KustValidator {
|
func NewKustValidator() *KustValidator {
|
||||||
return &KustValidator{}
|
return &KustValidator{}
|
||||||
@@ -4,7 +4,15 @@
|
|||||||
package builtinpluginconsts
|
package builtinpluginconsts
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// imageFieldSpecs is left empty since `containers` and `initContainers`
|
imagesFieldSpecs = `
|
||||||
// of *ANY* kind in *ANY* path are builtin supported in code
|
images:
|
||||||
imagesFieldSpecs = ``
|
- path: spec/containers[]/image
|
||||||
|
create: true
|
||||||
|
- path: spec/initContainers[]/image
|
||||||
|
create: true
|
||||||
|
- path: spec/template/spec/containers[]/image
|
||||||
|
create: true
|
||||||
|
- path: spec/template/spec/initContainers[]/image
|
||||||
|
create: true
|
||||||
|
`
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -21,6 +21,11 @@ nameReference:
|
|||||||
- path: spec/scaleTargetRef/name
|
- path: spec/scaleTargetRef/name
|
||||||
kind: HorizontalPodAutoscaler
|
kind: HorizontalPodAutoscaler
|
||||||
|
|
||||||
|
- kind: StatefulSet
|
||||||
|
fieldSpecs:
|
||||||
|
- path: spec/scaleTargetRef/name
|
||||||
|
kind: HorizontalPodAutoscaler
|
||||||
|
|
||||||
- kind: ConfigMap
|
- kind: ConfigMap
|
||||||
version: v1
|
version: v1
|
||||||
fieldSpecs:
|
fieldSpecs:
|
||||||
@@ -247,6 +252,10 @@ nameReference:
|
|||||||
kind: Role
|
kind: Role
|
||||||
- path: rules/resourceNames
|
- path: rules/resourceNames
|
||||||
kind: ClusterRole
|
kind: ClusterRole
|
||||||
|
- path: spec/template/spec/containers/env/valueFrom/secretKeyRef/name
|
||||||
|
kind: Service
|
||||||
|
group: serving.knative.dev
|
||||||
|
version: v1
|
||||||
|
|
||||||
- kind: Service
|
- kind: Service
|
||||||
version: v1
|
version: v1
|
||||||
|
|||||||
@@ -8,9 +8,16 @@ const (
|
|||||||
namespace:
|
namespace:
|
||||||
- path: metadata/namespace
|
- path: metadata/namespace
|
||||||
create: true
|
create: true
|
||||||
|
- path: metadata/name
|
||||||
|
kind: Namespace
|
||||||
|
create: true
|
||||||
- path: subjects
|
- path: subjects
|
||||||
kind: RoleBinding
|
kind: RoleBinding
|
||||||
- path: subjects
|
- path: subjects
|
||||||
kind: ClusterRoleBinding
|
kind: ClusterRoleBinding
|
||||||
|
- path: spec/service/namespace
|
||||||
|
group: apiregistration.k8s.io
|
||||||
|
kind: APIService
|
||||||
|
create: true
|
||||||
`
|
`
|
||||||
)
|
)
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user