Debian Codegraph @

kyaml/yaml/merge3/element_test.go

raw symbols SCIP
1 // Copyright 2019 The Kubernetes Authors.
2 // SPDX-License-Identifier: Apache-2.0
3
4 package merge3_test
5
6 //nolint:lll
7 var elementTestCases = []testCase{
8 //
9 // Test Case
10 //
11 {
12 description: `Add an element to an existing list`,
13 origin: `
14 apiVersion: apps/v1
15 kind: Deployment
16 spec:
17 template:
18 spec:
19 containers:
20 - name: foo
21 image: foo:1
22 `,
23 update: `
24 apiVersion: apps/v1
25 kind: Deployment
26 spec:
27 template:
28 spec:
29 containers:
30 - name: foo
31 image: foo:1
32 - name: baz
33 image: baz:2
34 `,
35 local: `
36 apiVersion: apps/v1
37 kind: Deployment
38 spec:
39 template:
40 spec:
41 containers:
42 - name: foo
43 image: foo:1
44 `,
45 expected: `
46 apiVersion: apps/v1
47 kind: Deployment
48 spec:
49 template:
50 spec:
51 containers:
52 - name: foo
53 image: foo:1
54 - image: baz:2
55 name: baz
56 `},
57
58 //
59 // Test Case
60 //
61 {
62 description: `Add an element to a non-existing list`,
63 origin: `
64 apiVersion: apps/v1
65 kind: Deployment`,
66 update: `
67 apiVersion: apps/v1
68 kind: Deployment
69 spec:
70 template:
71 spec:
72 containers:
73 - name: foo
74 image: foo:bar
75 `,
76 local: `
77 apiVersion: apps/v1
78 kind: Deployment
79 `,
80 expected: `
81 apiVersion: apps/v1
82 kind: Deployment
83 spec:
84 template:
85 spec:
86 containers:
87 - image: foo:bar
88 name: foo
89 `},
90
91 {
92 description: `Add an element to a non-existing list, existing in dest`,
93 origin: `
94 apiVersion: apps/v1
95 kind: Deployment`,
96 update: `
97 apiVersion: apps/v1
98 kind: Deployment
99 spec:
100 template:
101 spec:
102 containers:
103 - name: foo
104 image: foo:bar
105 `,
106 local: `
107 apiVersion: apps/v1
108 kind: Deployment
109 spec:
110 template:
111 spec:
112 containers:
113 - name: baz
114 image: baz:bar
115 `,
116 expected: `
117 apiVersion: apps/v1
118 kind: Deployment
119 spec:
120 template:
121 spec:
122 containers:
123 - name: baz
124 image: baz:bar
125 - image: foo:bar
126 name: foo
127 `},
128
129 //
130 // Test Case
131 // TODO(pwittrock): Figure out if there is something better we can do here
132 // This element is missing from the destination -- only the new fields are added
133 {
134 description: `Add a field to the element, element missing from dest`,
135 origin: `
136 apiVersion: apps/v1
137 kind: Deployment
138 spec:
139 template:
140 spec:
141 containers:
142 - name: foo
143 image: foo:bar`,
144 update: `
145 apiVersion: apps/v1
146 kind: Deployment
147 spec:
148 template:
149 spec:
150 containers:
151 - name: foo
152 image: foo:bar
153 command:
154 - run.sh
155 `,
156 local: `
157 apiVersion: apps/v1
158 kind: Deployment
159 `,
160 expected: `
161 apiVersion: apps/v1
162 kind: Deployment
163 spec:
164 template:
165 spec:
166 containers:
167 - command:
168 - run.sh
169 name: foo
170 `},
171
172 //
173 // Test Case
174 //
175 {
176 description: `Update a field on the elem, element missing from the dest`,
177 origin: `
178 apiVersion: apps/v1
179 kind: Deployment
180 spec:
181 template:
182 spec:
183 containers:
184 - name: foo
185 image: foo:bar
186 command:
187 - run.sh
188 `,
189 update: `
190 apiVersion: apps/v1
191 kind: Deployment
192 spec:
193 template:
194 spec:
195 containers:
196 - name: foo
197 image: foo:bar
198 command:
199 - run2.sh
200 `,
201 local: `
202 apiVersion: apps/v1
203 kind: Deployment
204 `,
205 expected: `
206 apiVersion: apps/v1
207 kind: Deployment
208 spec:
209 template:
210 spec:
211 containers:
212 - command:
213 - run2.sh
214 name: foo
215 `},
216
217 //
218 // Test Case
219 //
220 {
221 description: `Update a field on the elem, element present in the dest`,
222 origin: `
223 apiVersion: apps/v1
224 kind: Deployment
225 spec:
226 template:
227 spec:
228 containers:
229 - name: foo
230 image: foo:bar
231 command: ['run.sh']
232 `,
233 update: `
234 apiVersion: apps/v1
235 kind: Deployment
236 spec:
237 template:
238 spec:
239 containers:
240 - name: foo
241 image: foo:bar
242 command: ['run2.sh']
243 `,
244 local: `
245 apiVersion: apps/v1
246 kind: Deployment
247 spec:
248 template:
249 spec:
250 containers:
251 - name: foo
252 image: foo:bar
253 command: ['run.sh']
254 `,
255 expected: `
256 apiVersion: apps/v1
257 kind: Deployment
258 spec:
259 template:
260 spec:
261 containers:
262 - name: foo
263 image: foo:bar
264 command: ['run2.sh']
265 `},
266
267 //
268 // Test Case
269 //
270 {description: `Add a field on the elem, element present in the dest`,
271 origin: `
272 apiVersion: apps/v1
273 kind: Deployment
274 spec:
275 template:
276 spec:
277 containers:
278 - name: foo
279 image: foo:bar
280 `,
281 update: `
282 apiVersion: apps/v1
283 kind: Deployment
284 spec:
285 template:
286 spec:
287 containers:
288 - name: foo
289 image: foo:bar
290 command: ['run2.sh']
291 `,
292 local: `
293 apiVersion: apps/v1
294 kind: Deployment
295 spec:
296 template:
297 spec:
298 containers:
299 - name: foo
300 image: foo:bar
301 `,
302 expected: `
303 apiVersion: apps/v1
304 kind: Deployment
305 spec:
306 template:
307 spec:
308 containers:
309 - name: foo
310 image: foo:bar
311 command: ['run2.sh']
312 `},
313
314 //
315 // Test Case
316 //
317 {
318 description: `Add a field on the elem, element and field present in the dest`,
319 origin: `
320 apiVersion: apps/v1
321 kind: Deployment
322 spec:
323 template:
324 spec:
325 containers:
326 - name: foo
327 image: foo:bar
328 `,
329 update: `
330 apiVersion: apps/v1
331 kind: Deployment
332 spec:
333 template:
334 spec:
335 containers:
336 - name: foo
337 image: foo:bar
338 command: ['run2.sh']
339 `,
340 local: `
341 apiVersion: apps/v1
342 kind: Deployment
343 spec:
344 template:
345 spec:
346 containers:
347 - name: foo
348 image: foo:bar
349 command: ['run.sh']
350 `,
351 expected: `
352 apiVersion: apps/v1
353 kind: Deployment
354 spec:
355 template:
356 spec:
357 containers:
358 - name: foo
359 image: foo:bar
360 command: ['run2.sh']
361 `},
362
363 //
364 // Test Case
365 //
366 {
367 description: `Ignore an element`,
368 origin: `
369 apiVersion: apps/v1
370 kind: Deployment
371 spec:
372 template:
373 spec:
374 containers: null
375 `,
376 update: `
377 apiVersion: apps/v1
378 kind: Deployment
379 spec:
380 template:
381 spec:
382 containers: null
383 `,
384 local: `
385 apiVersion: apps/v1
386 kind: Deployment
387 spec:
388 template:
389 spec:
390 containers:
391 - name: foo
392 image: foo:bar
393 `,
394 expected: `
395 apiVersion: apps/v1
396 kind: Deployment
397 spec:
398 template:
399 spec:
400 containers:
401 - name: foo
402 image: foo:bar
403 `},
404
405 //
406 // Test Case
407 //
408 {
409 description: `Leave deleted`,
410 origin: `
411 apiVersion: apps/v1
412 kind: Deployment
413 spec:
414 template:
415 spec:
416 containers:
417 - name: foo
418 image: foo:bar
419 `,
420 update: `
421 apiVersion: apps/v1
422 kind: Deployment
423 `,
424 local: `
425 apiVersion: apps/v1
426 kind: Deployment
427 `,
428 expected: `
429 apiVersion: apps/v1
430 kind: Deployment
431 `},
432
433 //
434 // Test Case
435 //
436 {
437 description: `Remove an element -- matching`,
438 origin: `
439 apiVersion: apps/v1
440 kind: Deployment
441 spec:
442 template:
443 spec:
444 containers:
445 - name: foo
446 image: foo:bar
447 `,
448 update: `
449 apiVersion: apps/v1
450 kind: Deployment
451 spec:
452 template:
453 spec: {}
454 `,
455 local: `
456 apiVersion: apps/v1
457 kind: Deployment
458 spec:
459 template:
460 spec:
461 containers:
462 - name: foo
463 image: foo:bar
464 `,
465 expected: `
466 apiVersion: apps/v1
467 kind: Deployment
468 spec:
469 template:
470 spec: {}
471 `},
472
473 //
474 // Test Case
475 //
476 {
477 description: `Remove an element -- field missing from update`,
478 origin: `
479 apiVersion: apps/v1
480 kind: Deployment
481 spec:
482 template:
483 spec:
484 containers:
485 - name: foo
486 image: foo:bar
487 `,
488 update: `
489 apiVersion: apps/v1
490 kind: Deployment
491 spec:
492 template:
493 spec: {}
494 `,
495 local: `
496 apiVersion: apps/v1
497 kind: Deployment
498 spec:
499 template:
500 spec:
501 containers:
502 - name: foo
503 image: foo:bar
504 command: ['run.sh']
505 `,
506 expected: `
507 apiVersion: apps/v1
508 kind: Deployment
509 spec:
510 template:
511 spec: {}
512 `},
513
514 //
515 // Test Case
516 //
517 {
518 description: `Remove an element -- element missing`,
519 origin: `
520 apiVersion: apps/v1
521 kind: Deployment
522 spec:
523 template:
524 spec:
525 containers:
526 - name: foo
527 image: foo:bar
528 - name: baz
529 image: baz:bar
530 `,
531 update: `
532 apiVersion: apps/v1
533 kind: Deployment
534 spec:
535 template:
536 spec:
537 containers:
538 - name: foo
539 image: foo:bar
540 `,
541 local: `
542 apiVersion: apps/v1
543 kind: Deployment
544 spec:
545 template:
546 spec:
547 containers:
548 - name: foo
549 image: foo:bar
550 command: ['run.sh']
551 - name: baz
552 image: baz:bar
553 `,
554 expected: `
555 apiVersion: apps/v1
556 kind: Deployment
557 spec:
558 template:
559 spec:
560 containers:
561 - name: foo
562 image: foo:bar
563 command: ['run.sh']
564 `},
565
566 //
567 // Test Case
568 //
569 {
570 description: `Remove an element -- empty containers`,
571 origin: `
572 apiVersion: apps/v1
573 kind: Deployment
574 spec:
575 template:
576 spec:
577 containers:
578 - name: foo
579 image: foo:bar
580 `,
581 update: `
582 apiVersion: apps/v1
583 kind: Deployment
584 spec:
585 template:
586 spec:
587 containers: null
588 `,
589 local: `
590 apiVersion: apps/v1
591 kind: Deployment
592 spec:
593 template:
594 spec:
595 containers:
596 - name: foo
597 image: foo:bar
598 command: ['run.sh']
599 `,
600 expected: `
601 apiVersion: apps/v1
602 kind: Deployment
603 spec:
604 template:
605 spec: {}
606 `},
607
608 //
609 // Test Case
610 //
611 {
612 description: `Remove an element -- missing list field`,
613 origin: `
614 apiVersion: apps/v1
615 kind: Deployment
616 spec:
617 template:
618 spec:
619 containers:
620 - name: foo
621 image: foo:bar
622 `,
623 update: `
624 apiVersion: apps/v1
625 kind: Deployment
626 spec:
627 template:
628 spec: {}
629 `,
630 local: `
631 apiVersion: apps/v1
632 kind: Deployment
633 spec:
634 template:
635 spec:
636 containers:
637 - name: foo
638 image: foo:bar
639 command: ['run.sh']
640 `,
641 expected: `
642 apiVersion: apps/v1
643 kind: Deployment
644 spec:
645 template:
646 spec: {}
647 `},
648
649 //
650 // Test Case
651 //
652 {
653 description: `infer merge keys merge'`,
654 origin: `
655 kind: Deployment
656 spec:
657 template:
658 spec:
659 containers:
660 - name: foo
661 `,
662 update: `
663 kind: Deployment
664 spec:
665 template:
666 spec:
667 containers:
668 - name: foo
669 command: ['run2.sh']
670 `,
671 local: `
672 kind: Deployment
673 spec:
674 template:
675 spec:
676 containers:
677 - name: foo
678 image: foo:bar
679 `,
680 expected: `
681 kind: Deployment
682 spec:
683 template:
684 spec:
685 containers:
686 - name: foo
687 image: foo:bar
688 command: ['run2.sh']
689 `,
690 infer: true,
691 },
692
693 //
694 // Test Case
695 //
696 {
697 description: `no infer merge keys merge using schema`,
698 origin: `
699 apiVersion: apps/v1
700 kind: Deployment
701 spec:
702 template:
703 spec:
704 containers:
705 - name: foo
706 `,
707 update: `
708 apiVersion: apps/v1
709 kind: Deployment
710 spec:
711 template:
712 spec:
713 containers:
714 - name: foo
715 command: ['run2.sh']
716 `,
717 local: `
718 apiVersion: apps/v1
719 kind: Deployment
720 spec:
721 template:
722 spec:
723 containers:
724 - name: foo
725 image: foo:bar
726 `,
727 expected: `
728 apiVersion: apps/v1
729 kind: Deployment
730 spec:
731 template:
732 spec:
733 containers:
734 - name: foo
735 image: foo:bar
736 command: ['run2.sh']
737 `,
738 infer: false,
739 },
740
741 //
742 // Test Case
743 //
744 {
745 description: `no infer merge keys merge using explicit schema as line comment'`,
746 origin: `
747 apiVersion: custom
748 kind: Deployment
749 spec:
750 template:
751 spec:
752 containers:
753 - name: foo
754 `,
755 update: `
756 apiVersion: custom
757 kind: Deployment
758 spec:
759 template:
760 spec:
761 containers:
762 - name: foo
763 command: ['run2.sh']
764 `,
765 local: `
766 apiVersion: custom
767 kind: Deployment
768 spec:
769 template:
770 spec:
771 containers: # {"items":{"$ref": "#/definitions/io.k8s.api.core.v1.Container"},"type":"array","x-kubernetes-patch-merge-key":"name","x-kubernetes-patch-strategy": "merge"}
772 - name: foo # hell ow
773 image: foo:bar
774 `,
775 expected: `
776 apiVersion: custom
777 kind: Deployment
778 spec:
779 template:
780 spec:
781 containers: # {"items":{"$ref": "#/definitions/io.k8s.api.core.v1.Container"},"type":"array","x-kubernetes-patch-merge-key":"name","x-kubernetes-patch-strategy": "merge"}
782 - name: foo # hell ow
783 image: foo:bar
784 command: ['run2.sh']
785 `,
786 infer: false,
787 },
788
789 //
790 // Test Case
791 //
792 {
793 description: `no infer merge keys merge using explicit schema as head comment'`,
794 origin: `
795 apiVersion: custom
796 kind: Deployment
797 spec:
798 template:
799 spec:
800 containers:
801 - name: foo
802 `,
803 update: `
804 apiVersion: custom
805 kind: Deployment
806 spec:
807 template:
808 spec:
809 containers:
810 - name: foo
811 command: ['run2.sh']
812 `,
813 local: `
814 apiVersion: custom
815 kind: Deployment
816 spec:
817 template:
818 spec:
819 # {"items":{"$ref": "#/definitions/io.k8s.api.core.v1.Container"},"type":"array","x-kubernetes-patch-merge-key":"name","x-kubernetes-patch-strategy": "merge"}
820 containers:
821 - name: foo # hell ow
822 image: foo:bar
823 `,
824 expected: `
825 apiVersion: custom
826 kind: Deployment
827 spec:
828 template:
829 spec:
830 # {"items":{"$ref": "#/definitions/io.k8s.api.core.v1.Container"},"type":"array","x-kubernetes-patch-merge-key":"name","x-kubernetes-patch-strategy": "merge"}
831 containers:
832 - name: foo # hell ow
833 image: foo:bar
834 command: ['run2.sh']
835 `,
836 infer: false,
837 },
838
839 //
840 // Test Case
841 //
842 {
843 description: `no infer merge keys merge using explicit schema to parent field'`,
844 origin: `
845 apiVersion: custom
846 kind: Deployment
847 spec:
848 containers:
849 - name: foo
850 `,
851 update: `
852 apiVersion: custom
853 kind: Deployment
854 spec:
855 containers:
856 - name: foo
857 command: ['run2.sh']
858 `,
859 local: `
860 apiVersion: custom
861 kind: Deployment
862 spec: # {"$ref":"#/definitions/io.k8s.api.core.v1.PodSpec"}
863 containers:
864 - name: foo # hell ow
865 image: foo:bar
866 `,
867 expected: `
868 apiVersion: custom
869 kind: Deployment
870 spec: # {"$ref":"#/definitions/io.k8s.api.core.v1.PodSpec"}
871 containers:
872 - name: foo # hell ow
873 image: foo:bar
874 command: ['run2.sh']
875 `,
876 infer: false,
877 },
878
879 //
880 // Test Case
881 //
882 {
883 description: `no infer merge keys merge using explicit schema to parent field header'`,
884 origin: `
885 apiVersion: custom
886 kind: Deployment
887 spec:
888 containers:
889 - name: foo
890 `,
891 update: `
892 apiVersion: custom
893 kind: Deployment
894 spec:
895 containers:
896 - name: foo
897 command: ['run2.sh']
898 `,
899 local: `
900 apiVersion: custom
901 kind: Deployment
902 # {"$ref":"#/definitions/io.k8s.api.core.v1.PodSpec"}
903 spec:
904 containers:
905 - name: foo # hell ow
906 image: foo:bar
907 `,
908 expected: `
909 apiVersion: custom
910 kind: Deployment
911 # {"$ref":"#/definitions/io.k8s.api.core.v1.PodSpec"}
912 spec:
913 containers:
914 - name: foo # hell ow
915 image: foo:bar
916 command: ['run2.sh']
917 `,
918 infer: false,
919 },
920
921 // The following test cases are regression tests
922 // that should not be broken as a result of
923 // #3111, #3159
924
925 //
926 // Test Case
927 //
928 {
929 description: `Add a containerPort to an existing list`,
930 origin: `
931 apiVersion: apps/v1
932 kind: Deployment
933 spec:
934 template:
935 spec:
936 containers:
937 - image: test-image
938 name: test-deployment
939 ports:
940 - containerPort: 8080
941 `,
942 update: `
943 apiVersion: apps/v1
944 kind: Deployment
945 spec:
946 template:
947 spec:
948 containers:
949 - image: test-image
950 name: test-deployment
951 ports:
952 - containerPort: 8080
953 - containerPort: 80
954 `,
955 local: `
956 apiVersion: apps/v1
957 kind: Deployment
958 spec:
959 template:
960 spec:
961 containers:
962 - image: test-image
963 name: test-deployment
964 ports:
965 - containerPort: 8080
966 `,
967 expected: `
968 apiVersion: apps/v1
969 kind: Deployment
970 spec:
971 template:
972 spec:
973 containers:
974 - image: test-image
975 name: test-deployment
976 ports:
977 - containerPort: 8080
978 - containerPort: 80
979 `},
980
981 //
982 // Test Case
983 //
984 {
985 description: `Add a containerPort to a non-existing list, existing in dest`,
986 origin: `
987 apiVersion: apps/v1
988 kind: Deployment`,
989 update: `
990 apiVersion: apps/v1
991 kind: Deployment
992 spec:
993 template:
994 spec:
995 containers:
996 - image: test-image
997 name: test-deployment
998 ports:
999 - containerPort: 8080
1000 `,
1001 local: `
1002 apiVersion: apps/v1
1003 kind: Deployment
1004 spec:
1005 template:
1006 spec:
1007 containers:
1008 - image: test-image
1009 name: test-deployment
1010 ports:
1011 - containerPort: 80
1012 `,
1013 expected: `
1014 apiVersion: apps/v1
1015 kind: Deployment
1016 spec:
1017 template:
1018 spec:
1019 containers:
1020 - image: test-image
1021 name: test-deployment
1022 ports:
1023 - containerPort: 80
1024 - containerPort: 8080
1025 `},
1026
1027 //
1028 // Test Case
1029 //
1030 {
1031 description: `Add a name to containerPort`,
1032 origin: `
1033 apiVersion: apps/v1
1034 kind: Deployment
1035 spec:
1036 template:
1037 spec:
1038 containers:
1039 - image: test-image
1040 name: test-deployment
1041 ports:
1042 - containerPort: 8080
1043 `,
1044 update: `
1045 apiVersion: apps/v1
1046 kind: Deployment
1047 spec:
1048 template:
1049 spec:
1050 containers:
1051 - image: test-image
1052 name: test-deployment
1053 ports:
1054 - containerPort: 8080
1055 name: 8080-port-update
1056 - containerPort: 80
1057 `,
1058 local: `
1059 apiVersion: apps/v1
1060 kind: Deployment
1061 spec:
1062 template:
1063 spec:
1064 containers:
1065 - image: test-image
1066 name: test-deployment
1067 ports:
1068 - containerPort: 8080
1069 - containerPort: 80
1070 `,
1071 expected: `
1072 apiVersion: apps/v1
1073 kind: Deployment
1074 spec:
1075 template:
1076 spec:
1077 containers:
1078 - image: test-image
1079 name: test-deployment
1080 ports:
1081 - containerPort: 8080
1082 name: 8080-port-update
1083 - containerPort: 80
1084 `},
1085 //
1086 // Test Case
1087 //
1088 {
1089 description: `Update protocol for a port`,
1090 origin: `
1091 apiVersion: apps/v1
1092 kind: Deployment
1093 metadata:
1094 name: test-deployment
1095 spec:
1096 template:
1097 spec:
1098 containers:
1099 - image: test-image
1100 name: test-deployment
1101 ports:
1102 - containerPort: 8080
1103 protocol: UDP
1104 `,
1105 update: `
1106 apiVersion: apps/v1
1107 kind: Deployment
1108 metadata:
1109 name: test-deployment
1110 spec:
1111 template:
1112 spec:
1113 containers:
1114 - image: test-image
1115 name: test-deployment
1116 ports:
1117 - containerPort: 8080
1118 protocol: TCP
1119 `,
1120 local: `
1121 apiVersion: apps/v1
1122 kind: Deployment
1123 metadata:
1124 name: test-deployment
1125 spec:
1126 template:
1127 spec:
1128 containers:
1129 - image: test-image
1130 name: test-deployment
1131 ports:
1132 - containerPort: 8080
1133 protocol: UDP
1134 `,
1135 expected: `
1136 apiVersion: apps/v1
1137 kind: Deployment
1138 metadata:
1139 name: test-deployment
1140 spec:
1141 template:
1142 spec:
1143 containers:
1144 - image: test-image
1145 name: test-deployment
1146 ports:
1147 - containerPort: 8080
1148 protocol: TCP
1149 `},
1150 //
1151 // Test Case
1152 //
1153 {
1154 description: `Append container port`,
1155 origin: `
1156 apiVersion: apps/v1
1157 kind: Deployment
1158 metadata:
1159 name: test-deployment
1160 spec:
1161 template:
1162 spec:
1163 containers:
1164 - image: test-image
1165 name: test-deployment
1166 ports:
1167 - containerPort: 8080
1168 protocol: UDP
1169 `,
1170 update: `
1171 apiVersion: apps/v1
1172 kind: Deployment
1173 metadata:
1174 name: test-deployment
1175 spec:
1176 template:
1177 spec:
1178 containers:
1179 - image: test-image
1180 name: test-deployment
1181 ports:
1182 - containerPort: 8080
1183 protocol: TCP
1184 `,
1185 local: `
1186 apiVersion: apps/v1
1187 kind: Deployment
1188 metadata:
1189 name: test-deployment
1190 spec:
1191 template:
1192 spec:
1193 containers:
1194 - image: test-image
1195 name: test-deployment
1196 ports:
1197 - containerPort: 80
1198 protocol: HTTP
1199 `,
1200 expected: `
1201 apiVersion: apps/v1
1202 kind: Deployment
1203 metadata:
1204 name: test-deployment
1205 spec:
1206 template:
1207 spec:
1208 containers:
1209 - image: test-image
1210 name: test-deployment
1211 ports:
1212 - containerPort: 80
1213 protocol: HTTP
1214 - containerPort: 8080
1215 protocol: TCP
1216 `},
1217
1218 {
1219 description: `Update container-port name`,
1220 origin: `
1221 apiVersion: apps/v1
1222 kind: Deployment
1223 metadata:
1224 name: test-deployment
1225 spec:
1226 template:
1227 spec:
1228 containers:
1229 - image: test-image
1230 name: test-deployment
1231 ports:
1232 - containerPort: 8080
1233 protocol: UDP
1234 name: foo
1235 `,
1236 update: `
1237 apiVersion: apps/v1
1238 kind: Deployment
1239 metadata:
1240 name: test-deployment
1241 spec:
1242 template:
1243 spec:
1244 containers:
1245 - image: test-image
1246 name: test-deployment
1247 ports:
1248 - containerPort: 8080
1249 protocol: TCP
1250 name: bar
1251 `,
1252 local: `
1253 apiVersion: apps/v1
1254 kind: Deployment
1255 metadata:
1256 name: test-deployment
1257 spec:
1258 template:
1259 spec:
1260 containers:
1261 - image: test-image
1262 name: test-deployment
1263 ports:
1264 - containerPort: 8080
1265 protocol: TCP
1266 name: foo
1267 `,
1268 expected: `
1269 apiVersion: apps/v1
1270 kind: Deployment
1271 metadata:
1272 name: test-deployment
1273 spec:
1274 template:
1275 spec:
1276 containers:
1277 - image: test-image
1278 name: test-deployment
1279 ports:
1280 - containerPort: 8080
1281 protocol: TCP
1282 name: bar
1283 `},
1284
1285 //
1286 // Test Case
1287 //
1288 {
1289 description: `Add a containerPort with protocol to an existing list`,
1290 origin: `
1291 apiVersion: apps/v1
1292 kind: Deployment
1293 spec:
1294 template:
1295 spec:
1296 containers:
1297 - image: test-image
1298 name: test-deployment
1299 ports:
1300 - containerPort: 8080
1301 protocol: UDP
1302 `,
1303 update: `
1304 apiVersion: apps/v1
1305 kind: Deployment
1306 spec:
1307 template:
1308 spec:
1309 containers:
1310 - image: test-image
1311 name: test-deployment
1312 ports:
1313 - containerPort: 8080
1314 protocol: UDP
1315 - containerPort: 8080
1316 protocol: TCP
1317 `,
1318 local: `
1319 apiVersion: apps/v1
1320 kind: Deployment
1321 spec:
1322 template:
1323 spec:
1324 containers:
1325 - image: test-image
1326 name: test-deployment
1327 ports:
1328 - containerPort: 8080
1329 protocol: UDP
1330 `,
1331 expected: `
1332 apiVersion: apps/v1
1333 kind: Deployment
1334 spec:
1335 template:
1336 spec:
1337 containers:
1338 - image: test-image
1339 name: test-deployment
1340 ports:
1341 - containerPort: 8080
1342 protocol: UDP
1343 - containerPort: 8080
1344 protocol: TCP
1345 `},
1346
1347 //
1348 // Test Case
1349 //
1350 {
1351 description: `Add a containerPort with protocol to a non-existing list, existing in dest`,
1352 origin: `
1353 apiVersion: apps/v1
1354 kind: Deployment`,
1355 update: `
1356 apiVersion: apps/v1
1357 kind: Deployment
1358 spec:
1359 template:
1360 spec:
1361 containers:
1362 - image: test-image
1363 name: test-deployment
1364 ports:
1365 - containerPort: 8080
1366 protocol: UDP
1367 `,
1368 local: `
1369 apiVersion: apps/v1
1370 kind: Deployment
1371 spec:
1372 template:
1373 spec:
1374 containers:
1375 - image: test-image
1376 name: test-deployment
1377 ports:
1378 - containerPort: 8080
1379 protocol: TCP
1380 `,
1381 expected: `
1382 apiVersion: apps/v1
1383 kind: Deployment
1384 spec:
1385 template:
1386 spec:
1387 containers:
1388 - image: test-image
1389 name: test-deployment
1390 ports:
1391 - containerPort: 8080
1392 protocol: TCP
1393 - containerPort: 8080
1394 protocol: UDP
1395 `},
1396
1397 //
1398 // Test Case
1399 //
1400 {
1401 description: `Merge with name for same container-port`,
1402 origin: `
1403 apiVersion: apps/v1
1404 kind: Deployment
1405 metadata:
1406 name: test-deployment
1407 spec:
1408 template:
1409 spec:
1410 containers:
1411 - image: test-image
1412 name: test-deployment
1413 ports:
1414 - containerPort: 8080
1415 protocol: UDP
1416 name: original
1417 `,
1418 update: `
1419 apiVersion: apps/v1
1420 kind: Deployment
1421 metadata:
1422 name: test-deployment
1423 spec:
1424 template:
1425 spec:
1426 containers:
1427 - image: test-image
1428 name: test-deployment
1429 ports:
1430 - containerPort: 8080
1431 protocol: UDP
1432 name: original
1433 - containerPort: 8080
1434 protocol: TCP
1435 name: updated
1436 `,
1437 local: `
1438 apiVersion: apps/v1
1439 kind: Deployment
1440 metadata:
1441 name: test-deployment
1442 spec:
1443 template:
1444 spec:
1445 containers:
1446 - image: test-image
1447 name: test-deployment
1448 ports:
1449 - containerPort: 8080
1450 protocol: UDP
1451 name: original
1452 - containerPort: 8080
1453 protocol: HTTP
1454 name: local
1455 `,
1456 expected: `
1457 apiVersion: apps/v1
1458 kind: Deployment
1459 metadata:
1460 name: test-deployment
1461 spec:
1462 template:
1463 spec:
1464 containers:
1465 - image: test-image
1466 name: test-deployment
1467 ports:
1468 - containerPort: 8080
1469 protocol: UDP
1470 name: original
1471 - containerPort: 8080
1472 protocol: HTTP
1473 name: local
1474 - containerPort: 8080
1475 name: updated
1476 protocol: TCP
1477 `},
1478
1479 //
1480 // Test Case
1481 //
1482 {
1483 description: `Add single container port and add another container port after an existing container port`,
1484 origin: `
1485 apiVersion: apps/v1
1486 kind: Deployment
1487 metadata:
1488 name: test-deployment
1489 spec:
1490 template:
1491 spec:
1492 containers:
1493 - image: test-image
1494 name: test-deployment
1495 ports:
1496 - containerPort: 8001
1497 name: A
1498 protocol: TCP
1499 - containerPort: 8002
1500 name: B
1501 protocol: TCP
1502 `,
1503 update: `
1504 apiVersion: apps/v1
1505 kind: Deployment
1506 metadata:
1507 name: test-deployment
1508 spec:
1509 template:
1510 spec:
1511 containers:
1512 - image: test-image
1513 name: test-deployment
1514 ports:
1515 - containerPort: 8004
1516 name: D
1517 protocol: TCP
1518 `,
1519 local: `
1520 apiVersion: apps/v1
1521 kind: Deployment
1522 metadata:
1523 name: test-deployment
1524 spec:
1525 template:
1526 spec:
1527 containers:
1528 - image: test-image
1529 name: test-deployment
1530 ports:
1531 - containerPort: 8001
1532 name: A
1533 protocol: TCP
1534 - containerPort: 8003
1535 name: C
1536 protocol: TCP
1537 `,
1538 // This test records current behavior, but this behavior might be undesirable.
1539 // If so, feel free to change the test to pass with some improved algorithm.
1540 expected: `
1541 apiVersion: apps/v1
1542 kind: Deployment
1543 metadata:
1544 name: test-deployment
1545 spec:
1546 template:
1547 spec:
1548 containers:
1549 - image: test-image
1550 name: test-deployment
1551 ports:
1552 - containerPort: 8003
1553 name: C
1554 protocol: TCP
1555 - containerPort: 8004
1556 name: D
1557 protocol: TCP
1558 `},
1559
1560 //
1561 // Test Case
1562 //
1563 {
1564 description: `Add new container port after existing container ports and add another container port between existing container ports`,
1565 origin: `
1566 apiVersion: apps/v1
1567 kind: Deployment
1568 metadata:
1569 name: test-deployment
1570 spec:
1571 template:
1572 spec:
1573 containers:
1574 - image: test-image
1575 name: test-deployment
1576 ports:
1577 - containerPort: 8001
1578 name: A
1579 protocol: TCP
1580 - containerPort: 8002
1581 name: B
1582 protocol: TCP
1583 `,
1584 update: `
1585 apiVersion: apps/v1
1586 kind: Deployment
1587 metadata:
1588 name: test-deployment
1589 spec:
1590 template:
1591 spec:
1592 containers:
1593 - image: test-image
1594 name: test-deployment
1595 ports:
1596 - containerPort: 8001
1597 name: A
1598 protocol: TCP
1599 - containerPort: 8002
1600 name: B
1601 protocol: TCP
1602 - containerPort: 8004
1603 name: D
1604 protocol: TCP
1605 `,
1606 local: `
1607 apiVersion: apps/v1
1608 kind: Deployment
1609 metadata:
1610 name: test-deployment
1611 spec:
1612 template:
1613 spec:
1614 containers:
1615 - image: test-image
1616 name: test-deployment
1617 ports:
1618 - containerPort: 8001
1619 name: A
1620 protocol: TCP
1621 - containerPort: 8003
1622 name: C
1623 protocol: TCP
1624 - containerPort: 8002
1625 name: B
1626 protocol: TCP
1627 `,
1628 expected: `
1629 apiVersion: apps/v1
1630 kind: Deployment
1631 metadata:
1632 name: test-deployment
1633 spec:
1634 template:
1635 spec:
1636 containers:
1637 - image: test-image
1638 name: test-deployment
1639 ports:
1640 - containerPort: 8001
1641 name: A
1642 protocol: TCP
1643 - containerPort: 8003
1644 name: C
1645 protocol: TCP
1646 - containerPort: 8002
1647 name: B
1648 protocol: TCP
1649 - containerPort: 8004
1650 name: D
1651 protocol: TCP
1652 `},
1653
1654 {
1655 description: `Retain local protocol`,
1656 origin: `
1657 apiVersion: apps/v1
1658 kind: Deployment
1659 metadata:
1660 name: test-deployment
1661 spec:
1662 template:
1663 spec:
1664 containers:
1665 - image: test-image
1666 name: test-deployment
1667 ports:
1668 - containerPort: 8080
1669 protocol: UDP
1670 `,
1671 update: `
1672 apiVersion: apps/v1
1673 kind: Deployment
1674 metadata:
1675 name: test-deployment
1676 spec:
1677 template:
1678 spec:
1679 containers:
1680 - image: test-image
1681 name: test-deployment
1682 ports:
1683 - containerPort: 8080
1684 protocol: TCP
1685 `,
1686 local: `
1687 apiVersion: apps/v1
1688 kind: Deployment
1689 metadata:
1690 name: test-deployment
1691 spec:
1692 template:
1693 spec:
1694 containers:
1695 - image: test-image
1696 name: test-deployment
1697 ports:
1698 - containerPort: 8080
1699 protocol: HTTP
1700 `,
1701 expected: `
1702 apiVersion: apps/v1
1703 kind: Deployment
1704 metadata:
1705 name: test-deployment
1706 spec:
1707 template:
1708 spec:
1709 containers:
1710 - image: test-image
1711 name: test-deployment
1712 ports:
1713 - containerPort: 8080
1714 protocol: HTTP
1715 - containerPort: 8080
1716 protocol: TCP
1717 `},
1718 }