diff --git a/api/XDS_PROTOCOL.md b/api/XDS_PROTOCOL.md index 062a5fce96ea0..860d21956bd02 100644 --- a/api/XDS_PROTOCOL.md +++ b/api/XDS_PROTOCOL.md @@ -275,10 +275,15 @@ static_resources: - name: ads_cluster connect_timeout: { seconds: 5 } type: STATIC - hosts: - - socket_address: - address: - port_value: + load_assignment: + cluster_name: ads_cluster + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: + port_value: lb_policy: ROUND_ROBIN http2_protocol_options: {} admin: diff --git a/api/envoy/api/v2/cds.proto b/api/envoy/api/v2/cds.proto index f3c4118145dd2..3023dcbe527de 100644 --- a/api/envoy/api/v2/cds.proto +++ b/api/envoy/api/v2/cds.proto @@ -156,34 +156,20 @@ message Cluster { // when picking a host in the cluster. LbPolicy lb_policy = 6 [(validate.rules).enum.defined_only = true]; - // If the service discovery type is - // :ref:`STATIC`, - // :ref:`STRICT_DNS` - // or :ref:`LOGICAL_DNS`, - // then hosts is required. - // - // .. attention:: - // - // **This field is deprecated**. Set the - // :ref:`load_assignment` field instead. - // - repeated core.Address hosts = 7 [deprecated = true]; + reserved 7; // hosts is deprecated by :ref:`load_assignment + // ` // Setting this is required for specifying members of // :ref:`STATIC`, // :ref:`STRICT_DNS` // or :ref:`LOGICAL_DNS` clusters. - // This field supersedes :ref:`hosts` field. - // [#comment:TODO(dio): Deprecate the hosts field and add it to DEPRECATED.md - // once load_assignment is implemented.] // - // .. attention:: + // .. note:: // // Setting this allows non-EDS cluster types to contain embedded EDS equivalent // :ref:`endpoint assignments`. - // Setting this overrides :ref:`hosts` values. // - ClusterLoadAssignment load_assignment = 33; + ClusterLoadAssignment load_assignment = 33 [(gogoproto.nullable) = false]; // Optional :ref:`active health checking ` // configuration for the cluster. If no diff --git a/ci/build_setup.sh b/ci/build_setup.sh index f13905ca9139e..78fe55a4dfa4e 100755 --- a/ci/build_setup.sh +++ b/ci/build_setup.sh @@ -86,9 +86,9 @@ if [ "$1" != "-nofetch" ]; then then git clone https://github.com/envoyproxy/envoy-filter-example.git "${ENVOY_FILTER_EXAMPLE_SRCDIR}" fi - + # This is the hash on https://github.com/envoyproxy/envoy-filter-example.git we pin to. - (cd "${ENVOY_FILTER_EXAMPLE_SRCDIR}" && git fetch origin && git checkout -f 3e5b73305b961526ffcee7584251692a9a3ce4b3) + (cd "${ENVOY_FILTER_EXAMPLE_SRCDIR}" && git fetch origin && git checkout -f 15f8608a515ed92ce2497f2449d4f2f86b2bea5d) cp -f "${ENVOY_SRCDIR}"/ci/WORKSPACE.filter.example "${ENVOY_FILTER_EXAMPLE_SRCDIR}"/WORKSPACE fi diff --git a/configs/envoy_double_proxy_v2.template.yaml b/configs/envoy_double_proxy_v2.template.yaml index 38b6e4bb160be..8db6fdc91e787 100644 --- a/configs/envoy_double_proxy_v2.template.yaml +++ b/configs/envoy_double_proxy_v2.template.yaml @@ -92,20 +92,30 @@ static_resources: type: STATIC connect_timeout: 0.25s lb_policy: ROUND_ROBIN - hosts: - - socket_address: - protocol: TCP - address: 127.0.0.1 - port_value: 8125 + load_assignment: + cluster_name: statsd + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + protocol: TCP + address: 127.0.0.1 + port_value: 8125 - name: backhaul type: STRICT_DNS connect_timeout: 1s lb_policy: ROUND_ROBIN - hosts: - - socket_address: - protocol: TCP - address: front-proxy.yourcompany.net - port_value: 9400 + load_assignment: + cluster_name: backhaul + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + protocol: TCP + address: front-proxy.yourcompany.net + port_value: 9400 # There are so few connections going back # that we can get some imbalance. Until we come up # with a better solution just limit the requests @@ -128,11 +138,16 @@ static_resources: type: LOGICAL_DNS connect_timeout: 1s lb_policy: ROUND_ROBIN - hosts: - - socket_address: - protocol: TCP - address: collector-grpc.lightstep.com - port_value: 443 + load_assignment: + cluster_name: lightstep_saas + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + protocol: TCP + address: collector-grpc.lightstep.com + port_value: 443 http2_protocol_options: {} tls_context: common_tls_context: @@ -144,7 +159,7 @@ static_resources: flags_path: "/etc/envoy/flags" stats_sinks: - name: envoy.statsd - config: + config: tcp_cluster_name: statsd tracing: http: diff --git a/configs/envoy_front_proxy_v2.template.yaml b/configs/envoy_front_proxy_v2.template.yaml index f72aa94e3084d..be459a44d3b34 100644 --- a/configs/envoy_front_proxy_v2.template.yaml +++ b/configs/envoy_front_proxy_v2.template.yaml @@ -97,29 +97,44 @@ static_resources: type: STRICT_DNS connect_timeout: 0.25s lb_policy: ROUND_ROBIN - hosts: - - socket_address: - protocol: TCP - address: disccovery.yourcompany.net - port_value: 80 + load_assignment: + cluster_name: sds + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + protocol: TCP + address: discovery.yourcompany.net + port_value: 80 - name: statsd type: STATIC connect_timeout: 0.25s lb_policy: ROUND_ROBIN - hosts: - - socket_address: - protocol: TCP - address: 127.0.0.1 - port_value: 8125 + load_assignment: + cluster_name: statsd + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + protocol: TCP + address: 127.0.0.1 + port_value: 8125 - name: lightstep_saas type: LOGICAL_DNS connect_timeout: 1s lb_policy: ROUND_ROBIN - hosts: - - socket_address: - protocol: TCP - address: collector-grpc.lightstep.com - port_value: 443 + load_assignment: + cluster_name: lightstep_saas + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + protocol: TCP + address: collector-grpc.lightstep.com + port_value: 443 http2_protocol_options: {} {% for service, options in clusters.iteritems() -%} - {{ helper.internal_cluster_definition(service, options)|indent(2) }} diff --git a/configs/envoy_service_to_service_v2.template.yaml b/configs/envoy_service_to_service_v2.template.yaml index e6939aa681875..216c09fa0ea53 100644 --- a/configs/envoy_service_to_service_v2.template.yaml +++ b/configs/envoy_service_to_service_v2.template.yaml @@ -335,11 +335,16 @@ static_resources: {% endif %} type: LOGICAL_DNS lb_policy: ROUND_ROBIN - hosts: - - socket_address: - address: {{ host['remote_address'] }} - port_value: {{ host['port_value'] }} - protocol: {{ host['protocol'] }} + load_assignment: + cluster_name: egress_{{ host['name'] }} + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: {{ host['remote_address'] }} + port_value: {{ host['port_value'] }} + protocol: {{ host['protocol'] }} {% endfor -%} {% endfor -%} {% for key, value in mongos_servers.iteritems() -%} @@ -347,13 +352,18 @@ static_resources: connect_timeout: 0.25s type: STRICT_DNS lb_policy: RANDOM - hosts: - {% for server in value['hosts'] -%} - - socket_address: - protocol: {{ server['protocol'] }} - port_value: {{ server['port_value'] }} - address: {{ server['address'] }} - {% endfor -%} + load_assignment: + cluster_name: mongo_{{ key }} + endpoints: + - lb_endpoints: + {% for server in value['hosts'] -%} + - endpoint: + address: + socket_address: + protocol: {{ server['protocol'] }} + port_value: {{ server['port_value'] }} + address: {{ server['address'] }} + {% endfor -%} {% endfor %} - name: main_website connect_timeout: 0.25s @@ -361,20 +371,30 @@ static_resources: # Comment out the following line to test on v6 networks dns_lookup_family: V4_ONLY lb_policy: ROUND_ROBIN - hosts: - - socket_address: - address: main_website.com - port_value: 443 + load_assignment: + cluster_name: main_website + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: main_website.com + port_value: 443 tls_context: { sni: www.main_website.com } - name: local_service connect_timeout: 0.25s type: STATIC lb_policy: ROUND_ROBIN - hosts: - - socket_address: - protocol: TCP - address: 127.0.0.1 - port_value: 8080 + load_assignment: + cluster_name: local_service + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + protocol: TCP + address: 127.0.0.1 + port_value: 8080 circuit_breakers: thresholds: max_pending_requests: 30 @@ -384,11 +404,16 @@ static_resources: type: STATIC lb_policy: ROUND_ROBIN http2_protocol_options: {} - hosts: - - socket_address: - protocol: TCP - address: 127.0.0.1 - port_value: 8081 + load_assignment: + cluster_name: local_service_grpc + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + protocol: TCP + address: 127.0.0.1 + port_value: 8081 circuit_breakers: thresholds: max_requests: 200 @@ -397,31 +422,46 @@ static_resources: connect_timeout: 0.25s type: STRICT_DNS lb_policy: ROUND_ROBIN - hosts: - - socket_address: - protocol: TCP - address: rds.yourcompany.net - port_value: 80 + load_assignment: + cluster_name: rds + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + protocol: TCP + address: rds.yourcompany.net + port_value: 80 dns_lookup_family: V4_ONLY - name: statsd connect_timeout: 0.25s type: STATIC lb_policy: ROUND_ROBIN - hosts: - - socket_address: - protocol: TCP - address: 127.0.0.1 - port_value: 8125 + load_assignment: + cluster_name: statsd + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + protocol: TCP + address: 127.0.0.1 + port_value: 8125 dns_lookup_family: V4_ONLY - name: lightstep_saas connect_timeout: 1s type: LOGICAL_DNS lb_policy: ROUND_ROBIN - hosts: - - socket_address: - protocol: TCP - address: collector-grpc.lightstep.com - port_value: 443 + load_assignment: + cluster_name: statsd + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + protocol: TCP + address: collector-grpc.lightstep.com + port_value: 443 http2_protocol_options: max_concurrent_streams: 100 tls_context: @@ -435,20 +475,30 @@ static_resources: connect_timeout: 0.25s type: STRICT_DNS lb_policy: ROUND_ROBIN - hosts: - - socket_address: - protocol: TCP - address: cds.yourcompany.net - port_value: 80 + load_assignment: + cluster_name: cds_cluster + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + protocol: TCP + address: cds.yourcompany.net + port_value: 80 - name: sds connect_timeout: 0.25s type: STRICT_DNS lb_policy: ROUND_ROBIN - hosts: - - socket_address: - protocol: TCP - address: discovery.yourcompany.net - port_value: 80 + load_assignment: + cluster_name: sds + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + protocol: TCP + address: discovery.yourcompany.net + port_value: 80 dynamic_resources: cds_config: api_config_source: diff --git a/configs/freebind/freebind.yaml b/configs/freebind/freebind.yaml index 9b494bd05742f..42d15e420a46f 100644 --- a/configs/freebind/freebind.yaml +++ b/configs/freebind/freebind.yaml @@ -29,10 +29,15 @@ static_resources: connect_timeout: 30s type: STATIC lb_policy: ROUND_ROBIN - hosts: - - socket_address: - address: 127.0.0.1 - port_value: 10001 + load_assignment: + cluster_name: service_local + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 10001 # TODO(htuch): Figure out how to do end-to-end testing with # outgoing connections and free bind. # upstream_bind_config: diff --git a/configs/google_com_proxy.v2.yaml b/configs/google_com_proxy.v2.yaml index b97092748b9ec..53d0df398e901 100644 --- a/configs/google_com_proxy.v2.yaml +++ b/configs/google_com_proxy.v2.yaml @@ -38,8 +38,13 @@ static_resources: # Comment out the following line to test on v6 networks dns_lookup_family: V4_ONLY lb_policy: ROUND_ROBIN - hosts: - - socket_address: - address: google.com - port_value: 443 + load_assignment: + cluster_name: service_google + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: google.com + port_value: 443 tls_context: { sni: www.google.com } diff --git a/docs/root/configuration/http_filters/ext_authz_filter.rst b/docs/root/configuration/http_filters/ext_authz_filter.rst index 683b842da6663..95d0622a6975c 100644 --- a/docs/root/configuration/http_filters/ext_authz_filter.rst +++ b/docs/root/configuration/http_filters/ext_authz_filter.rst @@ -43,8 +43,15 @@ A sample filter configuration for a gRPC authorization server: - name: ext-authz type: static http2_protocol_options: {} - hosts: - - socket_address: { address: 127.0.0.1, port_value: 10003 } + load_assignment: + cluster_name: ext-authz + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 10003 # This timeout controls the initial TCP handshake timeout - not the timeout for the # entire request. @@ -71,8 +78,15 @@ A sample filter configuration for a raw HTTP authorization server: connect_timeout: 0.25s type: logical_dns lb_policy: round_robin - hosts: - - socket_address: { address: 127.0.0.1, port_value: 10003 } + load_assignment: + cluster_name: ext-authz + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 10003 Statistics ---------- diff --git a/docs/root/configuration/http_filters/grpc_json_transcoder_filter.rst b/docs/root/configuration/http_filters/grpc_json_transcoder_filter.rst index ccf09a1547981..4ab818fcc645a 100644 --- a/docs/root/configuration/http_filters/grpc_json_transcoder_filter.rst +++ b/docs/root/configuration/http_filters/grpc_json_transcoder_filter.rst @@ -135,7 +135,12 @@ gRPC or RESTful JSON requests to localhost:51051. lb_policy: round_robin dns_lookup_family: V4_ONLY http2_protocol_options: {} - hosts: - - socket_address: - address: docker.for.mac.localhost - port_value: 50051 + load_assignment: + cluster_name: grpc + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: docker.for.mac.localhost + port_value: 50051 diff --git a/docs/root/configuration/http_filters/jwt_authn_filter.rst b/docs/root/configuration/http_filters/jwt_authn_filter.rst index 1e22742e9f7b5..4fe7a73087ccc 100644 --- a/docs/root/configuration/http_filters/jwt_authn_filter.rst +++ b/docs/root/configuration/http_filters/jwt_authn_filter.rst @@ -78,10 +78,15 @@ Following cluster **example_jwks_cluster** is needed to fetch JWKS. cluster: name: example_jwks_cluster type: STRICT_DNS - hosts: - socket_address: - address: example.com - port_value: 80 + load_assignment: + cluster_name: example_jwks_cluster + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: example.com + port_value: 80 Inline JWKS config example diff --git a/docs/root/configuration/network_filters/ext_authz_filter.rst b/docs/root/configuration/network_filters/ext_authz_filter.rst index fc3f3006425d8..89be83c4bd9b1 100644 --- a/docs/root/configuration/network_filters/ext_authz_filter.rst +++ b/docs/root/configuration/network_filters/ext_authz_filter.rst @@ -40,8 +40,15 @@ A sample filter configuration could be: - name: ext-authz type: static http2_protocol_options: {} - hosts: - - socket_address: { address: 127.0.0.1, port_value: 10003 } + load_assignment: + cluster_name: ext-authz + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 10003 Statistics ---------- @@ -54,7 +61,7 @@ The network filter outputs statistics in the *config.ext_authz.* namespace. total, Counter, Total responses from the filter. error, Counter, Total errors contacting the external service. - denied, Counter, Total responses from the authorizations service that were to deny the traffic. + denied, Counter, Total responses from the authorizations service that were to deny the traffic. failure_mode_allowed, Counter, "Total requests that were error(s) but were allowed through because of failure_mode_allow set to true." ok, Counter, Total responses from the authorization service that were to allow the traffic. diff --git a/docs/root/configuration/secret.rst b/docs/root/configuration/secret.rst index c1d8566ebf083..0b4f938d52828 100644 --- a/docs/root/configuration/secret.rst +++ b/docs/root/configuration/secret.rst @@ -59,9 +59,13 @@ This example show how to configure secrets in the static_resource: E0:F3:C8:CE:5E:2E:A3:05:F0:70:1F:F5:12:E3:6E:2E:97:92:82:84:A2:28:BC:F7:73:32:D3:39:30:A1:B6:FD clusters: - connect_timeout: 0.25s - hosts: - - name: local_service_tls - ... + name: local_service_tls + load_assignment: + cluster_name: local_service_tls + endpoints: + - lb_endpoints: + - endpoint: + ... tls_context: common_tls_context: tls_certificate_sds_secret_configs: @@ -89,10 +93,15 @@ This example shows how to configure secrets fetched from remote SDS servers: clusters: - name: sds_server_mtls http2_protocol_options: {} - hosts: - socket_address: - address: 127.0.0.1 - port_value: 8234 + load_assignment: + cluster_name: sds_server_mtls + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 8234 tls_context: common_tls_context: - tls_certificate: @@ -102,24 +111,31 @@ This example shows how to configure secrets fetched from remote SDS servers: filename: certs/sds_key.pem - name: sds_server_uds http2_protocol_options: {} - hosts: - - pipe: - path: /tmp/uds_path - - name: example_cluster + load_assignment: + cluster_name: local_service_tls + endpoints: + - lb_endpoints: + - endpoint: + pipe: + path: /tmp/uds_path + - name: local_service_tls + load_assignment: + cluster_name: local_service_tls + endpoints: + - lb_endpoints: + - endpoint: + ... connect_timeout: 0.25s - hosts: - - name: local_service_tls - ... - tls_context: - common_tls_context: - tls_certificate_sds_secret_configs: - - name: client_cert - sds_config: - api_config_source: - api_type: GRPC - grpc_services: - google_grpc: - target_uri: unix:/tmp/uds_path + tls_context: + common_tls_context: + tls_certificate_sds_secret_configs: + - name: client_cert + sds_config: + api_config_source: + api_type: GRPC + grpc_services: + google_grpc: + target_uri: unix:/tmp/uds_path listeners: .... filter_chains: diff --git a/docs/root/intro/arch_overview/ssl.rst b/docs/root/intro/arch_overview/ssl.rst index 9d8bdad18676d..df1d8c52e36ed 100644 --- a/docs/root/intro/arch_overview/ssl.rst +++ b/docs/root/intro/arch_overview/ssl.rst @@ -61,7 +61,15 @@ Example configuration connect_timeout: 0.25s type: STATIC lb_policy: ROUND_ROBIN - hosts: [{ socket_address: { address: 127.0.0.2, port_value: 1234 }}] + load_assignment: + cluster_name: some_service + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.2 + port_value: 1234 tls_context: common_tls_context: tls_certificates: diff --git a/docs/root/start/start.rst b/docs/root/start/start.rst index ee6191ded3d85..5102631424734 100644 --- a/docs/root/start/start.rst +++ b/docs/root/start/start.rst @@ -93,7 +93,15 @@ The specification of the :ref:`clusters ` # Comment out the following line to test on v6 networks dns_lookup_family: V4_ONLY lb_policy: ROUND_ROBIN - hosts: [{ socket_address: { address: google.com, port_value: 443 }}] + load_assignment: + cluster_name: some_service + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: google.com + port_value: 443 tls_context: { sni: www.google.com } diff --git a/examples/front-proxy/front-envoy.yaml b/examples/front-proxy/front-envoy.yaml index d842cf3adc3b5..a9d7354c595ed 100644 --- a/examples/front-proxy/front-envoy.yaml +++ b/examples/front-proxy/front-envoy.yaml @@ -34,19 +34,29 @@ static_resources: type: strict_dns lb_policy: round_robin http2_protocol_options: {} - hosts: - - socket_address: - address: service1 - port_value: 80 + load_assignment: + cluster_name: service1 + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: service1 + port_value: 80 - name: service2 connect_timeout: 0.25s type: strict_dns lb_policy: round_robin http2_protocol_options: {} - hosts: - - socket_address: - address: service2 - port_value: 80 + load_assignment: + cluster_name: service2 + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: service2 + port_value: 80 admin: access_log_path: "/dev/null" address: diff --git a/examples/front-proxy/service-envoy.yaml b/examples/front-proxy/service-envoy.yaml index 4ae4562e5487c..cdfc44f1cf465 100644 --- a/examples/front-proxy/service-envoy.yaml +++ b/examples/front-proxy/service-envoy.yaml @@ -29,10 +29,15 @@ static_resources: connect_timeout: 0.25s type: strict_dns lb_policy: round_robin - hosts: - - socket_address: - address: 127.0.0.1 - port_value: 8080 + load_assignment: + cluster_name: local_service + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 8080 admin: access_log_path: "/dev/null" address: diff --git a/examples/grpc-bridge/config/s2s-grpc-envoy.yaml b/examples/grpc-bridge/config/s2s-grpc-envoy.yaml index f4ca6ba29c53f..3e0b5c06d4427 100644 --- a/examples/grpc-bridge/config/s2s-grpc-envoy.yaml +++ b/examples/grpc-bridge/config/s2s-grpc-envoy.yaml @@ -31,10 +31,15 @@ static_resources: type: static lb_policy: round_robin http2_protocol_options: {} - hosts: - - socket_address: - address: 127.0.0.1 - port_value: 8081 + load_assignment: + cluster_name: local_service_grpc + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 8081 admin: access_log_path: "/var/log/envoy/admin_access.log" address: diff --git a/examples/grpc-bridge/config/s2s-python-envoy.yaml b/examples/grpc-bridge/config/s2s-python-envoy.yaml index 1a0b18a3e68af..4fa4a82c43be9 100644 --- a/examples/grpc-bridge/config/s2s-python-envoy.yaml +++ b/examples/grpc-bridge/config/s2s-python-envoy.yaml @@ -46,7 +46,12 @@ static_resources: lb_policy: round_robin connect_timeout: 0.250s http_protocol_options: {} - hosts: - - socket_address: - address: grpc - port_value: 9211 + load_assignment: + cluster_name: grpc + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: grpc + port_value: 9211 diff --git a/examples/jaeger-native-tracing/front-envoy-jaeger.yaml b/examples/jaeger-native-tracing/front-envoy-jaeger.yaml index 0643a38132dd4..e38ec48f69e33 100644 --- a/examples/jaeger-native-tracing/front-envoy-jaeger.yaml +++ b/examples/jaeger-native-tracing/front-envoy-jaeger.yaml @@ -34,10 +34,15 @@ static_resources: type: strict_dns lb_policy: round_robin http2_protocol_options: {} - hosts: - - socket_address: - address: service1 - port_value: 80 + load_assignment: + cluster_name: service1 + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: service1 + port_value: 80 tracing: http: name: envoy.dynamic.ot diff --git a/examples/jaeger-native-tracing/service1-envoy-jaeger.yaml b/examples/jaeger-native-tracing/service1-envoy-jaeger.yaml index 2a18b588743e2..674a1a1bd9850 100644 --- a/examples/jaeger-native-tracing/service1-envoy-jaeger.yaml +++ b/examples/jaeger-native-tracing/service1-envoy-jaeger.yaml @@ -61,19 +61,29 @@ static_resources: connect_timeout: 0.250s type: strict_dns lb_policy: round_robin - hosts: - - socket_address: - address: 127.0.0.1 - port_value: 8080 + load_assignment: + cluster_name: local_service + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 8080 - name: service2 connect_timeout: 0.250s type: strict_dns lb_policy: round_robin http2_protocol_options: {} - hosts: - - socket_address: - address: service2 - port_value: 80 + load_assignment: + cluster_name: service2 + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: service2 + port_value: 80 tracing: http: name: envoy.dynamic.ot diff --git a/examples/jaeger-native-tracing/service2-envoy-jaeger.yaml b/examples/jaeger-native-tracing/service2-envoy-jaeger.yaml index 895224cd1a284..9756d27e9ac77 100644 --- a/examples/jaeger-native-tracing/service2-envoy-jaeger.yaml +++ b/examples/jaeger-native-tracing/service2-envoy-jaeger.yaml @@ -33,10 +33,15 @@ static_resources: connect_timeout: 0.250s type: strict_dns lb_policy: round_robin - hosts: - - socket_address: - address: 127.0.0.1 - port_value: 8080 + load_assignment: + cluster_name: local_service + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 8080 tracing: http: name: envoy.dynamic.ot diff --git a/examples/jaeger-tracing/front-envoy-jaeger.yaml b/examples/jaeger-tracing/front-envoy-jaeger.yaml index dba34e4c5993c..0a3eaae798ded 100644 --- a/examples/jaeger-tracing/front-envoy-jaeger.yaml +++ b/examples/jaeger-tracing/front-envoy-jaeger.yaml @@ -34,18 +34,28 @@ static_resources: type: strict_dns lb_policy: round_robin http2_protocol_options: {} - hosts: - - socket_address: - address: service1 - port_value: 80 + load_assignment: + cluster_name: service1 + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: service1 + port_value: 80 - name: jaeger connect_timeout: 1s type: strict_dns lb_policy: round_robin - hosts: - - socket_address: - address: jaeger - port_value: 9411 + load_assignment: + cluster_name: jaeger + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: jaeger + port_value: 9411 tracing: http: name: envoy.zipkin diff --git a/examples/jaeger-tracing/service1-envoy-jaeger.yaml b/examples/jaeger-tracing/service1-envoy-jaeger.yaml index c9aa369341d19..e912f7e7b42da 100644 --- a/examples/jaeger-tracing/service1-envoy-jaeger.yaml +++ b/examples/jaeger-tracing/service1-envoy-jaeger.yaml @@ -61,27 +61,42 @@ static_resources: connect_timeout: 0.250s type: strict_dns lb_policy: round_robin - hosts: - - socket_address: - address: 127.0.0.1 - port_value: 8080 + load_assignment: + cluster_name: local_service + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 8080 - name: service2 connect_timeout: 0.250s type: strict_dns lb_policy: round_robin http2_protocol_options: {} - hosts: - - socket_address: - address: service2 - port_value: 80 + load_assignment: + cluster_name: service2 + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: service2 + port_value: 80 - name: jaeger connect_timeout: 1s type: strict_dns lb_policy: round_robin - hosts: - - socket_address: - address: jaeger - port_value: 9411 + load_assignment: + cluster_name: jaeger + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: jaeger + port_value: 9411 tracing: http: name: envoy.zipkin diff --git a/examples/jaeger-tracing/service2-envoy-jaeger.yaml b/examples/jaeger-tracing/service2-envoy-jaeger.yaml index 6dbd16388c6cf..c57f1547c93b3 100644 --- a/examples/jaeger-tracing/service2-envoy-jaeger.yaml +++ b/examples/jaeger-tracing/service2-envoy-jaeger.yaml @@ -33,18 +33,28 @@ static_resources: connect_timeout: 0.250s type: strict_dns lb_policy: round_robin - hosts: - - socket_address: - address: 127.0.0.1 - port_value: 8080 + load_assignment: + cluster_name: local_service + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 8080 - name: jaeger connect_timeout: 1s type: strict_dns lb_policy: round_robin - hosts: - - socket_address: - address: jaeger - port_value: 9411 + load_assignment: + cluster_name: jaeger + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: jaeger + port_value: 9411 tracing: http: name: envoy.zipkin diff --git a/examples/lua/envoy.yaml b/examples/lua/envoy.yaml index ccf85ca18fb14..00f480ce7c98c 100644 --- a/examples/lua/envoy.yaml +++ b/examples/lua/envoy.yaml @@ -20,7 +20,7 @@ static_resources: routes: - match: prefix: "/" - route: + route: cluster: web_service http_filters: - name: envoy.lua @@ -41,10 +41,15 @@ static_resources: connect_timeout: 0.25s type: strict_dns # static lb_policy: round_robin - hosts: - - socket_address: - address: web_service - port_value: 80 + load_assignment: + cluster_name: web_service + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: web_service + port_value: 80 admin: access_log_path: "/dev/null" address: diff --git a/examples/zipkin-tracing/front-envoy-zipkin.yaml b/examples/zipkin-tracing/front-envoy-zipkin.yaml index e4e5a9cfb7fb4..da7b7f46a306f 100644 --- a/examples/zipkin-tracing/front-envoy-zipkin.yaml +++ b/examples/zipkin-tracing/front-envoy-zipkin.yaml @@ -35,18 +35,28 @@ static_resources: type: strict_dns lb_policy: round_robin http2_protocol_options: {} - hosts: - - socket_address: - address: service1 - port_value: 80 + load_assignment: + cluster_name: service1 + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: service1 + port_value: 80 - name: zipkin connect_timeout: 1s type: strict_dns lb_policy: round_robin - hosts: - - socket_address: - address: zipkin - port_value: 9411 + load_assignment: + cluster_name: zipkin + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: zipkin + port_value: 9411 tracing: http: name: envoy.zipkin diff --git a/examples/zipkin-tracing/service1-envoy-zipkin.yaml b/examples/zipkin-tracing/service1-envoy-zipkin.yaml index fbc9503c0a666..d6bed7eb3fc49 100644 --- a/examples/zipkin-tracing/service1-envoy-zipkin.yaml +++ b/examples/zipkin-tracing/service1-envoy-zipkin.yaml @@ -61,27 +61,42 @@ static_resources: connect_timeout: 0.250s type: strict_dns lb_policy: round_robin - hosts: - - socket_address: - address: 127.0.0.1 - port_value: 8080 + load_assignment: + cluster_name: local_service + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 8080 - name: service2 connect_timeout: 0.250s type: strict_dns lb_policy: round_robin http2_protocol_options: {} - hosts: - - socket_address: - address: service2 - port_value: 80 + load_assignment: + cluster_name: service2 + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: service2 + port_value: 80 - name: zipkin connect_timeout: 1s type: strict_dns lb_policy: round_robin - hosts: - - socket_address: - address: zipkin - port_value: 9411 + load_assignment: + cluster_name: zipkin + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: zipkin + port_value: 9411 tracing: http: name: envoy.zipkin diff --git a/examples/zipkin-tracing/service2-envoy-zipkin.yaml b/examples/zipkin-tracing/service2-envoy-zipkin.yaml index b17b3197014bf..3676b2836fa08 100644 --- a/examples/zipkin-tracing/service2-envoy-zipkin.yaml +++ b/examples/zipkin-tracing/service2-envoy-zipkin.yaml @@ -33,18 +33,28 @@ static_resources: connect_timeout: 0.250s type: strict_dns lb_policy: round_robin - hosts: - - socket_address: - address: 127.0.0.1 - port_value: 8080 + load_assignment: + cluster_name: local_service + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 8080 - name: zipkin connect_timeout: 1s type: strict_dns lb_policy: round_robin - hosts: - - socket_address: - address: zipkin - port_value: 9411 + load_assignment: + cluster_name: zipkin + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: zipkin + port_value: 9411 tracing: http: name: envoy.zipkin diff --git a/source/common/config/cds_json.cc b/source/common/config/cds_json.cc index a7a684a590d62..3fe52f2d71d8b 100644 --- a/source/common/config/cds_json.cc +++ b/source/common/config/cds_json.cc @@ -110,26 +110,14 @@ void CdsJson::translateCluster(const Json::Object& json_cluster, cluster.set_name(name); const std::string string_type = json_cluster.getString("type"); - auto set_dns_hosts = [&json_cluster, &cluster] { + auto set_dns_hosts = [&json_cluster, &cluster, name] { const auto hosts = json_cluster.getObjectArray("hosts"); - std::transform(hosts.cbegin(), hosts.cend(), - Protobuf::RepeatedPtrFieldBackInserter(cluster.mutable_hosts()), - [](const Json::ObjectSharedPtr& host) { - envoy::api::v2::core::Address address; - AddressJson::translateAddress(host->getString("url"), true, false, address); - return address; - }); + translateClusterHosts(name, hosts, true, false, *cluster.mutable_load_assignment()); }; if (string_type == "static") { cluster.set_type(envoy::api::v2::Cluster::STATIC); const auto hosts = json_cluster.getObjectArray("hosts"); - std::transform(hosts.cbegin(), hosts.cend(), - Protobuf::RepeatedPtrFieldBackInserter(cluster.mutable_hosts()), - [](const Json::ObjectSharedPtr& host) { - envoy::api::v2::core::Address address; - AddressJson::translateAddress(host->getString("url"), true, true, address); - return address; - }); + translateClusterHosts(name, hosts, true, true, *cluster.mutable_load_assignment()); } else if (string_type == "strict_dns") { cluster.set_type(envoy::api::v2::Cluster::STRICT_DNS); set_dns_hosts(); @@ -223,5 +211,23 @@ void CdsJson::translateCluster(const Json::Object& json_cluster, } } +void CdsJson::translateClusterHosts(const std::string& cluster_name, + const std::vector& json_cluster_hosts, + bool url, bool resolved, + envoy::api::v2::ClusterLoadAssignment& load_assignment) { + // TODO(dio): Early return when json_cluster_hosts is empty. + load_assignment.set_cluster_name(cluster_name); + auto* locality_lb_endpoints = load_assignment.add_endpoints(); + // Since this LocalityLbEndpoints is built from hosts list, set the default weight to 1. + locality_lb_endpoints->mutable_load_balancing_weight()->set_value(1); + for (const Json::ObjectSharedPtr& json_host : json_cluster_hosts) { + envoy::api::v2::core::Address address; + AddressJson::translateAddress(json_host->getString("url"), url, resolved, address); + auto* lb_endpoint = locality_lb_endpoints->add_lb_endpoints(); + lb_endpoint->mutable_endpoint()->mutable_address()->MergeFrom(address); + lb_endpoint->mutable_load_balancing_weight()->set_value(1); + } +} + } // namespace Config } // namespace Envoy diff --git a/source/common/config/cds_json.h b/source/common/config/cds_json.h index 1cb47f2555bcc..bd52a8b3eda2e 100644 --- a/source/common/config/cds_json.h +++ b/source/common/config/cds_json.h @@ -67,6 +67,22 @@ class CdsJson { const absl::optional& eds_config, envoy::api::v2::Cluster& cluster, const Stats::StatsOptions& stats_options); + + /** + * Translate a v1 JSON Cluster addresses (hosts) vector to v2 + * envoy::api::v2::ClusterLoadAssignment. This is needed since there are many tests depends on + * CdsJson::translateCluster that previously sets v2 envoy::api::v2::Cluster's hosts. + * @param cluster_name the cluster name. + * @param json_cluster_hosts source v1 JSON Cluster Hosts vector. + * @param url is json_address a URL? E.g. tcp://:. If not, it is + * treated as :. + * @param resolved is the address of json_addresses a concrete IP/pipe or unresolved hostname? + * @param load assignment destination v2 envoy::api::v2::ClusterLoadAssignment. + */ + static void translateClusterHosts(const std::string& cluster_name, + const std::vector& json_addresses, + bool url, bool resolved, + envoy::api::v2::ClusterLoadAssignment& load_assignment); }; } // namespace Config diff --git a/source/common/config/utility.cc b/source/common/config/utility.cc index cf0d1196f9acf..d2e299e0df4da 100644 --- a/source/common/config/utility.cc +++ b/source/common/config/utility.cc @@ -267,20 +267,5 @@ Grpc::AsyncClientFactoryPtr Utility::factoryForGrpcApiConfigSource( return async_client_manager.factoryForGrpcService(grpc_service, scope, false); } -envoy::api::v2::ClusterLoadAssignment Utility::translateClusterHosts( - const Protobuf::RepeatedPtrField& hosts) { - envoy::api::v2::ClusterLoadAssignment load_assignment; - envoy::api::v2::endpoint::LocalityLbEndpoints* locality_lb_endpoints = - load_assignment.add_endpoints(); - // Since this LocalityLbEndpoints is built from hosts list, set the default weight to 1. - locality_lb_endpoints->mutable_load_balancing_weight()->set_value(1); - for (const envoy::api::v2::core::Address& host : hosts) { - envoy::api::v2::endpoint::LbEndpoint* lb_endpoint = locality_lb_endpoints->add_lb_endpoints(); - lb_endpoint->mutable_endpoint()->mutable_address()->MergeFrom(host); - lb_endpoint->mutable_load_balancing_weight()->set_value(1); - } - return load_assignment; -} - } // namespace Config } // namespace Envoy diff --git a/source/common/config/utility.h b/source/common/config/utility.h index f58d3fe4c9c36..8aad438cc399e 100644 --- a/source/common/config/utility.h +++ b/source/common/config/utility.h @@ -352,14 +352,6 @@ class Utility { factoryForGrpcApiConfigSource(Grpc::AsyncClientManager& async_client_manager, const envoy::api::v2::core::ApiConfigSource& api_config_source, Stats::Scope& scope); - - /** - * Translate a set of cluster's hosts into a load assignment configuration. - * @param hosts cluster's list of hosts. - * @return envoy::api::v2::ClusterLoadAssignment a load assignment configuration. - */ - static envoy::api::v2::ClusterLoadAssignment - translateClusterHosts(const Protobuf::RepeatedPtrField& hosts); }; } // namespace Config diff --git a/source/common/upstream/cluster_manager_impl.cc b/source/common/upstream/cluster_manager_impl.cc index 06ee71363572e..265fcf0d56327 100644 --- a/source/common/upstream/cluster_manager_impl.cc +++ b/source/common/upstream/cluster_manager_impl.cc @@ -207,6 +207,10 @@ ClusterManagerImpl::ClusterManagerImpl(const envoy::config::bootstrap::v2::Boots if (cluster.type() != envoy::api::v2::Cluster::EDS) { loadCluster(cluster, "", false, active_clusters_); } + + // TODO(dio): make sure cluster's load_assignment cluster name to be the same with its cluster + // name, even for static configuration. + // https://github.com/envoyproxy/envoy/pull/4123#issuecomment-412693859. } // Now setup ADS if needed, this might rely on a primary cluster. diff --git a/source/common/upstream/health_discovery_service.cc b/source/common/upstream/health_discovery_service.cc index fcfc9238bb1b4..15e2935bdc62d 100644 --- a/source/common/upstream/health_discovery_service.cc +++ b/source/common/upstream/health_discovery_service.cc @@ -125,10 +125,13 @@ void HdsDelegate::processMessage( cluster_config.mutable_per_connection_buffer_limit_bytes()->set_value( ClusterConnectionBufferLimitBytes); - // Add endpoints to cluster + // Add endpoints to cluster. + auto* load_assignment = cluster_config.mutable_load_assignment(); + auto* locality_lb_endpoints = load_assignment->add_endpoints(); for (const auto& locality_endpoints : cluster_health_check.locality_endpoints()) { for (const auto& endpoint : locality_endpoints.endpoints()) { - cluster_config.add_hosts()->MergeFrom(endpoint.address()); + auto* lb_endpoint = locality_lb_endpoints->add_lb_endpoints(); + lb_endpoint->mutable_endpoint()->MergeFrom(endpoint); } } @@ -194,13 +197,15 @@ HdsCluster::HdsCluster(Runtime::Loader& runtime, const envoy::api::v2::Cluster& info_ = info_factory.createClusterInfo(runtime_, cluster_, bind_config_, stats_, ssl_context_manager_, added_via_api_, cm, local_info, dispatcher, random); - - for (const auto& host : cluster.hosts()) { - initial_hosts_->emplace_back(new HostImpl( - info_, "", Network::Address::resolveProtoAddress(host), - envoy::api::v2::core::Metadata::default_instance(), 1, - envoy::api::v2::core::Locality().default_instance(), - envoy::api::v2::endpoint::Endpoint::HealthCheckConfig().default_instance(), 0)); + const auto& locality_lb_endpoints = cluster.load_assignment().endpoints(); + for (const auto& locality_lb_endpoint : locality_lb_endpoints) { + for (const auto& lb_endpoint : locality_lb_endpoint.lb_endpoints()) { + const auto& host = lb_endpoint.endpoint().address(); + // TODO(dio): Check if initial weight and priority need to be inferred from the config. + initial_hosts_->emplace_back(new HostImpl( + info_, "", Network::Address::resolveProtoAddress(host), lb_endpoint.metadata(), 1, + locality_lb_endpoint.locality(), lb_endpoint.endpoint().health_check_config(), 0)); + } } initialize([] {}); } diff --git a/source/common/upstream/logical_dns_cluster.cc b/source/common/upstream/logical_dns_cluster.cc index 7a26b09546533..f04ee239385ed 100644 --- a/source/common/upstream/logical_dns_cluster.cc +++ b/source/common/upstream/logical_dns_cluster.cc @@ -28,18 +28,11 @@ LogicalDnsCluster::LogicalDnsCluster( std::chrono::milliseconds(PROTOBUF_GET_MS_OR_DEFAULT(cluster, dns_refresh_rate, 5000))), tls_(tls.allocateSlot()), resolve_timer_(factory_context.dispatcher().createTimer( [this]() -> void { startResolve(); })), - local_info_(factory_context.localInfo()), - load_assignment_(cluster.has_load_assignment() - ? cluster.load_assignment() - : Config::Utility::translateClusterHosts(cluster.hosts())) { + local_info_(factory_context.localInfo()), load_assignment_(cluster.load_assignment()) { const auto& locality_lb_endpoints = load_assignment_.endpoints(); if (locality_lb_endpoints.size() != 1 || locality_lb_endpoints[0].lb_endpoints().size() != 1) { - if (cluster.has_load_assignment()) { - throw EnvoyException( - "LOGICAL_DNS clusters must have a single locality_lb_endpoint and a single lb_endpoint"); - } else { - throw EnvoyException("LOGICAL_DNS clusters must have a single host"); - } + throw EnvoyException( + "LOGICAL_DNS clusters must have a single locality_lb_endpoint and a single lb_endpoint"); } switch (cluster.dns_lookup_family()) { diff --git a/source/common/upstream/upstream_impl.cc b/source/common/upstream/upstream_impl.cc index c532e462bfbfe..7de1256d1107a 100644 --- a/source/common/upstream/upstream_impl.cc +++ b/source/common/upstream/upstream_impl.cc @@ -868,12 +868,7 @@ StaticClusterImpl::StaticClusterImpl( Stats::ScopePtr&& stats_scope, bool added_via_api) : ClusterImplBase(cluster, runtime, factory_context, std::move(stats_scope), added_via_api), priority_state_manager_(new PriorityStateManager(*this, factory_context.localInfo())) { - // TODO(dio): Use by-reference when cluster.hosts() is removed. - const envoy::api::v2::ClusterLoadAssignment cluster_load_assignment( - cluster.has_load_assignment() ? cluster.load_assignment() - : Config::Utility::translateClusterHosts(cluster.hosts())); - - for (const auto& locality_lb_endpoint : cluster_load_assignment.endpoints()) { + for (const auto& locality_lb_endpoint : cluster.load_assignment().endpoints()) { priority_state_manager_->initializePriorityFor(locality_lb_endpoint); for (const auto& lb_endpoint : locality_lb_endpoint.lb_endpoints()) { priority_state_manager_->registerHostForPriority( @@ -1111,10 +1106,7 @@ StrictDnsClusterImpl::StrictDnsClusterImpl( NOT_REACHED_GCOVR_EXCL_LINE; } - const envoy::api::v2::ClusterLoadAssignment load_assignment( - cluster.has_load_assignment() ? cluster.load_assignment() - : Config::Utility::translateClusterHosts(cluster.hosts())); - const auto& locality_lb_endpoints = load_assignment.endpoints(); + const auto& locality_lb_endpoints = cluster.load_assignment().endpoints(); for (const auto& locality_lb_endpoint : locality_lb_endpoints) { for (const auto& lb_endpoint : locality_lb_endpoint.lb_endpoints()) { const auto& host = lb_endpoint.endpoint().address(); diff --git a/test/common/config/utility_test.cc b/test/common/config/utility_test.cc index d049e5a2b8c52..633f93a90471d 100644 --- a/test/common/config/utility_test.cc +++ b/test/common/config/utility_test.cc @@ -203,7 +203,9 @@ TEST(UtilityTest, UnixClusterStatic) { envoy::api::v2::core::ConfigSource eds_config; Stats::StatsOptionsImpl stats_options; Config::CdsJson::translateCluster(*json_object_ptr, eds_config, cluster, stats_options); - EXPECT_EQ("/test.sock", cluster.hosts(0).pipe().path()); + EXPECT_EQ( + "/test.sock", + cluster.load_assignment().endpoints(0).lb_endpoints(0).endpoint().address().pipe().path()); } TEST(UtilityTest, CheckFilesystemSubscriptionBackingPath) { diff --git a/test/common/upstream/cluster_manager_impl_test.cc b/test/common/upstream/cluster_manager_impl_test.cc index d7ad715c59e2e..9b0a81e03aa86 100644 --- a/test/common/upstream/cluster_manager_impl_test.cc +++ b/test/common/upstream/cluster_manager_impl_test.cc @@ -180,13 +180,20 @@ class ClusterManagerImplTest : public testing::Test { connect_timeout: 0.250s type: STATIC lb_policy: ROUND_ROBIN - hosts: - - socket_address: - address: "127.0.0.1" - port_value: 11001 - - socket_address: - address: "127.0.0.1" - port_value: 11002 + load_assignment: + cluster_name: cluster_1 + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11001 + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11002 )EOF"; const std::string merge_window = R"EOF( common_lb_config: @@ -565,13 +572,20 @@ TEST_F(ClusterManagerImplTest, RingHashLoadBalancerV2Initialization) { - name: redis_cluster connect_timeout: 0.250s lb_policy: RING_HASH - hosts: - - socket_address: - address: 127.0.0.1 - port_value: 8000 - - socket_address: - address: 127.0.0.1 - port_value: 8001 + load_assignment: + cluster_name: redis_cluster + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 8000 + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 8001 dns_lookup_family: V4_ONLY ring_hash_lb_config: minimum_ring_size: 125 @@ -842,10 +856,19 @@ version_info: version3 - cluster: name: "cds_cluster" connect_timeout: 0.25s - hosts: - - socket_address: - address: "127.0.0.1" - port_value: 11001 + load_assignment: + cluster_name: cds_cluster + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11001 + load_balancing_weight: + value: 1 + load_balancing_weight: + value: 1 dns_lookup_family: V4_ONLY last_updated: seconds: 1234567891 @@ -853,10 +876,19 @@ version_info: version3 - cluster: name: "fake_cluster" connect_timeout: 0.25s - hosts: - - socket_address: - address: "127.0.0.1" - port_value: 11001 + load_assignment: + cluster_name: fake_cluster + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11001 + load_balancing_weight: + value: 1 + load_balancing_weight: + value: 1 dns_lookup_family: V4_ONLY last_updated: seconds: 1234567891 @@ -864,10 +896,19 @@ version_info: version3 - cluster: name: "fake_cluster2" connect_timeout: 0.25s - hosts: - - socket_address: - address: "127.0.0.1" - port_value: 11001 + load_assignment: + cluster_name: fake_cluster2 + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11001 + load_balancing_weight: + value: 1 + load_balancing_weight: + value: 1 dns_lookup_family: V4_ONLY last_updated: seconds: 1234567891 @@ -877,10 +918,19 @@ version_info: version3 cluster: name: "cluster3" connect_timeout: 0.25s - hosts: - - socket_address: - address: "127.0.0.1" - port_value: 11001 + load_assignment: + cluster_name: cluster3 + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11001 + load_balancing_weight: + value: 1 + load_balancing_weight: + value: 1 dns_lookup_family: V4_ONLY last_updated: seconds: 1234567891 @@ -889,10 +939,19 @@ version_info: version3 cluster: name: "cluster4" connect_timeout: 0.25s - hosts: - - socket_address: - address: "127.0.0.1" - port_value: 11001 + load_assignment: + cluster_name: cluster4 + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11001 + load_balancing_weight: + value: 1 + load_balancing_weight: + value: 1 dns_lookup_family: V4_ONLY last_updated: seconds: 1234567891 @@ -901,10 +960,19 @@ version_info: version3 cluster: name: "cluster5" connect_timeout: 0.25s - hosts: - - socket_address: - address: "127.0.0.1" - port_value: 11001 + load_assignment: + cluster_name: cluster5 + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11001 + load_balancing_weight: + value: 1 + load_balancing_weight: + value: 1 dns_lookup_family: V4_ONLY last_updated: seconds: 1234567891 @@ -1014,10 +1082,19 @@ TEST_F(ClusterManagerImplTest, RemoveWarmingCluster) { cluster: name: "fake_cluster" connect_timeout: 0.25s - hosts: - - socket_address: - address: "127.0.0.1" - port_value: 11001 + load_assignment: + cluster_name: fake_cluster + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11001 + load_balancing_weight: + value: 1 + load_balancing_weight: + value: 1 dns_lookup_family: V4_ONLY last_updated: seconds: 1234567891 @@ -1559,10 +1636,15 @@ TEST_F(ClusterManagerImplTest, DynamicHostRemoveDefaultPriority) { address: 1.2.3.4 port_value: 80 lb_policy: ROUND_ROBIN - hosts: - - socket_address: - address: localhost - port_value: 11001 + load_assignment: + cluster_name: cluster_1 + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: localhost + port_value: 11001 )EOF"; std::shared_ptr dns_resolver(new Network::MockDnsResolver()); @@ -1634,10 +1716,15 @@ TEST_F(ClusterManagerImplTest, ConnPoolDestroyWithDraining) { address: 1.2.3.4 port_value: 80 lb_policy: ROUND_ROBIN - hosts: - - socket_address: - address: localhost - port_value: 11001 + load_assignment: + cluster_name: cluster_1 + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: localhost + port_value: 11001 )EOF"; std::shared_ptr dns_resolver(new Network::MockDnsResolver()); @@ -1956,10 +2043,15 @@ TEST_F(ClusterManagerImplTest, MergedUpdatesDestroyedOnUpdate) { connect_timeout: 0.250s type: STATIC lb_policy: ROUND_ROBIN - hosts: - - socket_address: - address: 127.0.0.1 - port_value: 12001 + load_assignment: + cluster_name: fake_cluster + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 12001 common_lb_config: update_merge_window: 3s )EOF"; @@ -2003,10 +2095,15 @@ TEST_F(ClusterManagerImplTest, MergedUpdatesDestroyedOnUpdate) { connect_timeout: 0.250s type: STATIC lb_policy: ROUND_ROBIN - hosts: - - socket_address: - address: 127.0.0.1 - port_value: 12001 + load_assignment: + cluster_name: fake_cluster + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 12001 common_lb_config: update_merge_window: 4s )EOF"; @@ -2242,10 +2339,15 @@ TEST_F(SockoptsTest, SockoptsUnset) { connect_timeout: 0.250s lb_policy: ROUND_ROBIN type: STATIC - hosts: - - socket_address: - address: "127.0.0.1" - port_value: 11001 + load_assignment: + cluster_name: SockoptsCluster + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11001 )EOF"; initialize(yaml); expectNoSocketOptions(); @@ -2259,10 +2361,15 @@ TEST_F(SockoptsTest, FreebindClusterOnly) { connect_timeout: 0.250s lb_policy: ROUND_ROBIN type: STATIC - hosts: - - socket_address: - address: "127.0.0.1" - port_value: 11001 + load_assignment: + cluster_name: SockoptsCluster + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11001 upstream_bind_config: freebind: true )EOF"; @@ -2278,10 +2385,15 @@ TEST_F(SockoptsTest, FreebindClusterManagerOnly) { connect_timeout: 0.250s lb_policy: ROUND_ROBIN type: STATIC - hosts: - - socket_address: - address: "127.0.0.1" - port_value: 11001 + load_assignment: + cluster_name: SockoptsCluster + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11001 cluster_manager: upstream_bind_config: freebind: true @@ -2298,10 +2410,15 @@ TEST_F(SockoptsTest, FreebindClusterOverride) { connect_timeout: 0.250s lb_policy: ROUND_ROBIN type: STATIC - hosts: - - socket_address: - address: "127.0.0.1" - port_value: 11001 + load_assignment: + cluster_name: SockoptsCluster + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11001 upstream_bind_config: freebind: true cluster_manager: @@ -2320,10 +2437,15 @@ TEST_F(SockoptsTest, SockoptsClusterOnly) { connect_timeout: 0.250s lb_policy: ROUND_ROBIN type: STATIC - hosts: - - socket_address: - address: "127.0.0.1" - port_value: 11001 + load_assignment: + cluster_name: SockoptsCluster + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11001 upstream_bind_config: socket_options: [ { level: 1, name: 2, int_value: 3, state: STATE_PREBIND }, @@ -2344,10 +2466,15 @@ TEST_F(SockoptsTest, SockoptsClusterManagerOnly) { connect_timeout: 0.250s lb_policy: ROUND_ROBIN type: STATIC - hosts: - - socket_address: - address: "127.0.0.1" - port_value: 11001 + load_assignment: + cluster_name: SockoptsCluster + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11001 cluster_manager: upstream_bind_config: socket_options: [ @@ -2368,10 +2495,15 @@ TEST_F(SockoptsTest, SockoptsClusterOverride) { connect_timeout: 0.250s lb_policy: ROUND_ROBIN type: STATIC - hosts: - - socket_address: - address: "127.0.0.1" - port_value: 11001 + load_assignment: + cluster_name: SockoptsCluster + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11001 upstream_bind_config: socket_options: [ { level: 1, name: 2, int_value: 3, state: STATE_PREBIND }, @@ -2495,10 +2627,15 @@ TEST_F(TcpKeepaliveTest, TcpKeepaliveUnset) { connect_timeout: 0.250s lb_policy: ROUND_ROBIN type: STATIC - hosts: - - socket_address: - address: "127.0.0.1" - port_value: 11001 + load_assignment: + cluster_name: TcpKeepaliveCluster + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11001 )EOF"; initialize(yaml); expectNoSocketOptions(); @@ -2512,10 +2649,15 @@ TEST_F(TcpKeepaliveTest, TcpKeepaliveCluster) { connect_timeout: 0.250s lb_policy: ROUND_ROBIN type: STATIC - hosts: - - socket_address: - address: "127.0.0.1" - port_value: 11001 + load_assignment: + cluster_name: TcpKeepaliveCluster + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11001 upstream_connection_options: tcp_keepalive: {} )EOF"; @@ -2531,10 +2673,15 @@ TEST_F(TcpKeepaliveTest, TcpKeepaliveClusterProbes) { connect_timeout: 0.250s lb_policy: ROUND_ROBIN type: STATIC - hosts: - - socket_address: - address: "127.0.0.1" - port_value: 11001 + load_assignment: + cluster_name: TcpKeepaliveCluster + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11001 upstream_connection_options: tcp_keepalive: keepalive_probes: 7 @@ -2551,10 +2698,15 @@ TEST_F(TcpKeepaliveTest, TcpKeepaliveWithAllOptions) { connect_timeout: 0.250s lb_policy: ROUND_ROBIN type: STATIC - hosts: - - socket_address: - address: "127.0.0.1" - port_value: 11001 + load_assignment: + cluster_name: TcpKeepaliveCluster + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 11001 upstream_connection_options: tcp_keepalive: keepalive_probes: 7 diff --git a/test/common/upstream/logical_dns_cluster_test.cc b/test/common/upstream/logical_dns_cluster_test.cc index 44bf2ebe260f1..67105641f7fb3 100644 --- a/test/common/upstream/logical_dns_cluster_test.cc +++ b/test/common/upstream/logical_dns_cluster_test.cc @@ -290,8 +290,11 @@ TEST_F(LogicalDnsClusterTest, BadConfig) { } )EOF"; - EXPECT_THROW_WITH_MESSAGE(setupFromV1Json(multiple_hosts_json), EnvoyException, - "LOGICAL_DNS clusters must have a single host"); + EXPECT_THROW_WITH_MESSAGE( + setupFromV1Json(multiple_hosts_json), EnvoyException, + // Since Envoy::Config::CdsJson now translates hosts to load_assignment, hence the message is + // changed. + "LOGICAL_DNS clusters must have a single locality_lb_endpoint and a single lb_endpoint"); const std::string multiple_lb_endpoints_yaml = R"EOF( name: name @@ -379,10 +382,15 @@ TEST_F(LogicalDnsClusterTest, Basic) { # Since the following expectResolve() requires Network::DnsLookupFamily::V4Only we need to set # dns_lookup_family to V4_ONLY explicitly for v2 .yaml config. dns_lookup_family: V4_ONLY - hosts: - - socket_address: - address: foo.bar.com - port_value: 443 + load_assignment: + cluster_name: name + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: foo.bar.com + port_value: 443 )EOF"; const std::string basic_yaml_load_assignment = R"EOF( diff --git a/test/common/upstream/upstream_impl_test.cc b/test/common/upstream/upstream_impl_test.cc index c1273e77129e9..b35f5eba3e5f3 100644 --- a/test/common/upstream/upstream_impl_test.cc +++ b/test/common/upstream/upstream_impl_test.cc @@ -178,7 +178,15 @@ TEST(StrictDnsClusterImplTest, ZeroHostsHealthChecker) { connect_timeout: 0.25s type: STRICT_DNS lb_policy: ROUND_ROBIN - hosts: [{ socket_address: { address: foo.bar.com, port_value: 443 }}] + load_assignment: + cluster_name: name + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: foo.bar.com + port_value: 443 )EOF"; ResolverData resolver(*dns_resolver, dispatcher); @@ -367,7 +375,15 @@ TEST(StrictDnsClusterImplTest, HostRemovalActiveHealthSkipped) { type: STRICT_DNS lb_policy: ROUND_ROBIN drain_connections_on_host_removal: true - hosts: [{ socket_address: { address: foo.bar.com, port_value: 443 }}] + load_assignment: + cluster_name: name + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: foo.bar.com + port_value: 443 )EOF"; ResolverData resolver(*dns_resolver, dispatcher); @@ -797,10 +813,15 @@ TEST(StaticClusterImplTest, InitialHosts) { connect_timeout: 0.25s type: STATIC lb_policy: ROUND_ROBIN - hosts: - - socket_address: - address: 10.0.0.1 - port_value: 443 + load_assignment: + cluster_name: name + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 10.0.0.1 + port_value: 443 )EOF"; NiceMock cm; @@ -1021,7 +1042,15 @@ TEST(StaticClusterImplTest, AltStatName) { connect_timeout: 0.25s type: STRICT_DNS lb_policy: ROUND_ROBIN - hosts: [{ socket_address: { address: 10.0.0.1, port_value: 443 }}] + load_assignment: + cluster_name: name + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 10.0.0.1 + port_value: 443 )EOF"; NiceMock cm; @@ -1321,7 +1350,15 @@ TEST(StaticClusterImplTest, MalformedHostIP) { connect_timeout: 0.25s type: STATIC lb_policy: ROUND_ROBIN - hosts: [{ socket_address: { address: foo.bar.com }}] + load_assignment: + cluster_name: name + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: foo.bar.com + port_value: 443 )EOF"; NiceMock cm; @@ -1439,7 +1476,15 @@ TEST(ClusterImplTest, CloseConnectionsOnHostHealthFailure) { type: STRICT_DNS lb_policy: ROUND_ROBIN close_connections_on_host_health_failure: true - hosts: [{ socket_address: { address: foo.bar.com, port_value: 443 }}] + load_assignment: + cluster_name: name + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: foo.bar.com + port_value: 443 )EOF"; envoy::api::v2::Cluster cluster_config = parseClusterFromV2Yaml(yaml); Envoy::Stats::ScopePtr scope = stats.createScope(fmt::format( @@ -1559,7 +1604,15 @@ TEST_F(ClusterInfoImplTest, Metadata) { connect_timeout: 0.25s type: STRICT_DNS lb_policy: MAGLEV - hosts: [{ socket_address: { address: foo.bar.com, port_value: 443 }}] + load_assignment: + cluster_name: name + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: foo.bar.com + port_value: 443 metadata: { filter_metadata: { com.bar.foo: { baz: test_value }, baz: {name: meh } } } common_lb_config: @@ -1587,7 +1640,15 @@ TEST_F(ClusterInfoImplTest, BrokenTypedMetadata) { connect_timeout: 0.25s type: STRICT_DNS lb_policy: MAGLEV - hosts: [{ socket_address: { address: foo.bar.com, port_value: 443 }}] + load_assignment: + cluster_name: name + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: foo.bar.com + port_value: 443 metadata: { filter_metadata: { com.bar.foo: { baz: test_value }, baz: {boom: meh} } } common_lb_config: @@ -1608,7 +1669,15 @@ TEST_F(ClusterInfoImplTest, ExtensionProtocolOptionsForUnknownFilter) { connect_timeout: 0.25s type: STRICT_DNS lb_policy: ROUND_ROBIN - hosts: [{ socket_address: { address: foo.bar.com, port_value: 443 }}] + load_assignment: + cluster_name: name + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: foo.bar.com + port_value: 443 extension_protocol_options: no_such_filter: { option: value } )EOF"; @@ -1713,7 +1782,15 @@ TEST_F(ClusterInfoImplTest, ExtensionProtocolOptionsForFilterWithoutOptions) { connect_timeout: 0.25s type: STRICT_DNS lb_policy: ROUND_ROBIN - hosts: [{ socket_address: { address: foo.bar.com, port_value: 443 }}] + load_assignment: + cluster_name: name + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: foo.bar.com + port_value: 443 extension_protocol_options: envoy.test.filter: { option: value } )EOF"; @@ -1751,7 +1828,15 @@ TEST_F(ClusterInfoImplTest, ExtensionProtocolOptionsForFilterWithOptions) { connect_timeout: 0.25s type: STRICT_DNS lb_policy: ROUND_ROBIN - hosts: [{ socket_address: { address: foo.bar.com, port_value: 443 }}] + load_assignment: + cluster_name: name + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: foo.bar.com + port_value: 443 extension_protocol_options: envoy.test.filter: { option: "value" } )EOF"; diff --git a/test/config/integration/google_com_proxy_port_0.v2.yaml b/test/config/integration/google_com_proxy_port_0.v2.yaml index feafcd384925a..d20acb1a603f0 100644 --- a/test/config/integration/google_com_proxy_port_0.v2.yaml +++ b/test/config/integration/google_com_proxy_port_0.v2.yaml @@ -33,4 +33,12 @@ static_resources: # Comment out the following line to test on v6 networks dns_lookup_family: {{ dns_lookup_family }} lb_policy: ROUND_ROBIN - hosts: [{ socket_address: { address: google.com, port_value: 443 }}] + load_assignment: + cluster_name: service_google + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: google.com + port_value: 443 diff --git a/test/config/integration/server.yaml b/test/config/integration/server.yaml index 0afe172d3197f..5887ae4bfb574 100644 --- a/test/config/integration/server.yaml +++ b/test/config/integration/server.yaml @@ -344,64 +344,104 @@ static_resources: clusters: - name: cds connect_timeout: 5s - hosts: - - socket_address: - address: {{ ip_loopback_address }} - port_value: 4 + load_assignment: + cluster_name: cds + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: {{ ip_loopback_address }} + port_value: 4 dns_lookup_family: "{{ dns_lookup_family }}" - name: rds connect_timeout: 5s - hosts: - - socket_address: - address: {{ ip_loopback_address }} - port_value: 4 + load_assignment: + cluster_name: rds + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: {{ ip_loopback_address }} + port_value: 4 dns_lookup_family: "{{ dns_lookup_family }}" - name: lds connect_timeout: 5s - hosts: - - socket_address: - address: {{ ip_loopback_address }} - port_value: 4 + load_assignment: + cluster_name: lds + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: {{ ip_loopback_address }} + port_value: 4 dns_lookup_family: "{{ dns_lookup_family }}" - name: cluster_1 connect_timeout: 5s - hosts: - - socket_address: - address: {{ ip_loopback_address }} - port_value: {{ upstream_0 }} + load_assignment: + cluster_name: cluster_1 + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: {{ ip_loopback_address }} + port_value: {{ upstream_0 }} dns_lookup_family: "{{ dns_lookup_family }}" - name: cluster_2 type: STRICT_DNS connect_timeout: 5s - hosts: - - socket_address: - address: localhost - port_value: {{ upstream_1 }} + load_assignment: + cluster_name: cluster_2 + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: localhost + port_value: {{ upstream_1 }} dns_lookup_family: "{{ dns_lookup_family }}" - name: cluster_3 connect_timeout: 5s per_connection_buffer_limit_bytes: 1024 - hosts: - - socket_address: - address: {{ ip_loopback_address }} - port_value: {{ upstream_0 }} + load_assignment: + cluster_name: cluster_3 + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: {{ ip_loopback_address }} + port_value: {{ upstream_0 }} dns_lookup_family: "{{ dns_lookup_family }}" - name: statsd type: STRICT_DNS connect_timeout: 5s - hosts: - - socket_address: - address: localhost - port_value: 4 + load_assignment: + cluster_name: statsd + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: localhost + port_value: 4 dns_lookup_family: "{{ dns_lookup_family }}" - name: redis type: STRICT_DNS connect_timeout: 5s lb_policy: RING_HASH - hosts: - - socket_address: - address: localhost - port_value: 4 + load_assignment: + cluster_name: redis + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: localhost + port_value: 4 dns_lookup_family: "{{ dns_lookup_family }}" outlier_detection: {} dynamic_resources: diff --git a/test/config/integration/server_ads.yaml b/test/config/integration/server_ads.yaml index 3400df7e47e58..46a1bc1b0c87e 100644 --- a/test/config/integration/server_ads.yaml +++ b/test/config/integration/server_ads.yaml @@ -11,10 +11,15 @@ static_resources: - name: ads_cluster connect_timeout: { seconds: 5 } type: STATIC - hosts: - - socket_address: - address: {{ ntop_ip_loopback_address }} - port_value: {{ ads_upstream }} + load_assignment: + cluster_name: ads_cluster + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: {{ ntop_ip_loopback_address }} + port_value: {{ ads_upstream }} lb_policy: ROUND_ROBIN http2_protocol_options: {} admin: diff --git a/test/config/integration/server_unix_listener.yaml b/test/config/integration/server_unix_listener.yaml index f985411fac4d3..65ed3b37b3886 100644 --- a/test/config/integration/server_unix_listener.yaml +++ b/test/config/integration/server_unix_listener.yaml @@ -28,10 +28,15 @@ static_resources: clusters: - name: cluster_0 connect_timeout: 5s - hosts: - - socket_address: - address: "{{ ip_loopback_address }}" - port_value: 0 + load_assignment: + cluster_name: cluster_0 + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: {{ ip_loopback_address }} + port_value: 0 dns_lookup_family: V4_ONLY cluster_manager: {} watchdog: {} diff --git a/test/config/utility.cc b/test/config/utility.cc index 9098a8102ee01..91bb7c5dd4779 100644 --- a/test/config/utility.cc +++ b/test/config/utility.cc @@ -27,10 +27,15 @@ const std::string ConfigHelper::BASE_CONFIG = R"EOF( static_resources: clusters: name: cluster_0 - hosts: - socket_address: - address: 127.0.0.1 - port_value: 0 + load_assignment: + cluster_name: cluster_0 + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 0 listeners: name: listener_0 address: @@ -132,8 +137,18 @@ ConfigHelper::ConfigHelper(const Network::Address::IpVersion version, const std: for (int i = 0; i < static_resources->clusters_size(); ++i) { auto* cluster = static_resources->mutable_clusters(i); - if (!cluster->hosts().empty() && cluster->mutable_hosts(0)->has_socket_address()) { - auto host_socket_addr = cluster->mutable_hosts(0)->mutable_socket_address(); + + auto* load_assignment = cluster->mutable_load_assignment(); + // TODO(dio): Probably setting endpoint and address to be non-nullable will be helpful here. + if (!load_assignment->endpoints().empty() && + !load_assignment->endpoints(0).lb_endpoints().empty() && + load_assignment->endpoints(0).lb_endpoints(0).has_endpoint() && + load_assignment->endpoints(0).lb_endpoints(0).endpoint().has_address() && + load_assignment->endpoints(0).lb_endpoints(0).endpoint().address().has_socket_address()) { + auto locality_lb_endpoint = load_assignment->mutable_endpoints(0); + auto lb_endpoint = locality_lb_endpoint->mutable_lb_endpoints(0); + auto host_socket_addr = + lb_endpoint->mutable_endpoint()->mutable_address()->mutable_socket_address(); host_socket_addr->set_address(Network::Test::getLoopbackAddressString(version)); } } @@ -176,14 +191,6 @@ void ConfigHelper::finalize(const std::vector& ports) { if (cluster->type() == envoy::api::v2::Cluster::EDS) { eds_hosts = true; } else { - for (int j = 0; j < cluster->hosts_size(); ++j) { - if (cluster->mutable_hosts(j)->has_socket_address()) { - auto* host_socket_addr = cluster->mutable_hosts(j)->mutable_socket_address(); - RELEASE_ASSERT(ports.size() > port_idx, ""); - host_socket_addr->set_port_value(ports[port_idx++]); - } - } - // Assign ports to statically defined load_assignment hosts. for (int j = 0; j < cluster->load_assignment().endpoints_size(); ++j) { auto locality_lb = cluster->mutable_load_assignment()->mutable_endpoints(j); diff --git a/test/integration/ads_integration_test.cc b/test/integration/ads_integration_test.cc index ba944c9c99176..39a1704091107 100644 --- a/test/integration/ads_integration_test.cc +++ b/test/integration/ads_integration_test.cc @@ -46,10 +46,15 @@ const std::string config = R"EOF( name: dummy_cluster connect_timeout: { seconds: 5 } type: STATIC - hosts: - socket_address: - address: 127.0.0.1 - port_value: 0 + load_assignment: + cluster_name: dummy_cluster + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 0 lb_policy: ROUND_ROBIN http2_protocol_options: {} admin: diff --git a/test/integration/eds_integration_test.cc b/test/integration/eds_integration_test.cc index 38c2b63b50114..2174fdffaacd3 100644 --- a/test/integration/eds_integration_test.cc +++ b/test/integration/eds_integration_test.cc @@ -46,7 +46,7 @@ class EdsIntegrationTest : public HttpIntegrationTest, config_helper_.addConfigModifier([this](envoy::config::bootstrap::v2::Bootstrap& bootstrap) { // Switch predefined cluster_0 to EDS filesystem sourcing. auto* cluster_0 = bootstrap.mutable_static_resources()->mutable_clusters(0); - cluster_0->mutable_hosts()->Clear(); + cluster_0->mutable_load_assignment()->clear_endpoints(); cluster_0->set_type(envoy::api::v2::Cluster::EDS); auto* eds_cluster_config = cluster_0->mutable_eds_cluster_config(); eds_cluster_config->mutable_eds_config()->set_path(eds_helper_.eds_path()); diff --git a/test/integration/hds_integration_test.cc b/test/integration/hds_integration_test.cc index b9b14be973f8c..99d7c98c9c406 100644 --- a/test/integration/hds_integration_test.cc +++ b/test/integration/hds_integration_test.cc @@ -50,7 +50,7 @@ class HdsIntegrationTest : public HttpIntegrationTest, hds_cluster->set_name("hds_cluster"); hds_cluster->mutable_http2_protocol_options(); auto* cluster_0 = bootstrap.mutable_static_resources()->mutable_clusters(0); - cluster_0->mutable_hosts()->Clear(); + cluster_0->mutable_load_assignment()->mutable_endpoints()->Clear(); }); HttpIntegrationTest::initialize(); diff --git a/test/integration/header_integration_test.cc b/test/integration/header_integration_test.cc index 1ebd4fa1c43ab..0d0c329f39563 100644 --- a/test/integration/header_integration_test.cc +++ b/test/integration/header_integration_test.cc @@ -218,10 +218,15 @@ class HeaderIntegrationTest name: unused-cluster type: STATIC lb_policy: ROUND_ROBIN - hosts: - - socket_address: - address: {} - port_value: 0 + load_assignment: + cluster_name: unused-cluster + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: {} + port_value: 0 )EOF", Network::Test::getLoopbackAddressString(version_)))); @@ -233,10 +238,15 @@ class HeaderIntegrationTest lb_policy: ROUND_ROBIN http2_protocol_options: {{}} connect_timeout: 5s - hosts: - - socket_address: - address: {} - port_value: 0 + load_assignment: + cluster_name: eds-cluster + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: {} + port_value: 0 )EOF", Network::Test::getLoopbackAddressString(version_)))); }); diff --git a/test/integration/http2_integration_test.cc b/test/integration/http2_integration_test.cc index 3c4dd561b407b..75c7d0395ba70 100644 --- a/test/integration/http2_integration_test.cc +++ b/test/integration/http2_integration_test.cc @@ -454,10 +454,15 @@ TEST_P(Http2IntegrationTest, DelayedCloseDisabled) { Http2RingHashIntegrationTest::Http2RingHashIntegrationTest() { config_helper_.addConfigModifier([&](envoy::config::bootstrap::v2::Bootstrap& bootstrap) -> void { auto* cluster = bootstrap.mutable_static_resources()->mutable_clusters(0); - cluster->clear_hosts(); cluster->set_lb_policy(envoy::api::v2::Cluster_LbPolicy_RING_HASH); - for (int i = 0; i < num_upstreams_; i++) { - auto* socket = cluster->add_hosts()->mutable_socket_address(); + auto* load_assignment = cluster->mutable_load_assignment(); + auto* locality_lb_endpoints = load_assignment->mutable_endpoints(0); + locality_lb_endpoints->clear_lb_endpoints(); + for (int i = 0; i < num_upstreams_; ++i) { + auto* socket = locality_lb_endpoints->add_lb_endpoints() + ->mutable_endpoint() + ->mutable_address() + ->mutable_socket_address(); socket->set_address(Network::Test::getLoopbackAddressString(version_)); } }); diff --git a/test/integration/http_integration.cc b/test/integration/http_integration.cc index b943ebda921dd..b5664a5f6c3a4 100644 --- a/test/integration/http_integration.cc +++ b/test/integration/http_integration.cc @@ -858,22 +858,22 @@ void HttpIntegrationTest::testRetryPriority() { auto cluster = bootstrap.mutable_static_resources()->mutable_clusters(0); auto load_assignment = cluster->mutable_load_assignment(); load_assignment->set_cluster_name(cluster->name()); - const auto& host_address = cluster->hosts(0).socket_address().address(); + + // Add another endpoint to simulate multiple priorities. + auto locality = load_assignment->add_endpoints(); + locality->MergeFrom(load_assignment->endpoints(0)); for (int i = 0; i < 2; ++i) { - auto locality = load_assignment->add_endpoints(); + auto locality = load_assignment->mutable_endpoints(i); locality->set_priority(i); locality->mutable_locality()->set_region("region"); locality->mutable_locality()->set_zone("zone"); locality->mutable_locality()->set_sub_zone("sub_zone" + std::to_string(i)); - auto lb_endpoint = locality->add_lb_endpoints(); - lb_endpoint->mutable_endpoint()->mutable_address()->mutable_socket_address()->set_address( - host_address); + + auto lb_endpoint = locality->mutable_lb_endpoints(0); lb_endpoint->mutable_endpoint()->mutable_address()->mutable_socket_address()->set_port_value( 0); } - - cluster->clear_hosts(); }); fake_upstreams_count_ = 2; @@ -931,8 +931,15 @@ void HttpIntegrationTest::testRetryHostPredicateFilter() { // We want to work with a cluster with two hosts. config_helper_.addConfigModifier([](envoy::config::bootstrap::v2::Bootstrap& bootstrap) { - auto* new_host = bootstrap.mutable_static_resources()->mutable_clusters(0)->add_hosts(); - new_host->MergeFrom(bootstrap.static_resources().clusters(0).hosts(0)); + // Add a new endpoint. + auto* new_lb_endpoint = bootstrap.mutable_static_resources() + ->mutable_clusters(0) + ->mutable_load_assignment() + ->mutable_endpoints(0) + ->add_lb_endpoints(); + + new_lb_endpoint->MergeFrom( + bootstrap.static_resources().clusters(0).load_assignment().endpoints(0).lb_endpoints(0)); }); fake_upstreams_count_ = 2; initialize(); diff --git a/test/integration/load_stats_integration_test.cc b/test/integration/load_stats_integration_test.cc index 949dd8a96fdda..3930573a496cc 100644 --- a/test/integration/load_stats_integration_test.cc +++ b/test/integration/load_stats_integration_test.cc @@ -123,7 +123,7 @@ class LoadStatsIntegrationTest : public HttpIntegrationTest, locality->set_sub_zone(sub_zone_); // Switch predefined cluster_0 to EDS filesystem sourcing. auto* cluster_0 = bootstrap.mutable_static_resources()->mutable_clusters(0); - cluster_0->mutable_hosts()->Clear(); + cluster_0->mutable_load_assignment()->clear_endpoints(); cluster_0->set_type(envoy::api::v2::Cluster::EDS); auto* eds_cluster_config = cluster_0->mutable_eds_cluster_config(); eds_cluster_config->mutable_eds_config()->set_path(eds_helper_.eds_path()); diff --git a/test/integration/uds_integration_test.h b/test/integration/uds_integration_test.h index 85891bd18d98d..c79c33a11ebac 100644 --- a/test/integration/uds_integration_test.h +++ b/test/integration/uds_integration_test.h @@ -32,10 +32,17 @@ class UdsUpstreamIntegrationTest auto* static_resources = bootstrap.mutable_static_resources(); for (int i = 0; i < static_resources->clusters_size(); ++i) { auto* cluster = static_resources->mutable_clusters(i); - for (int j = 0; j < cluster->hosts_size(); ++j) { - cluster->mutable_hosts(j)->clear_socket_address(); - cluster->mutable_hosts(j)->mutable_pipe()->set_path( - TestEnvironment::unixDomainSocketPath("udstest.1.sock", abstract_namespace_)); + auto* load_assignment = cluster->mutable_load_assignment(); + for (int j = 0; j < load_assignment->endpoints_size(); ++j) { + auto* locality_lb_endpoint = load_assignment->mutable_endpoints(j); + for (int k = 0; k < locality_lb_endpoint->lb_endpoints_size(); ++k) { + auto* lb_endpoint = locality_lb_endpoint->mutable_lb_endpoints(k); + // TODO(dio): Make lb_endpoint's endpoint and address non-nullable. + auto* address = lb_endpoint->mutable_endpoint()->mutable_address(); + address->clear_socket_address(); + address->mutable_pipe()->set_path( + TestEnvironment::unixDomainSocketPath("udstest.1.sock", abstract_namespace_)); + } } } }); diff --git a/test/server/server_fuzz_test.cc b/test/server/server_fuzz_test.cc index 7b6879d8d2128..bdbac514da033 100644 --- a/test/server/server_fuzz_test.cc +++ b/test/server/server_fuzz_test.cc @@ -44,8 +44,10 @@ makeHermeticPathsAndPorts(Fuzz::PerTestEnvironment& test_env, } } for (auto& cluster : *output.mutable_static_resources()->mutable_clusters()) { - for (auto& host : *cluster.mutable_hosts()) { - makePortHermetic(test_env, host); + for (auto& locality_lb : *cluster.mutable_load_assignment()->mutable_endpoints()) { + for (auto& lb_endpoint : *locality_lb.mutable_lb_endpoints()) { + makePortHermetic(test_env, *lb_endpoint.mutable_endpoint()->mutable_address()); + } } } return output;