|
1 | 1 | package bootstrap
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "fmt" |
4 | 5 | "testing"
|
5 | 6 |
|
6 | 7 | tassert "github.com/stretchr/testify/assert"
|
@@ -29,7 +30,7 @@ func TestBuild(t *testing.T) {
|
29 | 30 | },
|
30 | 31 | "my-container-2": {
|
31 | 32 | Liveness: &models.HealthProbe{Path: "/liveness", Port: 84, IsHTTP: true},
|
32 |
| - Readiness: &models.HealthProbe{Path: "/readiness", Port: 85}, // HTTPS (should overwrite my-containers probe) |
| 33 | + Readiness: &models.HealthProbe{Path: "/readiness", Port: 85}, // HTTPS |
33 | 34 | Startup: &models.HealthProbe{Path: "/startup", Port: 86, IsHTTP: true},
|
34 | 35 | },
|
35 | 36 | },
|
@@ -382,5 +383,352 @@ static_resources:
|
382 | 383 | '@type': type.googleapis.com/envoy.extensions.filters.listener.tls_inspector.v3.TlsInspector
|
383 | 384 | name: startup_listener
|
384 | 385 | `
|
385 |
| - assert.Equal(expectedYAML, string(actualYAML)) |
| 386 | + |
| 387 | + reversedExpectedYAML := `admin: |
| 388 | + access_log: |
| 389 | + - name: envoy.access_loggers.stream |
| 390 | + typed_config: |
| 391 | + '@type': type.googleapis.com/envoy.extensions.access_loggers.stream.v3.StdoutAccessLog |
| 392 | + address: |
| 393 | + socket_address: |
| 394 | + address: 127.0.0.1 |
| 395 | + port_value: 15000 |
| 396 | +dynamic_resources: |
| 397 | + ads_config: |
| 398 | + api_type: GRPC |
| 399 | + grpc_services: |
| 400 | + - envoy_grpc: |
| 401 | + cluster_name: osm-controller |
| 402 | + set_node_on_first_message_only: true |
| 403 | + transport_api_version: V3 |
| 404 | + cds_config: |
| 405 | + ads: {} |
| 406 | + resource_api_version: V3 |
| 407 | + lds_config: |
| 408 | + ads: {} |
| 409 | + resource_api_version: V3 |
| 410 | +node: |
| 411 | + id: foo.bar.co.uk |
| 412 | +static_resources: |
| 413 | + clusters: |
| 414 | + - load_assignment: |
| 415 | + cluster_name: osm-controller |
| 416 | + endpoints: |
| 417 | + - lb_endpoints: |
| 418 | + - endpoint: |
| 419 | + address: |
| 420 | + socket_address: |
| 421 | + address: osm-controller.osm-system.svc.cluster.local |
| 422 | + port_value: 15128 |
| 423 | + name: osm-controller |
| 424 | + transport_socket: |
| 425 | + name: envoy.transport_sockets.tls |
| 426 | + typed_config: |
| 427 | + '@type': type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext |
| 428 | + common_tls_context: |
| 429 | + alpn_protocols: |
| 430 | + - h2 |
| 431 | + tls_certificate_sds_secret_configs: |
| 432 | + - name: tls_sds |
| 433 | + sds_config: |
| 434 | + path: /etc/envoy/tls_certificate_sds_secret.yaml |
| 435 | + tls_params: |
| 436 | + cipher_suites: |
| 437 | + - abc |
| 438 | + - xyz |
| 439 | + ecdh_curves: |
| 440 | + - ABC |
| 441 | + - XYZ |
| 442 | + tls_maximum_protocol_version: TLSv1_2 |
| 443 | + tls_minimum_protocol_version: TLSv1_0 |
| 444 | + validation_context_sds_secret_config: |
| 445 | + name: validation_context_sds |
| 446 | + sds_config: |
| 447 | + path: /etc/envoy/validation_context_sds_secret.yaml |
| 448 | + type: LOGICAL_DNS |
| 449 | + typed_extension_protocol_options: |
| 450 | + envoy.extensions.upstreams.http.v3.HttpProtocolOptions: |
| 451 | + '@type': type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions |
| 452 | + explicit_http_config: |
| 453 | + http2_protocol_options: {} |
| 454 | + - load_assignment: |
| 455 | + cluster_name: my-container-2_liveness_cluster |
| 456 | + endpoints: |
| 457 | + - lb_endpoints: |
| 458 | + - endpoint: |
| 459 | + address: |
| 460 | + socket_address: |
| 461 | + address: 127.0.0.1 |
| 462 | + port_value: 84 |
| 463 | + name: my-container-2_liveness_cluster |
| 464 | + type: STATIC |
| 465 | + - load_assignment: |
| 466 | + cluster_name: my-container-2_readiness_cluster |
| 467 | + endpoints: |
| 468 | + - lb_endpoints: |
| 469 | + - endpoint: |
| 470 | + address: |
| 471 | + socket_address: |
| 472 | + address: 127.0.0.1 |
| 473 | + port_value: 85 |
| 474 | + name: my-container-2_readiness_cluster |
| 475 | + type: STATIC |
| 476 | + - load_assignment: |
| 477 | + cluster_name: my-container-2_startup_cluster |
| 478 | + endpoints: |
| 479 | + - lb_endpoints: |
| 480 | + - endpoint: |
| 481 | + address: |
| 482 | + socket_address: |
| 483 | + address: 127.0.0.1 |
| 484 | + port_value: 86 |
| 485 | + name: my-container-2_startup_cluster |
| 486 | + type: STATIC |
| 487 | + - load_assignment: |
| 488 | + cluster_name: my-container_liveness_cluster |
| 489 | + endpoints: |
| 490 | + - lb_endpoints: |
| 491 | + - endpoint: |
| 492 | + address: |
| 493 | + socket_address: |
| 494 | + address: 127.0.0.1 |
| 495 | + port_value: 81 |
| 496 | + name: my-container_liveness_cluster |
| 497 | + type: STATIC |
| 498 | + - load_assignment: |
| 499 | + cluster_name: my-container_readiness_cluster |
| 500 | + endpoints: |
| 501 | + - lb_endpoints: |
| 502 | + - endpoint: |
| 503 | + address: |
| 504 | + socket_address: |
| 505 | + address: 127.0.0.1 |
| 506 | + port_value: 82 |
| 507 | + name: my-container_readiness_cluster |
| 508 | + type: STATIC |
| 509 | + - load_assignment: |
| 510 | + cluster_name: my-container_startup_cluster |
| 511 | + endpoints: |
| 512 | + - lb_endpoints: |
| 513 | + - endpoint: |
| 514 | + address: |
| 515 | + socket_address: |
| 516 | + address: 127.0.0.1 |
| 517 | + port_value: 83 |
| 518 | + name: my-container_startup_cluster |
| 519 | + type: STATIC |
| 520 | + listeners: |
| 521 | + - address: |
| 522 | + socket_address: |
| 523 | + address: 0.0.0.0 |
| 524 | + port_value: 15901 |
| 525 | + filter_chains: |
| 526 | + - filters: |
| 527 | + - name: envoy.filters.network.http_connection_manager |
| 528 | + typed_config: |
| 529 | + '@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager |
| 530 | + access_log: |
| 531 | + - name: envoy.access_loggers.stream |
| 532 | + typed_config: |
| 533 | + '@type': type.googleapis.com/envoy.extensions.access_loggers.stream.v3.StdoutAccessLog |
| 534 | + log_format: |
| 535 | + json_format: |
| 536 | + authority: '%REQ(:AUTHORITY)%' |
| 537 | + bytes_received: '%BYTES_RECEIVED%' |
| 538 | + bytes_sent: '%BYTES_SENT%' |
| 539 | + duration: '%DURATION%' |
| 540 | + method: '%REQ(:METHOD)%' |
| 541 | + path: '%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%' |
| 542 | + protocol: '%PROTOCOL%' |
| 543 | + request_id: '%REQ(X-REQUEST-ID)%' |
| 544 | + requested_server_name: '%REQUESTED_SERVER_NAME%' |
| 545 | + response_code: '%RESPONSE_CODE%' |
| 546 | + response_code_details: '%RESPONSE_CODE_DETAILS%' |
| 547 | + response_flags: '%RESPONSE_FLAGS%' |
| 548 | + start_time: '%START_TIME%' |
| 549 | + time_to_first_byte: '%RESPONSE_DURATION%' |
| 550 | + upstream_cluster: '%UPSTREAM_CLUSTER%' |
| 551 | + upstream_host: '%UPSTREAM_HOST%' |
| 552 | + upstream_service_time: '%RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)%' |
| 553 | + user_agent: '%REQ(USER-AGENT)%' |
| 554 | + x_forwarded_for: '%REQ(X-FORWARDED-FOR)%' |
| 555 | + http_filters: |
| 556 | + - name: http_router |
| 557 | + typed_config: |
| 558 | + '@type': type.googleapis.com/envoy.extensions.filters.http.router.v3.Router |
| 559 | + route_config: |
| 560 | + name: local_route |
| 561 | + virtual_hosts: |
| 562 | + - domains: |
| 563 | + - '*' |
| 564 | + name: local_service |
| 565 | + routes: |
| 566 | + - match: |
| 567 | + prefix: /osm-liveness-probe/my-container-2 |
| 568 | + route: |
| 569 | + cluster: my-container-2_liveness_cluster |
| 570 | + prefix_rewrite: /liveness |
| 571 | + timeout: 1s |
| 572 | + - match: |
| 573 | + prefix: /osm-liveness-probe/my-container |
| 574 | + route: |
| 575 | + cluster: my-container_liveness_cluster |
| 576 | + prefix_rewrite: /liveness |
| 577 | + timeout: 1s |
| 578 | + stat_prefix: health_probes_http |
| 579 | + listener_filters: |
| 580 | + - name: tls_inspector |
| 581 | + typed_config: |
| 582 | + '@type': type.googleapis.com/envoy.extensions.filters.listener.tls_inspector.v3.TlsInspector |
| 583 | + name: liveness_listener |
| 584 | + - address: |
| 585 | + socket_address: |
| 586 | + address: 0.0.0.0 |
| 587 | + port_value: 15902 |
| 588 | + filter_chains: |
| 589 | + - filter_chain_match: |
| 590 | + transport_protocol: tls |
| 591 | + filters: |
| 592 | + - name: tcp_proxy |
| 593 | + typed_config: |
| 594 | + '@type': type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy |
| 595 | + access_log: |
| 596 | + - name: envoy.access_loggers.stream |
| 597 | + typed_config: |
| 598 | + '@type': type.googleapis.com/envoy.extensions.access_loggers.stream.v3.StdoutAccessLog |
| 599 | + log_format: |
| 600 | + json_format: |
| 601 | + bytes_received: '%BYTES_RECEIVED%' |
| 602 | + bytes_sent: '%BYTES_SENT%' |
| 603 | + duration: '%DURATION%' |
| 604 | + requested_server_name: '%REQUESTED_SERVER_NAME%' |
| 605 | + response_flags: '%RESPONSE_FLAGS%' |
| 606 | + start_time: '%START_TIME%' |
| 607 | + upstream_cluster: '%UPSTREAM_CLUSTER%' |
| 608 | + upstream_host: '%UPSTREAM_HOST%' |
| 609 | + cluster: my-container-2_readiness_cluster |
| 610 | + stat_prefix: health_probes_https |
| 611 | + - filters: |
| 612 | + - name: envoy.filters.network.http_connection_manager |
| 613 | + typed_config: |
| 614 | + '@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager |
| 615 | + access_log: |
| 616 | + - name: envoy.access_loggers.stream |
| 617 | + typed_config: |
| 618 | + '@type': type.googleapis.com/envoy.extensions.access_loggers.stream.v3.StdoutAccessLog |
| 619 | + log_format: |
| 620 | + json_format: |
| 621 | + authority: '%REQ(:AUTHORITY)%' |
| 622 | + bytes_received: '%BYTES_RECEIVED%' |
| 623 | + bytes_sent: '%BYTES_SENT%' |
| 624 | + duration: '%DURATION%' |
| 625 | + method: '%REQ(:METHOD)%' |
| 626 | + path: '%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%' |
| 627 | + protocol: '%PROTOCOL%' |
| 628 | + request_id: '%REQ(X-REQUEST-ID)%' |
| 629 | + requested_server_name: '%REQUESTED_SERVER_NAME%' |
| 630 | + response_code: '%RESPONSE_CODE%' |
| 631 | + response_code_details: '%RESPONSE_CODE_DETAILS%' |
| 632 | + response_flags: '%RESPONSE_FLAGS%' |
| 633 | + start_time: '%START_TIME%' |
| 634 | + time_to_first_byte: '%RESPONSE_DURATION%' |
| 635 | + upstream_cluster: '%UPSTREAM_CLUSTER%' |
| 636 | + upstream_host: '%UPSTREAM_HOST%' |
| 637 | + upstream_service_time: '%RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)%' |
| 638 | + user_agent: '%REQ(USER-AGENT)%' |
| 639 | + x_forwarded_for: '%REQ(X-FORWARDED-FOR)%' |
| 640 | + http_filters: |
| 641 | + - name: http_router |
| 642 | + typed_config: |
| 643 | + '@type': type.googleapis.com/envoy.extensions.filters.http.router.v3.Router |
| 644 | + route_config: |
| 645 | + name: local_route |
| 646 | + virtual_hosts: |
| 647 | + - domains: |
| 648 | + - '*' |
| 649 | + name: local_service |
| 650 | + routes: |
| 651 | + - match: |
| 652 | + prefix: /osm-readiness-probe/my-container |
| 653 | + route: |
| 654 | + cluster: my-container_readiness_cluster |
| 655 | + prefix_rewrite: /readiness |
| 656 | + timeout: 1s |
| 657 | + stat_prefix: health_probes_http |
| 658 | + listener_filters: |
| 659 | + - name: tls_inspector |
| 660 | + typed_config: |
| 661 | + '@type': type.googleapis.com/envoy.extensions.filters.listener.tls_inspector.v3.TlsInspector |
| 662 | + name: readiness_listener |
| 663 | + - address: |
| 664 | + socket_address: |
| 665 | + address: 0.0.0.0 |
| 666 | + port_value: 15903 |
| 667 | + filter_chains: |
| 668 | + - filters: |
| 669 | + - name: envoy.filters.network.http_connection_manager |
| 670 | + typed_config: |
| 671 | + '@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager |
| 672 | + access_log: |
| 673 | + - name: envoy.access_loggers.stream |
| 674 | + typed_config: |
| 675 | + '@type': type.googleapis.com/envoy.extensions.access_loggers.stream.v3.StdoutAccessLog |
| 676 | + log_format: |
| 677 | + json_format: |
| 678 | + authority: '%REQ(:AUTHORITY)%' |
| 679 | + bytes_received: '%BYTES_RECEIVED%' |
| 680 | + bytes_sent: '%BYTES_SENT%' |
| 681 | + duration: '%DURATION%' |
| 682 | + method: '%REQ(:METHOD)%' |
| 683 | + path: '%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%' |
| 684 | + protocol: '%PROTOCOL%' |
| 685 | + request_id: '%REQ(X-REQUEST-ID)%' |
| 686 | + requested_server_name: '%REQUESTED_SERVER_NAME%' |
| 687 | + response_code: '%RESPONSE_CODE%' |
| 688 | + response_code_details: '%RESPONSE_CODE_DETAILS%' |
| 689 | + response_flags: '%RESPONSE_FLAGS%' |
| 690 | + start_time: '%START_TIME%' |
| 691 | + time_to_first_byte: '%RESPONSE_DURATION%' |
| 692 | + upstream_cluster: '%UPSTREAM_CLUSTER%' |
| 693 | + upstream_host: '%UPSTREAM_HOST%' |
| 694 | + upstream_service_time: '%RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)%' |
| 695 | + user_agent: '%REQ(USER-AGENT)%' |
| 696 | + x_forwarded_for: '%REQ(X-FORWARDED-FOR)%' |
| 697 | + http_filters: |
| 698 | + - name: http_router |
| 699 | + typed_config: |
| 700 | + '@type': type.googleapis.com/envoy.extensions.filters.http.router.v3.Router |
| 701 | + route_config: |
| 702 | + name: local_route |
| 703 | + virtual_hosts: |
| 704 | + - domains: |
| 705 | + - '*' |
| 706 | + name: local_service |
| 707 | + routes: |
| 708 | + - match: |
| 709 | + prefix: /osm-startup-probe/my-container-2 |
| 710 | + route: |
| 711 | + cluster: my-container-2_startup_cluster |
| 712 | + prefix_rewrite: /startup |
| 713 | + timeout: 1s |
| 714 | + - match: |
| 715 | + prefix: /osm-startup-probe/my-container |
| 716 | + route: |
| 717 | + cluster: my-container_startup_cluster |
| 718 | + prefix_rewrite: /startup |
| 719 | + timeout: 1s |
| 720 | + stat_prefix: health_probes_http |
| 721 | + listener_filters: |
| 722 | + - name: tls_inspector |
| 723 | + typed_config: |
| 724 | + '@type': type.googleapis.com/envoy.extensions.filters.listener.tls_inspector.v3.TlsInspector |
| 725 | + name: startup_listener |
| 726 | +` |
| 727 | + |
| 728 | + // Because OriginalHealthProbes is a map and not a slice, it's unordered, so we need to use a more complex assertion here |
| 729 | + assert.Conditionf(func() (success bool) { |
| 730 | + return tassert.ObjectsAreEqual(expectedYAML, string(actualYAML)) || tassert.ObjectsAreEqual(reversedExpectedYAML, string(actualYAML)) |
| 731 | + }, fmt.Sprintf("Not equal: \n"+ |
| 732 | + "expected:\n%s\n--------OR----------\n%s\n"+ |
| 733 | + "actual :\n%s\n", expectedYAML, reversedExpectedYAML, actualYAML)) |
386 | 734 | }
|
0 commit comments