| 1 |
// Copyright 2019 The Kubernetes Authors. |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package krusty_test |
| 5 |
|
| 6 |
import ( |
| 7 |
"testing" |
| 8 |
|
| 9 |
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" |
| 10 |
) |
| 11 |
|
| 12 |
func makeCommonFileForExtendedPatchTest(th kusttest_test.Harness) { |
| 13 |
th.WriteF("base/deployment.yaml", ` |
| 14 |
apiVersion: apps/v1 |
| 15 |
kind: Deployment |
| 16 |
metadata: |
| 17 |
name: nginx |
| 18 |
labels: |
| 19 |
app: nginx |
| 20 |
spec: |
| 21 |
template: |
| 22 |
metadata: |
| 23 |
labels: |
| 24 |
app: nginx |
| 25 |
spec: |
| 26 |
containers: |
| 27 |
- name: nginx |
| 28 |
image: nginx |
| 29 |
volumeMounts: |
| 30 |
- name: nginx-persistent-storage |
| 31 |
mountPath: /tmp/ps |
| 32 |
volumes: |
| 33 |
- name: nginx-persistent-storage |
| 34 |
emptyDir: {} |
| 35 |
- configMap: |
| 36 |
name: configmap-in-base |
| 37 |
name: configmap-in-base |
| 38 |
--- |
| 39 |
apiVersion: apps/v1 |
| 40 |
kind: Deployment |
| 41 |
metadata: |
| 42 |
name: busybox |
| 43 |
labels: |
| 44 |
app: busybox |
| 45 |
spec: |
| 46 |
template: |
| 47 |
metadata: |
| 48 |
labels: |
| 49 |
app: busybox |
| 50 |
spec: |
| 51 |
containers: |
| 52 |
- name: busybox |
| 53 |
image: busybox |
| 54 |
volumeMounts: |
| 55 |
- name: busybox-persistent-storage |
| 56 |
mountPath: /tmp/ps |
| 57 |
volumes: |
| 58 |
- name: busybox-persistent-storage |
| 59 |
emptyDir: {} |
| 60 |
- configMap: |
| 61 |
name: configmap-in-base |
| 62 |
name: configmap-in-base |
| 63 |
`) |
| 64 |
th.WriteF("base/service.yaml", ` |
| 65 |
apiVersion: v1 |
| 66 |
kind: Service |
| 67 |
metadata: |
| 68 |
name: nginx |
| 69 |
labels: |
| 70 |
app: nginx |
| 71 |
spec: |
| 72 |
ports: |
| 73 |
- port: 80 |
| 74 |
selector: |
| 75 |
app: nginx |
| 76 |
--- |
| 77 |
apiVersion: v1 |
| 78 |
kind: Service |
| 79 |
metadata: |
| 80 |
name: busybox |
| 81 |
labels: |
| 82 |
app: busybox |
| 83 |
spec: |
| 84 |
ports: |
| 85 |
- port: 8080 |
| 86 |
selector: |
| 87 |
app: busybox |
| 88 |
`) |
| 89 |
} |
| 90 |
|
| 91 |
func TestExtendedPatchNameSelector(t *testing.T) { |
| 92 |
th := kusttest_test.MakeHarness(t) |
| 93 |
makeCommonFileForExtendedPatchTest(th) |
| 94 |
th.WriteK("base", ` |
| 95 |
resources: |
| 96 |
- deployment.yaml |
| 97 |
- service.yaml |
| 98 |
patches: |
| 99 |
- path: patch.yaml |
| 100 |
target: |
| 101 |
name: busybox |
| 102 |
`) |
| 103 |
th.WriteF("base/patch.yaml", ` |
| 104 |
apiVersion: apps/v1 |
| 105 |
kind: Deployment |
| 106 |
metadata: |
| 107 |
name: busybox |
| 108 |
annotations: |
| 109 |
new-key: new-value |
| 110 |
`) |
| 111 |
m := th.Run("base", th.MakeDefaultOptions()) |
| 112 |
th.AssertActualEqualsExpected(m, ` |
| 113 |
apiVersion: apps/v1 |
| 114 |
kind: Deployment |
| 115 |
metadata: |
| 116 |
labels: |
| 117 |
app: nginx |
| 118 |
name: nginx |
| 119 |
spec: |
| 120 |
template: |
| 121 |
metadata: |
| 122 |
labels: |
| 123 |
app: nginx |
| 124 |
spec: |
| 125 |
containers: |
| 126 |
- image: nginx |
| 127 |
name: nginx |
| 128 |
volumeMounts: |
| 129 |
- mountPath: /tmp/ps |
| 130 |
name: nginx-persistent-storage |
| 131 |
volumes: |
| 132 |
- emptyDir: {} |
| 133 |
name: nginx-persistent-storage |
| 134 |
- configMap: |
| 135 |
name: configmap-in-base |
| 136 |
name: configmap-in-base |
| 137 |
--- |
| 138 |
apiVersion: apps/v1 |
| 139 |
kind: Deployment |
| 140 |
metadata: |
| 141 |
annotations: |
| 142 |
new-key: new-value |
| 143 |
labels: |
| 144 |
app: busybox |
| 145 |
name: busybox |
| 146 |
spec: |
| 147 |
template: |
| 148 |
metadata: |
| 149 |
labels: |
| 150 |
app: busybox |
| 151 |
spec: |
| 152 |
containers: |
| 153 |
- image: busybox |
| 154 |
name: busybox |
| 155 |
volumeMounts: |
| 156 |
- mountPath: /tmp/ps |
| 157 |
name: busybox-persistent-storage |
| 158 |
volumes: |
| 159 |
- emptyDir: {} |
| 160 |
name: busybox-persistent-storage |
| 161 |
- configMap: |
| 162 |
name: configmap-in-base |
| 163 |
name: configmap-in-base |
| 164 |
--- |
| 165 |
apiVersion: v1 |
| 166 |
kind: Service |
| 167 |
metadata: |
| 168 |
labels: |
| 169 |
app: nginx |
| 170 |
name: nginx |
| 171 |
spec: |
| 172 |
ports: |
| 173 |
- port: 80 |
| 174 |
selector: |
| 175 |
app: nginx |
| 176 |
--- |
| 177 |
apiVersion: v1 |
| 178 |
kind: Service |
| 179 |
metadata: |
| 180 |
annotations: |
| 181 |
new-key: new-value |
| 182 |
labels: |
| 183 |
app: busybox |
| 184 |
name: busybox |
| 185 |
spec: |
| 186 |
ports: |
| 187 |
- port: 8080 |
| 188 |
selector: |
| 189 |
app: busybox |
| 190 |
`) |
| 191 |
} |
| 192 |
|
| 193 |
func TestExtendedPatchGvkSelector(t *testing.T) { |
| 194 |
th := kusttest_test.MakeHarness(t) |
| 195 |
makeCommonFileForExtendedPatchTest(th) |
| 196 |
th.WriteK("base", ` |
| 197 |
resources: |
| 198 |
- deployment.yaml |
| 199 |
- service.yaml |
| 200 |
patches: |
| 201 |
- path: patch.yaml |
| 202 |
target: |
| 203 |
kind: Deployment |
| 204 |
`) |
| 205 |
th.WriteF("base/patch.yaml", ` |
| 206 |
apiVersion: apps/v1 |
| 207 |
kind: Deployment |
| 208 |
metadata: |
| 209 |
name: busybox |
| 210 |
annotations: |
| 211 |
new-key: new-value |
| 212 |
`) |
| 213 |
m := th.Run("base", th.MakeDefaultOptions()) |
| 214 |
th.AssertActualEqualsExpected(m, ` |
| 215 |
apiVersion: apps/v1 |
| 216 |
kind: Deployment |
| 217 |
metadata: |
| 218 |
annotations: |
| 219 |
new-key: new-value |
| 220 |
labels: |
| 221 |
app: nginx |
| 222 |
name: nginx |
| 223 |
spec: |
| 224 |
template: |
| 225 |
metadata: |
| 226 |
labels: |
| 227 |
app: nginx |
| 228 |
spec: |
| 229 |
containers: |
| 230 |
- image: nginx |
| 231 |
name: nginx |
| 232 |
volumeMounts: |
| 233 |
- mountPath: /tmp/ps |
| 234 |
name: nginx-persistent-storage |
| 235 |
volumes: |
| 236 |
- emptyDir: {} |
| 237 |
name: nginx-persistent-storage |
| 238 |
- configMap: |
| 239 |
name: configmap-in-base |
| 240 |
name: configmap-in-base |
| 241 |
--- |
| 242 |
apiVersion: apps/v1 |
| 243 |
kind: Deployment |
| 244 |
metadata: |
| 245 |
annotations: |
| 246 |
new-key: new-value |
| 247 |
labels: |
| 248 |
app: busybox |
| 249 |
name: busybox |
| 250 |
spec: |
| 251 |
template: |
| 252 |
metadata: |
| 253 |
labels: |
| 254 |
app: busybox |
| 255 |
spec: |
| 256 |
containers: |
| 257 |
- image: busybox |
| 258 |
name: busybox |
| 259 |
volumeMounts: |
| 260 |
- mountPath: /tmp/ps |
| 261 |
name: busybox-persistent-storage |
| 262 |
volumes: |
| 263 |
- emptyDir: {} |
| 264 |
name: busybox-persistent-storage |
| 265 |
- configMap: |
| 266 |
name: configmap-in-base |
| 267 |
name: configmap-in-base |
| 268 |
--- |
| 269 |
apiVersion: v1 |
| 270 |
kind: Service |
| 271 |
metadata: |
| 272 |
labels: |
| 273 |
app: nginx |
| 274 |
name: nginx |
| 275 |
spec: |
| 276 |
ports: |
| 277 |
- port: 80 |
| 278 |
selector: |
| 279 |
app: nginx |
| 280 |
--- |
| 281 |
apiVersion: v1 |
| 282 |
kind: Service |
| 283 |
metadata: |
| 284 |
labels: |
| 285 |
app: busybox |
| 286 |
name: busybox |
| 287 |
spec: |
| 288 |
ports: |
| 289 |
- port: 8080 |
| 290 |
selector: |
| 291 |
app: busybox |
| 292 |
`) |
| 293 |
} |
| 294 |
|
| 295 |
func TestExtendedPatchLabelSelector(t *testing.T) { |
| 296 |
th := kusttest_test.MakeHarness(t) |
| 297 |
makeCommonFileForExtendedPatchTest(th) |
| 298 |
th.WriteK("base", ` |
| 299 |
resources: |
| 300 |
- deployment.yaml |
| 301 |
- service.yaml |
| 302 |
patches: |
| 303 |
- path: patch.yaml |
| 304 |
target: |
| 305 |
labelSelector: app=nginx |
| 306 |
`) |
| 307 |
th.WriteF("base/patch.yaml", ` |
| 308 |
apiVersion: apps/v1 |
| 309 |
kind: Deployment |
| 310 |
metadata: |
| 311 |
name: nginx |
| 312 |
annotations: |
| 313 |
new-key: new-value |
| 314 |
`) |
| 315 |
m := th.Run("base", th.MakeDefaultOptions()) |
| 316 |
th.AssertActualEqualsExpected(m, ` |
| 317 |
apiVersion: apps/v1 |
| 318 |
kind: Deployment |
| 319 |
metadata: |
| 320 |
annotations: |
| 321 |
new-key: new-value |
| 322 |
labels: |
| 323 |
app: nginx |
| 324 |
name: nginx |
| 325 |
spec: |
| 326 |
template: |
| 327 |
metadata: |
| 328 |
labels: |
| 329 |
app: nginx |
| 330 |
spec: |
| 331 |
containers: |
| 332 |
- image: nginx |
| 333 |
name: nginx |
| 334 |
volumeMounts: |
| 335 |
- mountPath: /tmp/ps |
| 336 |
name: nginx-persistent-storage |
| 337 |
volumes: |
| 338 |
- emptyDir: {} |
| 339 |
name: nginx-persistent-storage |
| 340 |
- configMap: |
| 341 |
name: configmap-in-base |
| 342 |
name: configmap-in-base |
| 343 |
--- |
| 344 |
apiVersion: apps/v1 |
| 345 |
kind: Deployment |
| 346 |
metadata: |
| 347 |
labels: |
| 348 |
app: busybox |
| 349 |
name: busybox |
| 350 |
spec: |
| 351 |
template: |
| 352 |
metadata: |
| 353 |
labels: |
| 354 |
app: busybox |
| 355 |
spec: |
| 356 |
containers: |
| 357 |
- image: busybox |
| 358 |
name: busybox |
| 359 |
volumeMounts: |
| 360 |
- mountPath: /tmp/ps |
| 361 |
name: busybox-persistent-storage |
| 362 |
volumes: |
| 363 |
- emptyDir: {} |
| 364 |
name: busybox-persistent-storage |
| 365 |
- configMap: |
| 366 |
name: configmap-in-base |
| 367 |
name: configmap-in-base |
| 368 |
--- |
| 369 |
apiVersion: v1 |
| 370 |
kind: Service |
| 371 |
metadata: |
| 372 |
annotations: |
| 373 |
new-key: new-value |
| 374 |
labels: |
| 375 |
app: nginx |
| 376 |
name: nginx |
| 377 |
spec: |
| 378 |
ports: |
| 379 |
- port: 80 |
| 380 |
selector: |
| 381 |
app: nginx |
| 382 |
--- |
| 383 |
apiVersion: v1 |
| 384 |
kind: Service |
| 385 |
metadata: |
| 386 |
labels: |
| 387 |
app: busybox |
| 388 |
name: busybox |
| 389 |
spec: |
| 390 |
ports: |
| 391 |
- port: 8080 |
| 392 |
selector: |
| 393 |
app: busybox |
| 394 |
`) |
| 395 |
} |
| 396 |
|
| 397 |
func TestExtendedPatchNameGvkSelector(t *testing.T) { |
| 398 |
th := kusttest_test.MakeHarness(t) |
| 399 |
makeCommonFileForExtendedPatchTest(th) |
| 400 |
th.WriteK("base", ` |
| 401 |
resources: |
| 402 |
- deployment.yaml |
| 403 |
- service.yaml |
| 404 |
patches: |
| 405 |
- path: patch.yaml |
| 406 |
target: |
| 407 |
name: busybox |
| 408 |
kind: Deployment |
| 409 |
`) |
| 410 |
th.WriteF("base/patch.yaml", ` |
| 411 |
apiVersion: apps/v1 |
| 412 |
kind: Deployment |
| 413 |
metadata: |
| 414 |
name: busybox |
| 415 |
annotations: |
| 416 |
new-key: new-value |
| 417 |
`) |
| 418 |
m := th.Run("base", th.MakeDefaultOptions()) |
| 419 |
th.AssertActualEqualsExpected(m, ` |
| 420 |
apiVersion: apps/v1 |
| 421 |
kind: Deployment |
| 422 |
metadata: |
| 423 |
labels: |
| 424 |
app: nginx |
| 425 |
name: nginx |
| 426 |
spec: |
| 427 |
template: |
| 428 |
metadata: |
| 429 |
labels: |
| 430 |
app: nginx |
| 431 |
spec: |
| 432 |
containers: |
| 433 |
- image: nginx |
| 434 |
name: nginx |
| 435 |
volumeMounts: |
| 436 |
- mountPath: /tmp/ps |
| 437 |
name: nginx-persistent-storage |
| 438 |
volumes: |
| 439 |
- emptyDir: {} |
| 440 |
name: nginx-persistent-storage |
| 441 |
- configMap: |
| 442 |
name: configmap-in-base |
| 443 |
name: configmap-in-base |
| 444 |
--- |
| 445 |
apiVersion: apps/v1 |
| 446 |
kind: Deployment |
| 447 |
metadata: |
| 448 |
annotations: |
| 449 |
new-key: new-value |
| 450 |
labels: |
| 451 |
app: busybox |
| 452 |
name: busybox |
| 453 |
spec: |
| 454 |
template: |
| 455 |
metadata: |
| 456 |
labels: |
| 457 |
app: busybox |
| 458 |
spec: |
| 459 |
containers: |
| 460 |
- image: busybox |
| 461 |
name: busybox |
| 462 |
volumeMounts: |
| 463 |
- mountPath: /tmp/ps |
| 464 |
name: busybox-persistent-storage |
| 465 |
volumes: |
| 466 |
- emptyDir: {} |
| 467 |
name: busybox-persistent-storage |
| 468 |
- configMap: |
| 469 |
name: configmap-in-base |
| 470 |
name: configmap-in-base |
| 471 |
--- |
| 472 |
apiVersion: v1 |
| 473 |
kind: Service |
| 474 |
metadata: |
| 475 |
labels: |
| 476 |
app: nginx |
| 477 |
name: nginx |
| 478 |
spec: |
| 479 |
ports: |
| 480 |
- port: 80 |
| 481 |
selector: |
| 482 |
app: nginx |
| 483 |
--- |
| 484 |
apiVersion: v1 |
| 485 |
kind: Service |
| 486 |
metadata: |
| 487 |
labels: |
| 488 |
app: busybox |
| 489 |
name: busybox |
| 490 |
spec: |
| 491 |
ports: |
| 492 |
- port: 8080 |
| 493 |
selector: |
| 494 |
app: busybox |
| 495 |
`) |
| 496 |
} |
| 497 |
|
| 498 |
func TestExtendedPatchNameLabelSelector(t *testing.T) { |
| 499 |
th := kusttest_test.MakeHarness(t) |
| 500 |
makeCommonFileForExtendedPatchTest(th) |
| 501 |
th.WriteK("base", ` |
| 502 |
resources: |
| 503 |
- deployment.yaml |
| 504 |
- service.yaml |
| 505 |
patches: |
| 506 |
- path: patch.yaml |
| 507 |
target: |
| 508 |
name: .* |
| 509 |
labelSelector: app=busybox |
| 510 |
`) |
| 511 |
th.WriteF("base/patch.yaml", ` |
| 512 |
apiVersion: apps/v1 |
| 513 |
kind: Deployment |
| 514 |
metadata: |
| 515 |
name: busybox |
| 516 |
annotations: |
| 517 |
new-key: new-value |
| 518 |
`) |
| 519 |
m := th.Run("base", th.MakeDefaultOptions()) |
| 520 |
th.AssertActualEqualsExpected(m, ` |
| 521 |
apiVersion: apps/v1 |
| 522 |
kind: Deployment |
| 523 |
metadata: |
| 524 |
labels: |
| 525 |
app: nginx |
| 526 |
name: nginx |
| 527 |
spec: |
| 528 |
template: |
| 529 |
metadata: |
| 530 |
labels: |
| 531 |
app: nginx |
| 532 |
spec: |
| 533 |
containers: |
| 534 |
- image: nginx |
| 535 |
name: nginx |
| 536 |
volumeMounts: |
| 537 |
- mountPath: /tmp/ps |
| 538 |
name: nginx-persistent-storage |
| 539 |
volumes: |
| 540 |
- emptyDir: {} |
| 541 |
name: nginx-persistent-storage |
| 542 |
- configMap: |
| 543 |
name: configmap-in-base |
| 544 |
name: configmap-in-base |
| 545 |
--- |
| 546 |
apiVersion: apps/v1 |
| 547 |
kind: Deployment |
| 548 |
metadata: |
| 549 |
annotations: |
| 550 |
new-key: new-value |
| 551 |
labels: |
| 552 |
app: busybox |
| 553 |
name: busybox |
| 554 |
spec: |
| 555 |
template: |
| 556 |
metadata: |
| 557 |
labels: |
| 558 |
app: busybox |
| 559 |
spec: |
| 560 |
containers: |
| 561 |
- image: busybox |
| 562 |
name: busybox |
| 563 |
volumeMounts: |
| 564 |
- mountPath: /tmp/ps |
| 565 |
name: busybox-persistent-storage |
| 566 |
volumes: |
| 567 |
- emptyDir: {} |
| 568 |
name: busybox-persistent-storage |
| 569 |
- configMap: |
| 570 |
name: configmap-in-base |
| 571 |
name: configmap-in-base |
| 572 |
--- |
| 573 |
apiVersion: v1 |
| 574 |
kind: Service |
| 575 |
metadata: |
| 576 |
labels: |
| 577 |
app: nginx |
| 578 |
name: nginx |
| 579 |
spec: |
| 580 |
ports: |
| 581 |
- port: 80 |
| 582 |
selector: |
| 583 |
app: nginx |
| 584 |
--- |
| 585 |
apiVersion: v1 |
| 586 |
kind: Service |
| 587 |
metadata: |
| 588 |
annotations: |
| 589 |
new-key: new-value |
| 590 |
labels: |
| 591 |
app: busybox |
| 592 |
name: busybox |
| 593 |
spec: |
| 594 |
ports: |
| 595 |
- port: 8080 |
| 596 |
selector: |
| 597 |
app: busybox |
| 598 |
`) |
| 599 |
} |
| 600 |
|
| 601 |
func TestExtendedPatchGvkLabelSelector(t *testing.T) { |
| 602 |
th := kusttest_test.MakeHarness(t) |
| 603 |
makeCommonFileForExtendedPatchTest(th) |
| 604 |
th.WriteK("base", ` |
| 605 |
resources: |
| 606 |
- deployment.yaml |
| 607 |
- service.yaml |
| 608 |
patches: |
| 609 |
- path: patch.yaml |
| 610 |
target: |
| 611 |
kind: Deployment |
| 612 |
labelSelector: app=busybox |
| 613 |
`) |
| 614 |
th.WriteF("base/patch.yaml", ` |
| 615 |
apiVersion: apps/v1 |
| 616 |
kind: Deployment |
| 617 |
metadata: |
| 618 |
name: busybox |
| 619 |
annotations: |
| 620 |
new-key: new-value |
| 621 |
`) |
| 622 |
m := th.Run("base", th.MakeDefaultOptions()) |
| 623 |
th.AssertActualEqualsExpected(m, ` |
| 624 |
apiVersion: apps/v1 |
| 625 |
kind: Deployment |
| 626 |
metadata: |
| 627 |
labels: |
| 628 |
app: nginx |
| 629 |
name: nginx |
| 630 |
spec: |
| 631 |
template: |
| 632 |
metadata: |
| 633 |
labels: |
| 634 |
app: nginx |
| 635 |
spec: |
| 636 |
containers: |
| 637 |
- image: nginx |
| 638 |
name: nginx |
| 639 |
volumeMounts: |
| 640 |
- mountPath: /tmp/ps |
| 641 |
name: nginx-persistent-storage |
| 642 |
volumes: |
| 643 |
- emptyDir: {} |
| 644 |
name: nginx-persistent-storage |
| 645 |
- configMap: |
| 646 |
name: configmap-in-base |
| 647 |
name: configmap-in-base |
| 648 |
--- |
| 649 |
apiVersion: apps/v1 |
| 650 |
kind: Deployment |
| 651 |
metadata: |
| 652 |
annotations: |
| 653 |
new-key: new-value |
| 654 |
labels: |
| 655 |
app: busybox |
| 656 |
name: busybox |
| 657 |
spec: |
| 658 |
template: |
| 659 |
metadata: |
| 660 |
labels: |
| 661 |
app: busybox |
| 662 |
spec: |
| 663 |
containers: |
| 664 |
- image: busybox |
| 665 |
name: busybox |
| 666 |
volumeMounts: |
| 667 |
- mountPath: /tmp/ps |
| 668 |
name: busybox-persistent-storage |
| 669 |
volumes: |
| 670 |
- emptyDir: {} |
| 671 |
name: busybox-persistent-storage |
| 672 |
- configMap: |
| 673 |
name: configmap-in-base |
| 674 |
name: configmap-in-base |
| 675 |
--- |
| 676 |
apiVersion: v1 |
| 677 |
kind: Service |
| 678 |
metadata: |
| 679 |
labels: |
| 680 |
app: nginx |
| 681 |
name: nginx |
| 682 |
spec: |
| 683 |
ports: |
| 684 |
- port: 80 |
| 685 |
selector: |
| 686 |
app: nginx |
| 687 |
--- |
| 688 |
apiVersion: v1 |
| 689 |
kind: Service |
| 690 |
metadata: |
| 691 |
labels: |
| 692 |
app: busybox |
| 693 |
name: busybox |
| 694 |
spec: |
| 695 |
ports: |
| 696 |
- port: 8080 |
| 697 |
selector: |
| 698 |
app: busybox |
| 699 |
`) |
| 700 |
} |
| 701 |
|
| 702 |
func TestExtendedPatchNameGvkLabelSelector(t *testing.T) { |
| 703 |
th := kusttest_test.MakeHarness(t) |
| 704 |
makeCommonFileForExtendedPatchTest(th) |
| 705 |
th.WriteK("base", ` |
| 706 |
resources: |
| 707 |
- deployment.yaml |
| 708 |
- service.yaml |
| 709 |
patches: |
| 710 |
- path: patch.yaml |
| 711 |
target: |
| 712 |
name: busybox |
| 713 |
kind: Deployment |
| 714 |
labelSelector: app=busybox |
| 715 |
`) |
| 716 |
th.WriteF("base/patch.yaml", ` |
| 717 |
apiVersion: apps/v1 |
| 718 |
kind: Deployment |
| 719 |
metadata: |
| 720 |
name: busybox |
| 721 |
annotations: |
| 722 |
new-key: new-value |
| 723 |
`) |
| 724 |
m := th.Run("base", th.MakeDefaultOptions()) |
| 725 |
th.AssertActualEqualsExpected(m, ` |
| 726 |
apiVersion: apps/v1 |
| 727 |
kind: Deployment |
| 728 |
metadata: |
| 729 |
labels: |
| 730 |
app: nginx |
| 731 |
name: nginx |
| 732 |
spec: |
| 733 |
template: |
| 734 |
metadata: |
| 735 |
labels: |
| 736 |
app: nginx |
| 737 |
spec: |
| 738 |
containers: |
| 739 |
- image: nginx |
| 740 |
name: nginx |
| 741 |
volumeMounts: |
| 742 |
- mountPath: /tmp/ps |
| 743 |
name: nginx-persistent-storage |
| 744 |
volumes: |
| 745 |
- emptyDir: {} |
| 746 |
name: nginx-persistent-storage |
| 747 |
- configMap: |
| 748 |
name: configmap-in-base |
| 749 |
name: configmap-in-base |
| 750 |
--- |
| 751 |
apiVersion: apps/v1 |
| 752 |
kind: Deployment |
| 753 |
metadata: |
| 754 |
annotations: |
| 755 |
new-key: new-value |
| 756 |
labels: |
| 757 |
app: busybox |
| 758 |
name: busybox |
| 759 |
spec: |
| 760 |
template: |
| 761 |
metadata: |
| 762 |
labels: |
| 763 |
app: busybox |
| 764 |
spec: |
| 765 |
containers: |
| 766 |
- image: busybox |
| 767 |
name: busybox |
| 768 |
volumeMounts: |
| 769 |
- mountPath: /tmp/ps |
| 770 |
name: busybox-persistent-storage |
| 771 |
volumes: |
| 772 |
- emptyDir: {} |
| 773 |
name: busybox-persistent-storage |
| 774 |
- configMap: |
| 775 |
name: configmap-in-base |
| 776 |
name: configmap-in-base |
| 777 |
--- |
| 778 |
apiVersion: v1 |
| 779 |
kind: Service |
| 780 |
metadata: |
| 781 |
labels: |
| 782 |
app: nginx |
| 783 |
name: nginx |
| 784 |
spec: |
| 785 |
ports: |
| 786 |
- port: 80 |
| 787 |
selector: |
| 788 |
app: nginx |
| 789 |
--- |
| 790 |
apiVersion: v1 |
| 791 |
kind: Service |
| 792 |
metadata: |
| 793 |
labels: |
| 794 |
app: busybox |
| 795 |
name: busybox |
| 796 |
spec: |
| 797 |
ports: |
| 798 |
- port: 8080 |
| 799 |
selector: |
| 800 |
app: busybox |
| 801 |
`) |
| 802 |
} |
| 803 |
|
| 804 |
func TestExtendedPatchNoMatch(t *testing.T) { |
| 805 |
th := kusttest_test.MakeHarness(t) |
| 806 |
makeCommonFileForExtendedPatchTest(th) |
| 807 |
th.WriteK("base", ` |
| 808 |
resources: |
| 809 |
- deployment.yaml |
| 810 |
- service.yaml |
| 811 |
patches: |
| 812 |
- path: patch.yaml |
| 813 |
target: |
| 814 |
name: no-match |
| 815 |
`) |
| 816 |
th.WriteF("base/patch.yaml", ` |
| 817 |
apiVersion: apps/v1 |
| 818 |
kind: Deployment |
| 819 |
metadata: |
| 820 |
name: busybox |
| 821 |
annotations: |
| 822 |
new-key: new-value |
| 823 |
`) |
| 824 |
m := th.Run("base", th.MakeDefaultOptions()) |
| 825 |
th.AssertActualEqualsExpected(m, ` |
| 826 |
apiVersion: apps/v1 |
| 827 |
kind: Deployment |
| 828 |
metadata: |
| 829 |
labels: |
| 830 |
app: nginx |
| 831 |
name: nginx |
| 832 |
spec: |
| 833 |
template: |
| 834 |
metadata: |
| 835 |
labels: |
| 836 |
app: nginx |
| 837 |
spec: |
| 838 |
containers: |
| 839 |
- image: nginx |
| 840 |
name: nginx |
| 841 |
volumeMounts: |
| 842 |
- mountPath: /tmp/ps |
| 843 |
name: nginx-persistent-storage |
| 844 |
volumes: |
| 845 |
- emptyDir: {} |
| 846 |
name: nginx-persistent-storage |
| 847 |
- configMap: |
| 848 |
name: configmap-in-base |
| 849 |
name: configmap-in-base |
| 850 |
--- |
| 851 |
apiVersion: apps/v1 |
| 852 |
kind: Deployment |
| 853 |
metadata: |
| 854 |
labels: |
| 855 |
app: busybox |
| 856 |
name: busybox |
| 857 |
spec: |
| 858 |
template: |
| 859 |
metadata: |
| 860 |
labels: |
| 861 |
app: busybox |
| 862 |
spec: |
| 863 |
containers: |
| 864 |
- image: busybox |
| 865 |
name: busybox |
| 866 |
volumeMounts: |
| 867 |
- mountPath: /tmp/ps |
| 868 |
name: busybox-persistent-storage |
| 869 |
volumes: |
| 870 |
- emptyDir: {} |
| 871 |
name: busybox-persistent-storage |
| 872 |
- configMap: |
| 873 |
name: configmap-in-base |
| 874 |
name: configmap-in-base |
| 875 |
--- |
| 876 |
apiVersion: v1 |
| 877 |
kind: Service |
| 878 |
metadata: |
| 879 |
labels: |
| 880 |
app: nginx |
| 881 |
name: nginx |
| 882 |
spec: |
| 883 |
ports: |
| 884 |
- port: 80 |
| 885 |
selector: |
| 886 |
app: nginx |
| 887 |
--- |
| 888 |
apiVersion: v1 |
| 889 |
kind: Service |
| 890 |
metadata: |
| 891 |
labels: |
| 892 |
app: busybox |
| 893 |
name: busybox |
| 894 |
spec: |
| 895 |
ports: |
| 896 |
- port: 8080 |
| 897 |
selector: |
| 898 |
app: busybox |
| 899 |
`) |
| 900 |
} |
| 901 |
|
| 902 |
func TestExtendedPatchWithoutTarget(t *testing.T) { |
| 903 |
th := kusttest_test.MakeHarness(t) |
| 904 |
makeCommonFileForExtendedPatchTest(th) |
| 905 |
th.WriteK("base", ` |
| 906 |
resources: |
| 907 |
- deployment.yaml |
| 908 |
- service.yaml |
| 909 |
patches: |
| 910 |
- path: patch.yaml |
| 911 |
`) |
| 912 |
th.WriteF("base/patch.yaml", ` |
| 913 |
apiVersion: apps/v1 |
| 914 |
kind: Deployment |
| 915 |
metadata: |
| 916 |
name: busybox |
| 917 |
annotations: |
| 918 |
new-key: new-value |
| 919 |
`) |
| 920 |
m := th.Run("base", th.MakeDefaultOptions()) |
| 921 |
th.AssertActualEqualsExpected(m, ` |
| 922 |
apiVersion: apps/v1 |
| 923 |
kind: Deployment |
| 924 |
metadata: |
| 925 |
labels: |
| 926 |
app: nginx |
| 927 |
name: nginx |
| 928 |
spec: |
| 929 |
template: |
| 930 |
metadata: |
| 931 |
labels: |
| 932 |
app: nginx |
| 933 |
spec: |
| 934 |
containers: |
| 935 |
- image: nginx |
| 936 |
name: nginx |
| 937 |
volumeMounts: |
| 938 |
- mountPath: /tmp/ps |
| 939 |
name: nginx-persistent-storage |
| 940 |
volumes: |
| 941 |
- emptyDir: {} |
| 942 |
name: nginx-persistent-storage |
| 943 |
- configMap: |
| 944 |
name: configmap-in-base |
| 945 |
name: configmap-in-base |
| 946 |
--- |
| 947 |
apiVersion: apps/v1 |
| 948 |
kind: Deployment |
| 949 |
metadata: |
| 950 |
annotations: |
| 951 |
new-key: new-value |
| 952 |
labels: |
| 953 |
app: busybox |
| 954 |
name: busybox |
| 955 |
spec: |
| 956 |
template: |
| 957 |
metadata: |
| 958 |
labels: |
| 959 |
app: busybox |
| 960 |
spec: |
| 961 |
containers: |
| 962 |
- image: busybox |
| 963 |
name: busybox |
| 964 |
volumeMounts: |
| 965 |
- mountPath: /tmp/ps |
| 966 |
name: busybox-persistent-storage |
| 967 |
volumes: |
| 968 |
- emptyDir: {} |
| 969 |
name: busybox-persistent-storage |
| 970 |
- configMap: |
| 971 |
name: configmap-in-base |
| 972 |
name: configmap-in-base |
| 973 |
--- |
| 974 |
apiVersion: v1 |
| 975 |
kind: Service |
| 976 |
metadata: |
| 977 |
labels: |
| 978 |
app: nginx |
| 979 |
name: nginx |
| 980 |
spec: |
| 981 |
ports: |
| 982 |
- port: 80 |
| 983 |
selector: |
| 984 |
app: nginx |
| 985 |
--- |
| 986 |
apiVersion: v1 |
| 987 |
kind: Service |
| 988 |
metadata: |
| 989 |
labels: |
| 990 |
app: busybox |
| 991 |
name: busybox |
| 992 |
spec: |
| 993 |
ports: |
| 994 |
- port: 8080 |
| 995 |
selector: |
| 996 |
app: busybox |
| 997 |
`) |
| 998 |
} |
| 999 |
|
| 1000 |
func TestExtendedPatchNoMatchMultiplePatch(t *testing.T) { |
| 1001 |
th := kusttest_test.MakeHarness(t) |
| 1002 |
makeCommonFileForExtendedPatchTest(th) |
| 1003 |
th.WriteK("base", ` |
| 1004 |
resources: |
| 1005 |
- deployment.yaml |
| 1006 |
- service.yaml |
| 1007 |
patches: |
| 1008 |
- path: patch.yaml |
| 1009 |
target: |
| 1010 |
name: no-match |
| 1011 |
- path: patch.yaml |
| 1012 |
target: |
| 1013 |
name: busybox |
| 1014 |
kind: Job |
| 1015 |
`) |
| 1016 |
th.WriteF("base/patch.yaml", ` |
| 1017 |
apiVersion: apps/v1 |
| 1018 |
kind: Deployment |
| 1019 |
metadata: |
| 1020 |
name: busybox |
| 1021 |
annotations: |
| 1022 |
new-key: new-value |
| 1023 |
`) |
| 1024 |
m := th.Run("base", th.MakeDefaultOptions()) |
| 1025 |
th.AssertActualEqualsExpected(m, ` |
| 1026 |
apiVersion: apps/v1 |
| 1027 |
kind: Deployment |
| 1028 |
metadata: |
| 1029 |
labels: |
| 1030 |
app: nginx |
| 1031 |
name: nginx |
| 1032 |
spec: |
| 1033 |
template: |
| 1034 |
metadata: |
| 1035 |
labels: |
| 1036 |
app: nginx |
| 1037 |
spec: |
| 1038 |
containers: |
| 1039 |
- image: nginx |
| 1040 |
name: nginx |
| 1041 |
volumeMounts: |
| 1042 |
- mountPath: /tmp/ps |
| 1043 |
name: nginx-persistent-storage |
| 1044 |
volumes: |
| 1045 |
- emptyDir: {} |
| 1046 |
name: nginx-persistent-storage |
| 1047 |
- configMap: |
| 1048 |
name: configmap-in-base |
| 1049 |
name: configmap-in-base |
| 1050 |
--- |
| 1051 |
apiVersion: apps/v1 |
| 1052 |
kind: Deployment |
| 1053 |
metadata: |
| 1054 |
labels: |
| 1055 |
app: busybox |
| 1056 |
name: busybox |
| 1057 |
spec: |
| 1058 |
template: |
| 1059 |
metadata: |
| 1060 |
labels: |
| 1061 |
app: busybox |
| 1062 |
spec: |
| 1063 |
containers: |
| 1064 |
- image: busybox |
| 1065 |
name: busybox |
| 1066 |
volumeMounts: |
| 1067 |
- mountPath: /tmp/ps |
| 1068 |
name: busybox-persistent-storage |
| 1069 |
volumes: |
| 1070 |
- emptyDir: {} |
| 1071 |
name: busybox-persistent-storage |
| 1072 |
- configMap: |
| 1073 |
name: configmap-in-base |
| 1074 |
name: configmap-in-base |
| 1075 |
--- |
| 1076 |
apiVersion: v1 |
| 1077 |
kind: Service |
| 1078 |
metadata: |
| 1079 |
labels: |
| 1080 |
app: nginx |
| 1081 |
name: nginx |
| 1082 |
spec: |
| 1083 |
ports: |
| 1084 |
- port: 80 |
| 1085 |
selector: |
| 1086 |
app: nginx |
| 1087 |
--- |
| 1088 |
apiVersion: v1 |
| 1089 |
kind: Service |
| 1090 |
metadata: |
| 1091 |
labels: |
| 1092 |
app: busybox |
| 1093 |
name: busybox |
| 1094 |
spec: |
| 1095 |
ports: |
| 1096 |
- port: 8080 |
| 1097 |
selector: |
| 1098 |
app: busybox |
| 1099 |
`) |
| 1100 |
} |
| 1101 |
|
| 1102 |
func TestExtendedPatchMultiplePatchOverlapping(t *testing.T) { |
| 1103 |
th := kusttest_test.MakeHarness(t) |
| 1104 |
makeCommonFileForExtendedPatchTest(th) |
| 1105 |
th.WriteK("base", ` |
| 1106 |
resources: |
| 1107 |
- deployment.yaml |
| 1108 |
- service.yaml |
| 1109 |
patches: |
| 1110 |
- path: patch1.yaml |
| 1111 |
target: |
| 1112 |
labelSelector: app=busybox |
| 1113 |
- path: patch2.yaml |
| 1114 |
target: |
| 1115 |
name: busybox |
| 1116 |
kind: Deployment |
| 1117 |
`) |
| 1118 |
th.WriteF("base/patch1.yaml", ` |
| 1119 |
apiVersion: apps/v1 |
| 1120 |
kind: Deployment |
| 1121 |
metadata: |
| 1122 |
name: busybox |
| 1123 |
annotations: |
| 1124 |
new-key-from-patch1: new-value |
| 1125 |
`) |
| 1126 |
th.WriteF("base/patch2.yaml", ` |
| 1127 |
apiVersion: apps/v1 |
| 1128 |
kind: Deployment |
| 1129 |
metadata: |
| 1130 |
name: busybox |
| 1131 |
annotations: |
| 1132 |
new-key-from-patch2: new-value |
| 1133 |
`) |
| 1134 |
m := th.Run("base", th.MakeDefaultOptions()) |
| 1135 |
th.AssertActualEqualsExpected(m, ` |
| 1136 |
apiVersion: apps/v1 |
| 1137 |
kind: Deployment |
| 1138 |
metadata: |
| 1139 |
labels: |
| 1140 |
app: nginx |
| 1141 |
name: nginx |
| 1142 |
spec: |
| 1143 |
template: |
| 1144 |
metadata: |
| 1145 |
labels: |
| 1146 |
app: nginx |
| 1147 |
spec: |
| 1148 |
containers: |
| 1149 |
- image: nginx |
| 1150 |
name: nginx |
| 1151 |
volumeMounts: |
| 1152 |
- mountPath: /tmp/ps |
| 1153 |
name: nginx-persistent-storage |
| 1154 |
volumes: |
| 1155 |
- emptyDir: {} |
| 1156 |
name: nginx-persistent-storage |
| 1157 |
- configMap: |
| 1158 |
name: configmap-in-base |
| 1159 |
name: configmap-in-base |
| 1160 |
--- |
| 1161 |
apiVersion: apps/v1 |
| 1162 |
kind: Deployment |
| 1163 |
metadata: |
| 1164 |
annotations: |
| 1165 |
new-key-from-patch1: new-value |
| 1166 |
new-key-from-patch2: new-value |
| 1167 |
labels: |
| 1168 |
app: busybox |
| 1169 |
name: busybox |
| 1170 |
spec: |
| 1171 |
template: |
| 1172 |
metadata: |
| 1173 |
labels: |
| 1174 |
app: busybox |
| 1175 |
spec: |
| 1176 |
containers: |
| 1177 |
- image: busybox |
| 1178 |
name: busybox |
| 1179 |
volumeMounts: |
| 1180 |
- mountPath: /tmp/ps |
| 1181 |
name: busybox-persistent-storage |
| 1182 |
volumes: |
| 1183 |
- emptyDir: {} |
| 1184 |
name: busybox-persistent-storage |
| 1185 |
- configMap: |
| 1186 |
name: configmap-in-base |
| 1187 |
name: configmap-in-base |
| 1188 |
--- |
| 1189 |
apiVersion: v1 |
| 1190 |
kind: Service |
| 1191 |
metadata: |
| 1192 |
labels: |
| 1193 |
app: nginx |
| 1194 |
name: nginx |
| 1195 |
spec: |
| 1196 |
ports: |
| 1197 |
- port: 80 |
| 1198 |
selector: |
| 1199 |
app: nginx |
| 1200 |
--- |
| 1201 |
apiVersion: v1 |
| 1202 |
kind: Service |
| 1203 |
metadata: |
| 1204 |
annotations: |
| 1205 |
new-key-from-patch1: new-value |
| 1206 |
labels: |
| 1207 |
app: busybox |
| 1208 |
name: busybox |
| 1209 |
spec: |
| 1210 |
ports: |
| 1211 |
- port: 8080 |
| 1212 |
selector: |
| 1213 |
app: busybox |
| 1214 |
`) |
| 1215 |
} |