Debian Codegraph @

api/krusty/multiplepatch_test.go

raw
1 // Copyright 2019 The Kubernetes Authors.
2 // SPDX-License-Identifier: Apache-2.0
3
4 package krusty_test
5
6 import (
7 "strings"
8 "testing"
9
10 kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
11 )
12
13 func TestPatchesInOneFile(t *testing.T) {
14 th := kusttest_test.MakeHarness(t)
15 th.WriteK("base", `
16 resources:
17 - namespace.yaml
18 - deployment-controller-manager.yaml
19 - deployment-audit-manager.yaml
20 `)
21 th.WriteF("base/namespace.yaml", `
22 apiVersion: v1
23 kind: Namespace
24 metadata:
25 labels:
26 control-plane: controller-manager
27 admission.gatekeeper.sh/ignore: no-self-managing
28 name: system
29 `)
30 th.WriteF("base/deployment-controller-manager.yaml", `
31 apiVersion: apps/v1
32 kind: Deployment
33 metadata:
34 name: controller-manager
35 namespace: system
36 labels:
37 control-plane: controller-manager
38 gatekeeper.sh/operation: webhook
39 spec:
40 selector:
41 matchLabels:
42 control-plane: controller-manager
43 gatekeeper.sh/operation: webhook
44 replicas: 3
45 template:
46 metadata:
47 annotations:
48 container.seccomp.security.alpha.kubernetes.io/manager: runtime/default
49 labels:
50 control-plane: controller-manager
51 gatekeeper.sh/operation: webhook
52 spec:
53 containers:
54 - command:
55 - /manager
56 args:
57 - "--port=8443"
58 - "--logtostderr"
59 - "--exempt-namespace=gatekeeper-system"
60 - "--operation=webhook"
61 image: openpolicyagent/gatekeeper:v3.4.0
62 imagePullPolicy: Always
63 name: manager
64 terminationGracePeriodSeconds: 60
65 nodeSelector:
66 kubernetes.io/os: linux
67 priorityClassName: system-cluster-critical
68 `)
69 th.WriteF("base/deployment-audit-manager.yaml", `
70 apiVersion: apps/v1
71 kind: Deployment
72 metadata:
73 name: audit
74 namespace: system
75 labels:
76 control-plane: audit-controller
77 gatekeeper.sh/operation: audit
78 spec:
79 selector:
80 matchLabels:
81 control-plane: audit-controller
82 gatekeeper.sh/operation: audit
83 replicas: 1
84 template:
85 metadata:
86 labels:
87 control-plane: audit-controller
88 gatekeeper.sh/operation: audit
89 annotations:
90 container.seccomp.security.alpha.kubernetes.io/manager: runtime/default
91 spec:
92 automountServiceAccountToken: true
93 containers:
94 - args:
95 - --operation=audit
96 - --operation=status
97 - --logtostderr
98 command:
99 - /manager
100 env:
101 - name: POD_NAMESPACE
102 valueFrom:
103 fieldRef:
104 apiVersion: v1
105 fieldPath: metadata.namespace
106 - name: POD_NAME
107 valueFrom:
108 fieldRef:
109 fieldPath: metadata.name
110 image: openpolicyagent/gatekeeper:v3.4.0
111 imagePullPolicy: Always
112 livenessProbe:
113 httpGet:
114 path: /healthz
115 port: 9090
116 name: manager
117 serviceAccountName: gatekeeper-admin
118 terminationGracePeriodSeconds: 60
119 nodeSelector:
120 kubernetes.io/os: linux
121 priorityClassName: system-cluster-critical
122 `)
123 const imagePatchAuditManager = `
124 apiVersion: apps/v1
125 kind: Deployment
126 metadata:
127 name: audit
128 namespace: system
129 spec:
130 template:
131 spec:
132 containers:
133 - image: AUDIT_IMAGE
134 name: manager
135 args:
136 - --port=8443
137 - --logtostderr
138 - --emit-admission-events
139 - --exempt-namespace=gatekeeper-system
140 - --operation=webhook
141 - --disable-opa-builtin=http.send
142 `
143 const imagePatchControllerManager = `
144 apiVersion: apps/v1
145 kind: Deployment
146 metadata:
147 name: controller-manager
148 namespace: system
149 spec:
150 template:
151 spec:
152 containers:
153 - image: CONTROLLER_IMAGE
154 name: manager
155 args:
156 - --emit-audit-events
157 - --operation=audit
158 - --operation=status
159 - --logtostderr
160 `
161 th.WriteF(
162 "overlay/image_patch_audit_manager.yaml",
163 imagePatchAuditManager)
164 th.WriteF(
165 "overlay/image_patch_controller_manager.yaml",
166 imagePatchControllerManager)
167 const expected = `
168 apiVersion: v1
169 kind: Namespace
170 metadata:
171 labels:
172 admission.gatekeeper.sh/ignore: no-self-managing
173 control-plane: controller-manager
174 name: system
175 ---
176 apiVersion: apps/v1
177 kind: Deployment
178 metadata:
179 labels:
180 control-plane: controller-manager
181 gatekeeper.sh/operation: webhook
182 name: controller-manager
183 namespace: system
184 spec:
185 replicas: 3
186 selector:
187 matchLabels:
188 control-plane: controller-manager
189 gatekeeper.sh/operation: webhook
190 template:
191 metadata:
192 annotations:
193 container.seccomp.security.alpha.kubernetes.io/manager: runtime/default
194 labels:
195 control-plane: controller-manager
196 gatekeeper.sh/operation: webhook
197 spec:
198 containers:
199 - args:
200 - --emit-audit-events
201 - --operation=audit
202 - --operation=status
203 - --logtostderr
204 command:
205 - /manager
206 image: CONTROLLER_IMAGE
207 imagePullPolicy: Always
208 name: manager
209 nodeSelector:
210 kubernetes.io/os: linux
211 priorityClassName: system-cluster-critical
212 terminationGracePeriodSeconds: 60
213 ---
214 apiVersion: apps/v1
215 kind: Deployment
216 metadata:
217 labels:
218 control-plane: audit-controller
219 gatekeeper.sh/operation: audit
220 name: audit
221 namespace: system
222 spec:
223 replicas: 1
224 selector:
225 matchLabels:
226 control-plane: audit-controller
227 gatekeeper.sh/operation: audit
228 template:
229 metadata:
230 annotations:
231 container.seccomp.security.alpha.kubernetes.io/manager: runtime/default
232 labels:
233 control-plane: audit-controller
234 gatekeeper.sh/operation: audit
235 spec:
236 automountServiceAccountToken: true
237 containers:
238 - args:
239 - --port=8443
240 - --logtostderr
241 - --emit-admission-events
242 - --exempt-namespace=gatekeeper-system
243 - --operation=webhook
244 - --disable-opa-builtin=http.send
245 command:
246 - /manager
247 env:
248 - name: POD_NAMESPACE
249 valueFrom:
250 fieldRef:
251 apiVersion: v1
252 fieldPath: metadata.namespace
253 - name: POD_NAME
254 valueFrom:
255 fieldRef:
256 fieldPath: metadata.name
257 image: AUDIT_IMAGE
258 imagePullPolicy: Always
259 livenessProbe:
260 httpGet:
261 path: /healthz
262 port: 9090
263 name: manager
264 nodeSelector:
265 kubernetes.io/os: linux
266 priorityClassName: system-cluster-critical
267 serviceAccountName: gatekeeper-admin
268 terminationGracePeriodSeconds: 60
269 `
270 // Technique 1: "patchesStrategicMerge:" field, two patch files.
271 th.WriteK("overlay", `
272 resources:
273 - ../base
274 patchesStrategicMerge:
275 - image_patch_controller_manager.yaml
276 - image_patch_audit_manager.yaml
277 `)
278 m := th.Run("overlay", th.MakeDefaultOptions())
279 th.AssertActualEqualsExpected(m, expected)
280
281 // Technique 2: "patches:" field, two patch files.
282 th.WriteK("overlay", `
283 resources:
284 - ../base
285 patches:
286 - path: image_patch_controller_manager.yaml
287 - path: image_patch_audit_manager.yaml
288 `)
289 m = th.Run("overlay", th.MakeDefaultOptions())
290 th.AssertActualEqualsExpected(m, expected)
291
292 // Technique 3: "patchesStrategicMerge:" field, one patch file.
293 th.WriteK("overlay", `
294 resources:
295 - ../base
296 patchesStrategicMerge:
297 - twoPatchesInOneFile.yaml
298 `)
299 th.WriteF(
300 "overlay/twoPatchesInOneFile.yaml",
301 imagePatchAuditManager+"\n---\n"+imagePatchControllerManager)
302 m = th.Run("overlay", th.MakeDefaultOptions())
303 th.AssertActualEqualsExpected(m, expected)
304
305 // Technique 4: "patches:" field, one patch file.
306 th.WriteK("overlay", `
307 resources:
308 - ../base
309 patches:
310 - path: twoPatchesInOneFile.yaml
311 `)
312 m = th.Run("overlay", th.MakeDefaultOptions())
313 th.AssertActualEqualsExpected(m, expected)
314 }
315
316 func TestRemoveEmptyDirWithNullFieldInSmp(t *testing.T) {
317 th := kusttest_test.MakeHarness(t)
318 th.WriteK(".", `
319 resources:
320 - deployment.yaml
321 patchesStrategicMerge:
322 - patch.yaml
323 `)
324 th.WriteF("deployment.yaml", `
325 apiVersion: apps/v1
326 kind: Deployment
327 metadata:
328 name: nginx
329 spec:
330 template:
331 spec:
332 volumes:
333 - name: fancyDisk
334 emptyDir: {}
335 `)
336 th.WriteF("patch.yaml", `
337 apiVersion: apps/v1
338 kind: Deployment
339 metadata:
340 name: nginx
341 spec:
342 template:
343 spec:
344 volumes:
345 - name: fancyDisk
346 emptyDir: null
347 `)
348 m := th.Run(".", th.MakeDefaultOptions())
349 th.AssertActualEqualsExpected(m, `
350 apiVersion: apps/v1
351 kind: Deployment
352 metadata:
353 name: nginx
354 spec:
355 template:
356 spec:
357 volumes:
358 - name: fancyDisk
359 `)
360 }
361
362 func TestRemoveEmptyDirAddPersistentDisk(t *testing.T) {
363 th := kusttest_test.MakeHarness(t)
364 th.WriteK(".", `
365 resources:
366 - deployment.yaml
367 patchesStrategicMerge:
368 - patch.yaml
369 `)
370 th.WriteF("deployment.yaml", `
371 apiVersion: apps/v1
372 kind: Deployment
373 metadata:
374 name: nginx
375 spec:
376 template:
377 spec:
378 volumes:
379 - name: fancyDisk
380 emptyDir: {}
381 `)
382 th.WriteF("patch.yaml", `
383 apiVersion: apps/v1
384 kind: Deployment
385 metadata:
386 name: nginx
387 spec:
388 template:
389 spec:
390 volumes:
391 - name: fancyDisk
392 emptyDir: null
393 gcePersistentDisk:
394 pdName: fancyDisk
395 `)
396 m := th.Run(".", th.MakeDefaultOptions())
397 th.AssertActualEqualsExpected(m, `
398 apiVersion: apps/v1
399 kind: Deployment
400 metadata:
401 name: nginx
402 spec:
403 template:
404 spec:
405 volumes:
406 - gcePersistentDisk:
407 pdName: fancyDisk
408 name: fancyDisk
409 `)
410 }
411
412 func TestVolumeRemoveEmptyDirInOverlay(t *testing.T) {
413 th := kusttest_test.MakeHarness(t)
414 th.WriteK("base", `
415 resources:
416 - deployment.yaml
417 configMapGenerator:
418 - name: baseCm
419 literals:
420 - foo=bar
421 `)
422 th.WriteF("base/deployment.yaml", `
423 apiVersion: apps/v1
424 kind: Deployment
425 metadata:
426 name: nginx
427 spec:
428 template:
429 spec:
430 containers:
431 - name: nginx
432 image: nginx
433 volumeMounts:
434 - name: fancyDisk
435 mountPath: /tmp/ps
436 volumes:
437 - name: fancyDisk
438 emptyDir: {}
439 - configMap:
440 name: baseCm
441 name: baseCm
442 `)
443 m := th.Run("base", th.MakeDefaultOptions())
444 th.AssertActualEqualsExpected(m, `
445 apiVersion: apps/v1
446 kind: Deployment
447 metadata:
448 name: nginx
449 spec:
450 template:
451 spec:
452 containers:
453 - image: nginx
454 name: nginx
455 volumeMounts:
456 - mountPath: /tmp/ps
457 name: fancyDisk
458 volumes:
459 - emptyDir: {}
460 name: fancyDisk
461 - configMap:
462 name: baseCm-798k5k7g9f
463 name: baseCm
464 ---
465 apiVersion: v1
466 data:
467 foo: bar
468 kind: ConfigMap
469 metadata:
470 name: baseCm-798k5k7g9f
471 `)
472
473 th.WriteK("overlay", `
474 patchesStrategicMerge:
475 - patch.yaml
476 resources:
477 - ../base
478 configMapGenerator:
479 - name: overlayCm
480 literals:
481 - hello=world
482 `)
483 th.WriteF("overlay/patch.yaml", `
484 apiVersion: apps/v1
485 kind: Deployment
486 metadata:
487 name: nginx
488 spec:
489 template:
490 spec:
491 volumes:
492 - name: fancyDisk
493 emptyDir: null
494 gcePersistentDisk:
495 pdName: fancyDisk
496 - configMap:
497 name: overlayCm
498 name: overlayCm
499 `)
500 m = th.Run("overlay", th.MakeDefaultOptions())
501 th.AssertActualEqualsExpected(m, `
502 apiVersion: apps/v1
503 kind: Deployment
504 metadata:
505 name: nginx
506 spec:
507 template:
508 spec:
509 containers:
510 - image: nginx
511 name: nginx
512 volumeMounts:
513 - mountPath: /tmp/ps
514 name: fancyDisk
515 volumes:
516 - gcePersistentDisk:
517 pdName: fancyDisk
518 name: fancyDisk
519 - configMap:
520 name: overlayCm-dc6fm46dhm
521 name: overlayCm
522 - configMap:
523 name: baseCm-798k5k7g9f
524 name: baseCm
525 ---
526 apiVersion: v1
527 data:
528 foo: bar
529 kind: ConfigMap
530 metadata:
531 name: baseCm-798k5k7g9f
532 ---
533 apiVersion: v1
534 data:
535 hello: world
536 kind: ConfigMap
537 metadata:
538 name: overlayCm-dc6fm46dhm
539 `)
540 }
541
542 // Goal is to remove " emptyDir: {}" with a patch.
543 func TestRemoveEmptyDirWithPatchesAtSameLevel(t *testing.T) {
544 th := kusttest_test.MakeHarness(t)
545 th.WriteK("base", `
546 resources:
547 - deployment.yaml
548 `)
549 th.WriteF("base/deployment.yaml", `
550 apiVersion: apps/v1
551 kind: Deployment
552 metadata:
553 name: nginx
554 spec:
555 template:
556 spec:
557 containers:
558 - name: nginx
559 image: nginx
560 - name: sidecar
561 image: sidecar:latest
562 volumes:
563 - name: nginx-persistent-storage
564 emptyDir: {}
565 `)
566 th.WriteK("overlay", `
567 patchesStrategicMerge:
568 - deployment-patch1.yaml
569 - deployment-patch2.yaml
570 resources:
571 - ../base
572 `)
573 th.WriteF("overlay/deployment-patch1.yaml", `
574 apiVersion: apps/v1
575 kind: Deployment
576 metadata:
577 name: nginx
578 spec:
579 template:
580 spec:
581 volumes:
582 - name: nginx-persistent-storage
583 emptyDir: null
584 gcePersistentDisk:
585 pdName: nginx-persistent-storage
586 `)
587 th.WriteF("overlay/deployment-patch2.yaml", `
588 apiVersion: apps/v1
589 kind: Deployment
590 metadata:
591 name: nginx
592 spec:
593 template:
594 spec:
595 containers:
596 - image: nginx
597 name: nginx
598 env:
599 - name: ANOTHERENV
600 value: FOO
601 volumes:
602 - name: nginx-persistent-storage
603 `)
604 opts := th.MakeDefaultOptions()
605 m := th.Run("overlay", opts)
606 th.AssertActualEqualsExpected(
607 m, `
608 apiVersion: apps/v1
609 kind: Deployment
610 metadata:
611 name: nginx
612 spec:
613 template:
614 spec:
615 containers:
616 - env:
617 - name: ANOTHERENV
618 value: FOO
619 image: nginx
620 name: nginx
621 - image: sidecar:latest
622 name: sidecar
623 volumes:
624 - gcePersistentDisk:
625 pdName: nginx-persistent-storage
626 name: nginx-persistent-storage
627 `)
628 }
629
630 func TestSimpleMultiplePatches(t *testing.T) {
631 th := kusttest_test.MakeHarness(t)
632 th.WriteK("base", `
633 namePrefix: b-
634 commonLabels:
635 team: foo
636 resources:
637 - deployment.yaml
638 - service.yaml
639 configMapGenerator:
640 - name: configmap-in-base
641 literals:
642 - foo=bar
643 `)
644 th.WriteF("base/deployment.yaml", `
645 apiVersion: apps/v1
646 kind: Deployment
647 metadata:
648 name: nginx
649 spec:
650 template:
651 spec:
652 containers:
653 - name: nginx
654 image: nginx
655 volumeMounts:
656 - name: nginx-persistent-storage
657 mountPath: /tmp/ps
658 - name: sidecar
659 image: sidecar:latest
660 volumes:
661 - configMap:
662 name: configmap-in-base
663 name: configmap-in-base
664 `)
665 th.WriteF("base/service.yaml", `
666 apiVersion: v1
667 kind: Service
668 metadata:
669 name: nginx
670 spec:
671 ports:
672 - port: 80
673 `)
674 th.WriteK("overlay", `
675 namePrefix: a-
676 commonLabels:
677 env: staging
678 patchesStrategicMerge:
679 - deployment-patch1.yaml
680 - deployment-patch2.yaml
681 resources:
682 - ../base
683 configMapGenerator:
684 - name: configmap-in-overlay
685 literals:
686 - hello=world
687 `)
688 th.WriteF("overlay/deployment-patch1.yaml", `
689 apiVersion: apps/v1
690 kind: Deployment
691 metadata:
692 name: nginx
693 spec:
694 template:
695 spec:
696 containers:
697 - name: nginx
698 image: nginx:latest
699 env:
700 - name: ENVKEY
701 value: ENVVALUE
702 volumes:
703 - name: nginx-persistent-storage
704 gcePersistentDisk:
705 pdName: nginx-persistent-storage
706 - configMap:
707 name: configmap-in-overlay
708 name: configmap-in-overlay
709 `)
710 th.WriteF("overlay/deployment-patch2.yaml", `
711 apiVersion: apps/v1
712 kind: Deployment
713 metadata:
714 name: nginx
715 spec:
716 template:
717 spec:
718 containers:
719 - name: nginx
720 env:
721 - name: ANOTHERENV
722 value: FOO
723 `)
724 m := th.Run("overlay", th.MakeDefaultOptions())
725 th.AssertActualEqualsExpected(m, `
726 apiVersion: apps/v1
727 kind: Deployment
728 metadata:
729 labels:
730 env: staging
731 team: foo
732 name: a-b-nginx
733 spec:
734 selector:
735 matchLabels:
736 env: staging
737 team: foo
738 template:
739 metadata:
740 labels:
741 env: staging
742 team: foo
743 spec:
744 containers:
745 - env:
746 - name: ANOTHERENV
747 value: FOO
748 - name: ENVKEY
749 value: ENVVALUE
750 image: nginx:latest
751 name: nginx
752 volumeMounts:
753 - mountPath: /tmp/ps
754 name: nginx-persistent-storage
755 - image: sidecar:latest
756 name: sidecar
757 volumes:
758 - gcePersistentDisk:
759 pdName: nginx-persistent-storage
760 name: nginx-persistent-storage
761 - configMap:
762 name: a-configmap-in-overlay-dc6fm46dhm
763 name: configmap-in-overlay
764 - configMap:
765 name: a-b-configmap-in-base-798k5k7g9f
766 name: configmap-in-base
767 ---
768 apiVersion: v1
769 kind: Service
770 metadata:
771 labels:
772 env: staging
773 team: foo
774 name: a-b-nginx
775 spec:
776 ports:
777 - port: 80
778 selector:
779 env: staging
780 team: foo
781 ---
782 apiVersion: v1
783 data:
784 foo: bar
785 kind: ConfigMap
786 metadata:
787 labels:
788 env: staging
789 team: foo
790 name: a-b-configmap-in-base-798k5k7g9f
791 ---
792 apiVersion: v1
793 data:
794 hello: world
795 kind: ConfigMap
796 metadata:
797 labels:
798 env: staging
799 name: a-configmap-in-overlay-dc6fm46dhm
800 `)
801 }
802
803 func makeCommonFilesForMultiplePatchTests(th kusttest_test.Harness) {
804 th.WriteK("base", `
805 namePrefix: team-foo-
806 commonLabels:
807 app: mynginx
808 org: example.com
809 team: foo
810 commonAnnotations:
811 note: This is a test annotation
812 resources:
813 - deployment.yaml
814 - service.yaml
815 configMapGenerator:
816 - name: configmap-in-base
817 literals:
818 - foo=bar
819 `)
820 th.WriteF("base/deployment.yaml", `
821 apiVersion: apps/v1
822 kind: Deployment
823 metadata:
824 name: nginx
825 labels:
826 app: nginx
827 spec:
828 template:
829 metadata:
830 labels:
831 app: nginx
832 spec:
833 containers:
834 - name: nginx
835 image: nginx
836 volumeMounts:
837 - name: nginx-persistent-storage
838 mountPath: /tmp/ps
839 - name: sidecar
840 image: sidecar:latest
841 volumes:
842 - configMap:
843 name: configmap-in-base
844 name: configmap-in-base
845 `)
846 th.WriteF("base/service.yaml", `
847 apiVersion: v1
848 kind: Service
849 metadata:
850 name: nginx
851 labels:
852 app: nginx
853 spec:
854 ports:
855 - port: 80
856 selector:
857 app: nginx
858 `)
859 th.WriteK("overlay/staging", `
860 namePrefix: staging-
861 commonLabels:
862 env: staging
863 patchesStrategicMerge:
864 - deployment-patch1.yaml
865 - deployment-patch2.yaml
866 resources:
867 - ../../base
868 configMapGenerator:
869 - name: configmap-in-overlay
870 literals:
871 - hello=world
872 `)
873 }
874
875 func TestMultiplePatchesNoConflict(t *testing.T) {
876 th := kusttest_test.MakeHarness(t)
877 makeCommonFilesForMultiplePatchTests(th)
878 th.WriteF("overlay/staging/deployment-patch1.yaml", `
879 apiVersion: apps/v1
880 kind: Deployment
881 metadata:
882 name: nginx
883 spec:
884 template:
885 spec:
886 containers:
887 - name: nginx
888 image: nginx:latest
889 env:
890 - name: ENVKEY
891 value: ENVVALUE
892 volumes:
893 - name: nginx-persistent-storage
894 gcePersistentDisk:
895 pdName: nginx-persistent-storage
896 - configMap:
897 name: configmap-in-overlay
898 name: configmap-in-overlay
899 `)
900 th.WriteF("overlay/staging/deployment-patch2.yaml", `
901 apiVersion: apps/v1
902 kind: Deployment
903 metadata:
904 name: nginx
905 spec:
906 template:
907 spec:
908 containers:
909 - name: nginx
910 env:
911 - name: ANOTHERENV
912 value: FOO
913 `)
914 m := th.Run("overlay/staging", th.MakeDefaultOptions())
915 th.AssertActualEqualsExpected(m, `
916 apiVersion: apps/v1
917 kind: Deployment
918 metadata:
919 annotations:
920 note: This is a test annotation
921 labels:
922 app: mynginx
923 env: staging
924 org: example.com
925 team: foo
926 name: staging-team-foo-nginx
927 spec:
928 selector:
929 matchLabels:
930 app: mynginx
931 env: staging
932 org: example.com
933 team: foo
934 template:
935 metadata:
936 annotations:
937 note: This is a test annotation
938 labels:
939 app: mynginx
940 env: staging
941 org: example.com
942 team: foo
943 spec:
944 containers:
945 - env:
946 - name: ANOTHERENV
947 value: FOO
948 - name: ENVKEY
949 value: ENVVALUE
950 image: nginx:latest
951 name: nginx
952 volumeMounts:
953 - mountPath: /tmp/ps
954 name: nginx-persistent-storage
955 - image: sidecar:latest
956 name: sidecar
957 volumes:
958 - gcePersistentDisk:
959 pdName: nginx-persistent-storage
960 name: nginx-persistent-storage
961 - configMap:
962 name: staging-configmap-in-overlay-dc6fm46dhm
963 name: configmap-in-overlay
964 - configMap:
965 name: staging-team-foo-configmap-in-base-798k5k7g9f
966 name: configmap-in-base
967 ---
968 apiVersion: v1
969 kind: Service
970 metadata:
971 annotations:
972 note: This is a test annotation
973 labels:
974 app: mynginx
975 env: staging
976 org: example.com
977 team: foo
978 name: staging-team-foo-nginx
979 spec:
980 ports:
981 - port: 80
982 selector:
983 app: mynginx
984 env: staging
985 org: example.com
986 team: foo
987 ---
988 apiVersion: v1
989 data:
990 foo: bar
991 kind: ConfigMap
992 metadata:
993 annotations:
994 note: This is a test annotation
995 labels:
996 app: mynginx
997 env: staging
998 org: example.com
999 team: foo
1000 name: staging-team-foo-configmap-in-base-798k5k7g9f
1001 ---
1002 apiVersion: v1
1003 data:
1004 hello: world
1005 kind: ConfigMap
1006 metadata:
1007 labels:
1008 env: staging
1009 name: staging-configmap-in-overlay-dc6fm46dhm
1010 `)
1011 }
1012
1013 func TestNonCommutablePatches(t *testing.T) {
1014 th := kusttest_test.MakeHarness(t)
1015 makeCommonFilesForMultiplePatchTests(th)
1016 th.WriteF("overlay/staging/deployment-patch1.yaml", `
1017 apiVersion: apps/v1
1018 kind: Deployment
1019 metadata:
1020 name: nginx
1021 spec:
1022 template:
1023 spec:
1024 containers:
1025 - name: nginx
1026 env:
1027 - name: ENABLE_FEATURE_FOO
1028 value: TRUE
1029 volumes:
1030 - name: nginx-persistent-storage
1031 gcePersistentDisk:
1032 pdName: nginx-persistent-storage
1033 - configMap:
1034 name: configmap-in-overlay
1035 name: configmap-in-overlay
1036 `)
1037 th.WriteF("overlay/staging/deployment-patch2.yaml", `
1038 apiVersion: apps/v1
1039 kind: Deployment
1040 metadata:
1041 name: nginx
1042 spec:
1043 template:
1044 spec:
1045 containers:
1046 - name: nginx
1047 env:
1048 - name: ENABLE_FEATURE_FOO
1049 value: FALSE
1050 `)
1051 // kyaml doesn't try to detect conflicts in patches
1052 // (so ENABLE_FEATURE_FOO FALSE wins).
1053 m := th.Run("overlay/staging", th.MakeDefaultOptions())
1054 th.AssertActualEqualsExpected(m, `
1055 apiVersion: apps/v1
1056 kind: Deployment
1057 metadata:
1058 annotations:
1059 note: This is a test annotation
1060 labels:
1061 app: mynginx
1062 env: staging
1063 org: example.com
1064 team: foo
1065 name: staging-team-foo-nginx
1066 spec:
1067 selector:
1068 matchLabels:
1069 app: mynginx
1070 env: staging
1071 org: example.com
1072 team: foo
1073 template:
1074 metadata:
1075 annotations:
1076 note: This is a test annotation
1077 labels:
1078 app: mynginx
1079 env: staging
1080 org: example.com
1081 team: foo
1082 spec:
1083 containers:
1084 - env:
1085 - name: ENABLE_FEATURE_FOO
1086 value: false
1087 image: nginx
1088 name: nginx
1089 volumeMounts:
1090 - mountPath: /tmp/ps
1091 name: nginx-persistent-storage
1092 - image: sidecar:latest
1093 name: sidecar
1094 volumes:
1095 - gcePersistentDisk:
1096 pdName: nginx-persistent-storage
1097 name: nginx-persistent-storage
1098 - configMap:
1099 name: staging-configmap-in-overlay-dc6fm46dhm
1100 name: configmap-in-overlay
1101 - configMap:
1102 name: staging-team-foo-configmap-in-base-798k5k7g9f
1103 name: configmap-in-base
1104 ---
1105 apiVersion: v1
1106 kind: Service
1107 metadata:
1108 annotations:
1109 note: This is a test annotation
1110 labels:
1111 app: mynginx
1112 env: staging
1113 org: example.com
1114 team: foo
1115 name: staging-team-foo-nginx
1116 spec:
1117 ports:
1118 - port: 80
1119 selector:
1120 app: mynginx
1121 env: staging
1122 org: example.com
1123 team: foo
1124 ---
1125 apiVersion: v1
1126 data:
1127 foo: bar
1128 kind: ConfigMap
1129 metadata:
1130 annotations:
1131 note: This is a test annotation
1132 labels:
1133 app: mynginx
1134 env: staging
1135 org: example.com
1136 team: foo
1137 name: staging-team-foo-configmap-in-base-798k5k7g9f
1138 ---
1139 apiVersion: v1
1140 data:
1141 hello: world
1142 kind: ConfigMap
1143 metadata:
1144 labels:
1145 env: staging
1146 name: staging-configmap-in-overlay-dc6fm46dhm
1147 `)
1148 }
1149
1150 func TestMultiplePatchesWithOnePatchDeleteDirective(t *testing.T) {
1151 additivePatch := `apiVersion: apps/v1
1152 kind: Deployment
1153 metadata:
1154 name: nginx
1155 spec:
1156 template:
1157 spec:
1158 containers:
1159 - name: nginx
1160 env:
1161 - name: SOME_NAME
1162 value: somevalue
1163 `
1164 deletePatch := `apiVersion: apps/v1
1165 kind: Deployment
1166 metadata:
1167 name: nginx
1168 spec:
1169 template:
1170 spec:
1171 containers:
1172 - $patch: delete
1173 name: sidecar
1174 `
1175 cases := map[string]struct {
1176 patch1 string
1177 patch2 string
1178 expectError bool
1179 }{
1180 "Patch with delete directive first": {
1181 patch1: deletePatch,
1182 patch2: additivePatch,
1183 },
1184 "Patch with delete directive second": {
1185 patch1: additivePatch,
1186 patch2: deletePatch,
1187 },
1188 }
1189 for name := range cases {
1190 c := cases[name]
1191 t.Run(name, func(t *testing.T) {
1192 th := kusttest_test.MakeHarness(t)
1193 makeCommonFilesForMultiplePatchTests(th)
1194 th.WriteF("overlay/staging/deployment-patch1.yaml", c.patch1)
1195 th.WriteF("overlay/staging/deployment-patch2.yaml", c.patch2)
1196 m := th.Run("overlay/staging", th.MakeDefaultOptions())
1197 th.AssertActualEqualsExpected(m, `apiVersion: apps/v1
1198 kind: Deployment
1199 metadata:
1200 annotations:
1201 note: This is a test annotation
1202 labels:
1203 app: mynginx
1204 env: staging
1205 org: example.com
1206 team: foo
1207 name: staging-team-foo-nginx
1208 spec:
1209 selector:
1210 matchLabels:
1211 app: mynginx
1212 env: staging
1213 org: example.com
1214 team: foo
1215 template:
1216 metadata:
1217 annotations:
1218 note: This is a test annotation
1219 labels:
1220 app: mynginx
1221 env: staging
1222 org: example.com
1223 team: foo
1224 spec:
1225 containers:
1226 - env:
1227 - name: SOME_NAME
1228 value: somevalue
1229 image: nginx
1230 name: nginx
1231 volumeMounts:
1232 - mountPath: /tmp/ps
1233 name: nginx-persistent-storage
1234 volumes:
1235 - configMap:
1236 name: staging-team-foo-configmap-in-base-798k5k7g9f
1237 name: configmap-in-base
1238 ---
1239 apiVersion: v1
1240 kind: Service
1241 metadata:
1242 annotations:
1243 note: This is a test annotation
1244 labels:
1245 app: mynginx
1246 env: staging
1247 org: example.com
1248 team: foo
1249 name: staging-team-foo-nginx
1250 spec:
1251 ports:
1252 - port: 80
1253 selector:
1254 app: mynginx
1255 env: staging
1256 org: example.com
1257 team: foo
1258 ---
1259 apiVersion: v1
1260 data:
1261 foo: bar
1262 kind: ConfigMap
1263 metadata:
1264 annotations:
1265 note: This is a test annotation
1266 labels:
1267 app: mynginx
1268 env: staging
1269 org: example.com
1270 team: foo
1271 name: staging-team-foo-configmap-in-base-798k5k7g9f
1272 ---
1273 apiVersion: v1
1274 data:
1275 hello: world
1276 kind: ConfigMap
1277 metadata:
1278 labels:
1279 env: staging
1280 name: staging-configmap-in-overlay-dc6fm46dhm
1281 `)
1282 })
1283 }
1284 }
1285
1286 func TestSinglePatchWithMultiplePatchDeleteDirectives(t *testing.T) {
1287 th := kusttest_test.MakeHarness(t)
1288 makeCommonFilesForMultiplePatchTests(th)
1289 th.WriteF("overlay/staging/deployment-patch1.yaml", `
1290 $patch: delete
1291 apiVersion: apps/v1
1292 kind: Deployment
1293 metadata:
1294 name: nginx
1295 ---
1296 $patch: delete
1297 apiVersion: v1
1298 kind: Service
1299 metadata:
1300 name: nginx
1301 `)
1302 th.WriteF("overlay/staging/deployment-patch2.yaml", `
1303 apiVersion: v1
1304 kind: ConfigMap
1305 metadata:
1306 name: configmap-in-base
1307 data:
1308 foo2: bar2
1309 `)
1310 th.WriteK("overlay/staging", `
1311 namePrefix: staging-
1312 commonLabels:
1313 env: staging
1314 patches:
1315 - path: deployment-patch1.yaml
1316 - path: deployment-patch2.yaml
1317 resources:
1318 - ../../base
1319 configMapGenerator:
1320 - name: configmap-in-overlay
1321 literals:
1322 - hello=world
1323 `)
1324 m := th.Run("overlay/staging", th.MakeDefaultOptions())
1325 th.AssertActualEqualsExpected(m, `
1326 apiVersion: v1
1327 data:
1328 foo: bar
1329 foo2: bar2
1330 kind: ConfigMap
1331 metadata:
1332 annotations:
1333 note: This is a test annotation
1334 labels:
1335 app: mynginx
1336 env: staging
1337 org: example.com
1338 team: foo
1339 name: staging-team-foo-configmap-in-base-8cmgkm9f44
1340 ---
1341 apiVersion: v1
1342 data:
1343 hello: world
1344 kind: ConfigMap
1345 metadata:
1346 labels:
1347 env: staging
1348 name: staging-configmap-in-overlay-dc6fm46dhm
1349 `)
1350 }
1351
1352 func TestMultiplePatchesBothWithPatchDeleteDirective(t *testing.T) {
1353 th := kusttest_test.MakeHarness(t)
1354 makeCommonFilesForMultiplePatchTests(th)
1355 th.WriteF("overlay/staging/deployment-patch1.yaml", `
1356 apiVersion: apps/v1
1357 kind: Deployment
1358 metadata:
1359 name: nginx
1360 spec:
1361 template:
1362 spec:
1363 containers:
1364 - $patch: delete
1365 name: sidecar
1366 `)
1367 th.WriteF("overlay/staging/deployment-patch2.yaml", `
1368 apiVersion: apps/v1
1369 kind: Deployment
1370 metadata:
1371 name: nginx
1372 spec:
1373 template:
1374 spec:
1375 containers:
1376 - $patch: delete
1377 name: nginx
1378 `)
1379 // kyaml doesn't fail on conflicts in patches; both containers
1380 // (nginx and sidecar) are deleted per this patching instruction.
1381 m := th.Run("overlay/staging", th.MakeDefaultOptions())
1382 th.AssertActualEqualsExpected(m, `
1383 apiVersion: apps/v1
1384 kind: Deployment
1385 metadata:
1386 annotations:
1387 note: This is a test annotation
1388 labels:
1389 app: mynginx
1390 env: staging
1391 org: example.com
1392 team: foo
1393 name: staging-team-foo-nginx
1394 spec:
1395 selector:
1396 matchLabels:
1397 app: mynginx
1398 env: staging
1399 org: example.com
1400 team: foo
1401 template:
1402 metadata:
1403 annotations:
1404 note: This is a test annotation
1405 labels:
1406 app: mynginx
1407 env: staging
1408 org: example.com
1409 team: foo
1410 spec:
1411 containers: []
1412 volumes:
1413 - configMap:
1414 name: staging-team-foo-configmap-in-base-798k5k7g9f
1415 name: configmap-in-base
1416 ---
1417 apiVersion: v1
1418 kind: Service
1419 metadata:
1420 annotations:
1421 note: This is a test annotation
1422 labels:
1423 app: mynginx
1424 env: staging
1425 org: example.com
1426 team: foo
1427 name: staging-team-foo-nginx
1428 spec:
1429 ports:
1430 - port: 80
1431 selector:
1432 app: mynginx
1433 env: staging
1434 org: example.com
1435 team: foo
1436 ---
1437 apiVersion: v1
1438 data:
1439 foo: bar
1440 kind: ConfigMap
1441 metadata:
1442 annotations:
1443 note: This is a test annotation
1444 labels:
1445 app: mynginx
1446 env: staging
1447 org: example.com
1448 team: foo
1449 name: staging-team-foo-configmap-in-base-798k5k7g9f
1450 ---
1451 apiVersion: v1
1452 data:
1453 hello: world
1454 kind: ConfigMap
1455 metadata:
1456 labels:
1457 env: staging
1458 name: staging-configmap-in-overlay-dc6fm46dhm
1459 `)
1460 }
1461
1462 // test for #3513
1463 func TestSmpWithDifferentKeysOnDifferentPorts(t *testing.T) {
1464 th := kusttest_test.MakeHarness(t)
1465 th.WriteK(".", `
1466 resources:
1467 - resource.yaml
1468 patches:
1469 - path: patch.yaml
1470 target:
1471 kind: StatefulSet
1472 name: myapp
1473 `)
1474 th.WriteF("resource.yaml", `
1475 apiVersion: apps/v1
1476 kind: StatefulSet
1477 metadata:
1478 name: myapp
1479 spec:
1480 template:
1481 spec:
1482 containers:
1483 - name: consul
1484 image: "dashicorp/consul:1.9.1"
1485 ports:
1486 - containerPort: 8500
1487 name: http
1488 - containerPort: 8501
1489 name: https
1490 - containerPort: 8301
1491 protocol: "TCP"
1492 name: serflan-tcp
1493 - containerPort: 8301
1494 protocol: "UDP"
1495 name: serflan-udp
1496 - containerPort: 8302
1497 name: serfwan
1498 - containerPort: 8300
1499 name: server
1500 - containerPort: 8600
1501 name: dns-tcp
1502 protocol: "TCP"
1503 - containerPort: 8600
1504 name: dns-udp
1505 protocol: "UDP"`)
1506 th.WriteF("patch.yaml", `
1507 kind: StatefulSet
1508 metadata:
1509 name: myapp
1510 labels:
1511 test: label
1512 `)
1513 m := th.Run(".", th.MakeDefaultOptions())
1514 th.AssertActualEqualsExpected(m, `
1515 apiVersion: apps/v1
1516 kind: StatefulSet
1517 metadata:
1518 labels:
1519 test: label
1520 name: myapp
1521 spec:
1522 template:
1523 spec:
1524 containers:
1525 - image: dashicorp/consul:1.9.1
1526 name: consul
1527 ports:
1528 - containerPort: 8500
1529 name: http
1530 - containerPort: 8501
1531 name: https
1532 - containerPort: 8301
1533 name: serflan-tcp
1534 protocol: TCP
1535 - containerPort: 8301
1536 name: serflan-udp
1537 protocol: UDP
1538 - containerPort: 8302
1539 name: serfwan
1540 - containerPort: 8300
1541 name: server
1542 - containerPort: 8600
1543 name: dns-tcp
1544 protocol: TCP
1545 - containerPort: 8600
1546 name: dns-udp
1547 protocol: UDP
1548 `)
1549 }
1550
1551 // test for #3616
1552 func TestSmpDeleteOnResource(t *testing.T) {
1553 th := kusttest_test.MakeHarness(t)
1554 th.WriteK(".", `
1555 resources:
1556 - workloads.yaml
1557 patches:
1558 - patch: |
1559 apiVersion: monitoring.coreos.com/v1
1560 kind: PrometheusRule
1561 metadata:
1562 name: rule1
1563 $patch: delete
1564 `)
1565 th.WriteF("workloads.yaml", `
1566 apiVersion: monitoring.coreos.com/v1
1567 kind: PrometheusRule
1568 metadata:
1569 labels:
1570 role: alert-rules
1571 name: rule1
1572 spec:
1573 groups:
1574 - name: rabbitmq.rules
1575 ---
1576 apiVersion: monitoring.coreos.com/v1
1577 kind: PrometheusRule
1578 metadata:
1579 labels:
1580 role: alert-rules
1581 name: rule2
1582 spec:
1583 groups:
1584 - name: rabbitmq.rules
1585 `)
1586 m := th.Run(".", th.MakeDefaultOptions())
1587 th.AssertActualEqualsExpected(m, `
1588 apiVersion: monitoring.coreos.com/v1
1589 kind: PrometheusRule
1590 metadata:
1591 labels:
1592 role: alert-rules
1593 name: rule2
1594 spec:
1595 groups:
1596 - name: rabbitmq.rules
1597 `)
1598 }
1599
1600 // test for #3620
1601 func TestPatchPortHasNoProtocol(t *testing.T) {
1602 th := kusttest_test.MakeHarness(t)
1603 th.WriteK(".", `
1604 resources:
1605 - service.yaml
1606 patchesStrategicMerge:
1607 - patch.yaml
1608 `)
1609 th.WriteF("service.yaml", `
1610 apiVersion: v1
1611 kind: Service
1612 metadata:
1613 name: web
1614 spec:
1615 ports:
1616 - port: 30900
1617 targetPort: 30900
1618 protocol: TCP
1619 type: NodePort
1620 `)
1621 th.WriteF("patch.yaml", `
1622 apiVersion: v1
1623 kind: Service
1624 metadata:
1625 name: web
1626 labels:
1627 service: web
1628 spec:
1629 ports:
1630 - port: 30900
1631 targetPort: 30900
1632 selector:
1633 service: web
1634 `)
1635 m := th.Run(".", th.MakeDefaultOptions())
1636 th.AssertActualEqualsExpected(m, `
1637 apiVersion: v1
1638 kind: Service
1639 metadata:
1640 labels:
1641 service: web
1642 name: web
1643 spec:
1644 ports:
1645 - port: 30900
1646 protocol: TCP
1647 targetPort: 30900
1648 selector:
1649 service: web
1650 type: NodePort
1651 `)
1652 }
1653
1654 // test for #3620
1655 func TestPatchAddNewServicePort(t *testing.T) {
1656 th := kusttest_test.MakeHarness(t)
1657 th.WriteK(".", `
1658 resources:
1659 - service.yaml
1660 patchesStrategicMerge:
1661 - patch.yaml
1662 `)
1663 th.WriteF("service.yaml", `
1664 apiVersion: v1
1665 kind: Service
1666 metadata:
1667 name: web
1668 spec:
1669 ports:
1670 - port: 30900
1671 targetPort: 30900
1672 protocol: TCP
1673 type: NodePort
1674 `)
1675 th.WriteF("patch.yaml", `
1676 apiVersion: v1
1677 kind: Service
1678 metadata:
1679 name: web
1680 labels:
1681 service: web
1682 spec:
1683 ports:
1684 - port: 30901
1685 targetPort: 30901
1686 selector:
1687 service: web
1688 `)
1689 m := th.Run(".", th.MakeDefaultOptions())
1690 th.AssertActualEqualsExpected(m, `
1691 apiVersion: v1
1692 kind: Service
1693 metadata:
1694 labels:
1695 service: web
1696 name: web
1697 spec:
1698 ports:
1699 - port: 30901
1700 targetPort: 30901
1701 - port: 30900
1702 protocol: TCP
1703 targetPort: 30900
1704 selector:
1705 service: web
1706 type: NodePort
1707 `)
1708 }
1709
1710 // test for #4111
1711 func TestPatchPreservesInternalAnnotations(t *testing.T) {
1712 th := kusttest_test.MakeHarness(t)
1713 th.WriteK(".", `
1714 nameSuffix: -abc
1715 resources:
1716 - fluentd.yaml
1717 patchesJson6902:
1718 - path: patch.yaml
1719 target:
1720 name: fluentd-sa
1721 kind: ServiceAccount
1722 version: v1
1723 `)
1724 th.WriteF("fluentd.yaml", `
1725 apiVersion: v1
1726 kind: DaemonSet
1727 metadata:
1728 name: fluentd
1729 spec:
1730 template:
1731 spec:
1732 containers:
1733 - image: fluentd:latest
1734 name: fluentd
1735 serviceAccountName: fluentd-sa
1736 ---
1737 apiVersion: v1
1738 kind: ServiceAccount
1739 metadata:
1740 name: fluentd-sa
1741 `)
1742 th.WriteF("patch.yaml", `
1743 - op: add
1744 path: /metadata/annotations
1745 value:
1746 note: this is a test annotation
1747 `)
1748 m := th.Run(".", th.MakeDefaultOptions())
1749 th.AssertActualEqualsExpected(m, `
1750 apiVersion: v1
1751 kind: DaemonSet
1752 metadata:
1753 name: fluentd-abc
1754 spec:
1755 template:
1756 spec:
1757 containers:
1758 - image: fluentd:latest
1759 name: fluentd
1760 serviceAccountName: fluentd-sa-abc
1761 ---
1762 apiVersion: v1
1763 kind: ServiceAccount
1764 metadata:
1765 annotations:
1766 note: this is a test annotation
1767 name: fluentd-sa-abc
1768 `)
1769 }
1770
1771 // TestEmptyPatchFilesShouldBeIgnored verifies that empty patch files are ignored.
1772 // Tests three cases:
1773 // 1. Completely empty file
1774 // 2. File with only comments
1775 // 3. File with whitespace and comments
1776 func TestEmptyPatchFilesShouldBeIgnored(t *testing.T) {
1777 th := kusttest_test.MakeHarness(t)
1778
1779 // Write a basic resource
1780 th.WriteF("deployment.yaml", `
1781 apiVersion: apps/v1
1782 kind: Deployment
1783 metadata:
1784 name: nginx
1785 spec:
1786 template:
1787 spec:
1788 containers:
1789 - name: nginx
1790 image: nginx
1791 `)
1792
1793 // Create empty patch files of different types
1794 th.WriteF("empty.yaml", ``)
1795 th.WriteF("comments-only.yaml", `
1796 # This is a comment
1797 # Another comment
1798 `)
1799 th.WriteF("whitespace.yaml", `
1800
1801 # Comments with whitespace
1802
1803 # Indented comment
1804
1805 `)
1806
1807 // Reference empty patches in kustomization
1808 th.WriteK(".", `
1809 resources:
1810 - deployment.yaml
1811 patches:
1812 - path: empty.yaml
1813 - path: comments-only.yaml
1814 - path: whitespace.yaml
1815 `)
1816
1817 // Empty patches should be ignored, output should be unchanged
1818 m := th.Run(".", th.MakeDefaultOptions())
1819 th.AssertActualEqualsExpected(m, `
1820 apiVersion: apps/v1
1821 kind: Deployment
1822 metadata:
1823 name: nginx
1824 spec:
1825 template:
1826 spec:
1827 containers:
1828 - image: nginx
1829 name: nginx
1830 `)
1831 }
1832
1833 // TestEmptyPatchesStrategicMergeFails verifies that empty patch files are
1834 // handled correctly with the deprecated patchesStrategicMerge field
1835 func TestEmptyPatchesStrategicMergeFails(t *testing.T) {
1836 th := kusttest_test.MakeHarness(t)
1837
1838 // Create a basic resource
1839 th.WriteF("resource.yaml", `
1840 apiVersion: v1
1841 kind: ConfigMap
1842 metadata:
1843 name: dummy
1844 data:
1845 dummy: value
1846 `)
1847
1848 // Create an empty patch file
1849 th.WriteF("empty-patch.yaml", ``)
1850
1851 // Create a patch file with only comments
1852 th.WriteF("comments-patch.yaml", `
1853 # This is just a comment
1854 # Another comment
1855 `)
1856
1857 // Create kustomization using patchesStrategicMerge
1858 th.WriteK(".", `
1859 resources:
1860 - resource.yaml
1861 patchesStrategicMerge:
1862 - empty-patch.yaml
1863 - comments-patch.yaml
1864 `)
1865
1866 // This fails with message
1867 err := th.RunWithErr(".", th.MakeDefaultOptions())
1868 if err == nil {
1869 t.Fatalf("expected error for empty patchesStrategicMerge files but got none")
1870 }
1871 if !strings.Contains(err.Error(), "patch appears to be empty") {
1872 t.Fatalf("unexpected error: %v", err)
1873 }
1874 }