|
1 | 1 | package bootstrap
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "fmt" |
4 | 5 | "testing"
|
5 | 6 |
|
6 | 7 | tassert "github.com/stretchr/testify/assert"
|
@@ -104,5 +105,352 @@ static_resources:
|
104 | 105 | explicit_http_config:
|
105 | 106 | http2_protocol_options: {}
|
106 | 107 | `
|
107 |
| - assert.Equal(expectedYAML, string(actualYAML)) |
| 108 | + |
| 109 | + reversedExpectedYAML := `admin: |
| 110 | + access_log: |
| 111 | + - name: envoy.access_loggers.stream |
| 112 | + typed_config: |
| 113 | + '@type': type.googleapis.com/envoy.extensions.access_loggers.stream.v3.StdoutAccessLog |
| 114 | + address: |
| 115 | + socket_address: |
| 116 | + address: 127.0.0.1 |
| 117 | + port_value: 15000 |
| 118 | +dynamic_resources: |
| 119 | + ads_config: |
| 120 | + api_type: GRPC |
| 121 | + grpc_services: |
| 122 | + - envoy_grpc: |
| 123 | + cluster_name: osm-controller |
| 124 | + set_node_on_first_message_only: true |
| 125 | + transport_api_version: V3 |
| 126 | + cds_config: |
| 127 | + ads: {} |
| 128 | + resource_api_version: V3 |
| 129 | + lds_config: |
| 130 | + ads: {} |
| 131 | + resource_api_version: V3 |
| 132 | +node: |
| 133 | + id: foo.bar.co.uk |
| 134 | +static_resources: |
| 135 | + clusters: |
| 136 | + - load_assignment: |
| 137 | + cluster_name: osm-controller |
| 138 | + endpoints: |
| 139 | + - lb_endpoints: |
| 140 | + - endpoint: |
| 141 | + address: |
| 142 | + socket_address: |
| 143 | + address: osm-controller.osm-system.svc.cluster.local |
| 144 | + port_value: 15128 |
| 145 | + name: osm-controller |
| 146 | + transport_socket: |
| 147 | + name: envoy.transport_sockets.tls |
| 148 | + typed_config: |
| 149 | + '@type': type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext |
| 150 | + common_tls_context: |
| 151 | + alpn_protocols: |
| 152 | + - h2 |
| 153 | + tls_certificate_sds_secret_configs: |
| 154 | + - name: tls_sds |
| 155 | + sds_config: |
| 156 | + path: /etc/envoy/tls_certificate_sds_secret.yaml |
| 157 | + tls_params: |
| 158 | + cipher_suites: |
| 159 | + - abc |
| 160 | + - xyz |
| 161 | + ecdh_curves: |
| 162 | + - ABC |
| 163 | + - XYZ |
| 164 | + tls_maximum_protocol_version: TLSv1_2 |
| 165 | + tls_minimum_protocol_version: TLSv1_0 |
| 166 | + validation_context_sds_secret_config: |
| 167 | + name: validation_context_sds |
| 168 | + sds_config: |
| 169 | + path: /etc/envoy/validation_context_sds_secret.yaml |
| 170 | + type: LOGICAL_DNS |
| 171 | + typed_extension_protocol_options: |
| 172 | + envoy.extensions.upstreams.http.v3.HttpProtocolOptions: |
| 173 | + '@type': type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions |
| 174 | + explicit_http_config: |
| 175 | + http2_protocol_options: {} |
| 176 | + - load_assignment: |
| 177 | + cluster_name: my-container-2_liveness_cluster |
| 178 | + endpoints: |
| 179 | + - lb_endpoints: |
| 180 | + - endpoint: |
| 181 | + address: |
| 182 | + socket_address: |
| 183 | + address: 127.0.0.1 |
| 184 | + port_value: 84 |
| 185 | + name: my-container-2_liveness_cluster |
| 186 | + type: STATIC |
| 187 | + - load_assignment: |
| 188 | + cluster_name: my-container-2_readiness_cluster |
| 189 | + endpoints: |
| 190 | + - lb_endpoints: |
| 191 | + - endpoint: |
| 192 | + address: |
| 193 | + socket_address: |
| 194 | + address: 127.0.0.1 |
| 195 | + port_value: 85 |
| 196 | + name: my-container-2_readiness_cluster |
| 197 | + type: STATIC |
| 198 | + - load_assignment: |
| 199 | + cluster_name: my-container-2_startup_cluster |
| 200 | + endpoints: |
| 201 | + - lb_endpoints: |
| 202 | + - endpoint: |
| 203 | + address: |
| 204 | + socket_address: |
| 205 | + address: 127.0.0.1 |
| 206 | + port_value: 86 |
| 207 | + name: my-container-2_startup_cluster |
| 208 | + type: STATIC |
| 209 | + - load_assignment: |
| 210 | + cluster_name: my-container_liveness_cluster |
| 211 | + endpoints: |
| 212 | + - lb_endpoints: |
| 213 | + - endpoint: |
| 214 | + address: |
| 215 | + socket_address: |
| 216 | + address: 127.0.0.1 |
| 217 | + port_value: 81 |
| 218 | + name: my-container_liveness_cluster |
| 219 | + type: STATIC |
| 220 | + - load_assignment: |
| 221 | + cluster_name: my-container_readiness_cluster |
| 222 | + endpoints: |
| 223 | + - lb_endpoints: |
| 224 | + - endpoint: |
| 225 | + address: |
| 226 | + socket_address: |
| 227 | + address: 127.0.0.1 |
| 228 | + port_value: 82 |
| 229 | + name: my-container_readiness_cluster |
| 230 | + type: STATIC |
| 231 | + - load_assignment: |
| 232 | + cluster_name: my-container_startup_cluster |
| 233 | + endpoints: |
| 234 | + - lb_endpoints: |
| 235 | + - endpoint: |
| 236 | + address: |
| 237 | + socket_address: |
| 238 | + address: 127.0.0.1 |
| 239 | + port_value: 83 |
| 240 | + name: my-container_startup_cluster |
| 241 | + type: STATIC |
| 242 | + listeners: |
| 243 | + - address: |
| 244 | + socket_address: |
| 245 | + address: 0.0.0.0 |
| 246 | + port_value: 15901 |
| 247 | + filter_chains: |
| 248 | + - filters: |
| 249 | + - name: envoy.filters.network.http_connection_manager |
| 250 | + typed_config: |
| 251 | + '@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager |
| 252 | + access_log: |
| 253 | + - name: envoy.access_loggers.stream |
| 254 | + typed_config: |
| 255 | + '@type': type.googleapis.com/envoy.extensions.access_loggers.stream.v3.StdoutAccessLog |
| 256 | + log_format: |
| 257 | + json_format: |
| 258 | + authority: '%REQ(:AUTHORITY)%' |
| 259 | + bytes_received: '%BYTES_RECEIVED%' |
| 260 | + bytes_sent: '%BYTES_SENT%' |
| 261 | + duration: '%DURATION%' |
| 262 | + method: '%REQ(:METHOD)%' |
| 263 | + path: '%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%' |
| 264 | + protocol: '%PROTOCOL%' |
| 265 | + request_id: '%REQ(X-REQUEST-ID)%' |
| 266 | + requested_server_name: '%REQUESTED_SERVER_NAME%' |
| 267 | + response_code: '%RESPONSE_CODE%' |
| 268 | + response_code_details: '%RESPONSE_CODE_DETAILS%' |
| 269 | + response_flags: '%RESPONSE_FLAGS%' |
| 270 | + start_time: '%START_TIME%' |
| 271 | + time_to_first_byte: '%RESPONSE_DURATION%' |
| 272 | + upstream_cluster: '%UPSTREAM_CLUSTER%' |
| 273 | + upstream_host: '%UPSTREAM_HOST%' |
| 274 | + upstream_service_time: '%RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)%' |
| 275 | + user_agent: '%REQ(USER-AGENT)%' |
| 276 | + x_forwarded_for: '%REQ(X-FORWARDED-FOR)%' |
| 277 | + http_filters: |
| 278 | + - name: http_router |
| 279 | + typed_config: |
| 280 | + '@type': type.googleapis.com/envoy.extensions.filters.http.router.v3.Router |
| 281 | + route_config: |
| 282 | + name: local_route |
| 283 | + virtual_hosts: |
| 284 | + - domains: |
| 285 | + - '*' |
| 286 | + name: local_service |
| 287 | + routes: |
| 288 | + - match: |
| 289 | + prefix: /osm-liveness-probe/my-container-2 |
| 290 | + route: |
| 291 | + cluster: my-container-2_liveness_cluster |
| 292 | + prefix_rewrite: /liveness |
| 293 | + timeout: 1s |
| 294 | + - match: |
| 295 | + prefix: /osm-liveness-probe/my-container |
| 296 | + route: |
| 297 | + cluster: my-container_liveness_cluster |
| 298 | + prefix_rewrite: /liveness |
| 299 | + timeout: 1s |
| 300 | + stat_prefix: health_probes_http |
| 301 | + listener_filters: |
| 302 | + - name: tls_inspector |
| 303 | + typed_config: |
| 304 | + '@type': type.googleapis.com/envoy.extensions.filters.listener.tls_inspector.v3.TlsInspector |
| 305 | + name: liveness_listener |
| 306 | + - address: |
| 307 | + socket_address: |
| 308 | + address: 0.0.0.0 |
| 309 | + port_value: 15902 |
| 310 | + filter_chains: |
| 311 | + - filter_chain_match: |
| 312 | + transport_protocol: tls |
| 313 | + filters: |
| 314 | + - name: tcp_proxy |
| 315 | + typed_config: |
| 316 | + '@type': type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy |
| 317 | + access_log: |
| 318 | + - name: envoy.access_loggers.stream |
| 319 | + typed_config: |
| 320 | + '@type': type.googleapis.com/envoy.extensions.access_loggers.stream.v3.StdoutAccessLog |
| 321 | + log_format: |
| 322 | + json_format: |
| 323 | + bytes_received: '%BYTES_RECEIVED%' |
| 324 | + bytes_sent: '%BYTES_SENT%' |
| 325 | + duration: '%DURATION%' |
| 326 | + requested_server_name: '%REQUESTED_SERVER_NAME%' |
| 327 | + response_flags: '%RESPONSE_FLAGS%' |
| 328 | + start_time: '%START_TIME%' |
| 329 | + upstream_cluster: '%UPSTREAM_CLUSTER%' |
| 330 | + upstream_host: '%UPSTREAM_HOST%' |
| 331 | + cluster: my-container-2_readiness_cluster |
| 332 | + stat_prefix: health_probes_https |
| 333 | + - filters: |
| 334 | + - name: envoy.filters.network.http_connection_manager |
| 335 | + typed_config: |
| 336 | + '@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager |
| 337 | + access_log: |
| 338 | + - name: envoy.access_loggers.stream |
| 339 | + typed_config: |
| 340 | + '@type': type.googleapis.com/envoy.extensions.access_loggers.stream.v3.StdoutAccessLog |
| 341 | + log_format: |
| 342 | + json_format: |
| 343 | + authority: '%REQ(:AUTHORITY)%' |
| 344 | + bytes_received: '%BYTES_RECEIVED%' |
| 345 | + bytes_sent: '%BYTES_SENT%' |
| 346 | + duration: '%DURATION%' |
| 347 | + method: '%REQ(:METHOD)%' |
| 348 | + path: '%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%' |
| 349 | + protocol: '%PROTOCOL%' |
| 350 | + request_id: '%REQ(X-REQUEST-ID)%' |
| 351 | + requested_server_name: '%REQUESTED_SERVER_NAME%' |
| 352 | + response_code: '%RESPONSE_CODE%' |
| 353 | + response_code_details: '%RESPONSE_CODE_DETAILS%' |
| 354 | + response_flags: '%RESPONSE_FLAGS%' |
| 355 | + start_time: '%START_TIME%' |
| 356 | + time_to_first_byte: '%RESPONSE_DURATION%' |
| 357 | + upstream_cluster: '%UPSTREAM_CLUSTER%' |
| 358 | + upstream_host: '%UPSTREAM_HOST%' |
| 359 | + upstream_service_time: '%RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)%' |
| 360 | + user_agent: '%REQ(USER-AGENT)%' |
| 361 | + x_forwarded_for: '%REQ(X-FORWARDED-FOR)%' |
| 362 | + http_filters: |
| 363 | + - name: http_router |
| 364 | + typed_config: |
| 365 | + '@type': type.googleapis.com/envoy.extensions.filters.http.router.v3.Router |
| 366 | + route_config: |
| 367 | + name: local_route |
| 368 | + virtual_hosts: |
| 369 | + - domains: |
| 370 | + - '*' |
| 371 | + name: local_service |
| 372 | + routes: |
| 373 | + - match: |
| 374 | + prefix: /osm-readiness-probe/my-container |
| 375 | + route: |
| 376 | + cluster: my-container_readiness_cluster |
| 377 | + prefix_rewrite: /readiness |
| 378 | + timeout: 1s |
| 379 | + stat_prefix: health_probes_http |
| 380 | + listener_filters: |
| 381 | + - name: tls_inspector |
| 382 | + typed_config: |
| 383 | + '@type': type.googleapis.com/envoy.extensions.filters.listener.tls_inspector.v3.TlsInspector |
| 384 | + name: readiness_listener |
| 385 | + - address: |
| 386 | + socket_address: |
| 387 | + address: 0.0.0.0 |
| 388 | + port_value: 15903 |
| 389 | + filter_chains: |
| 390 | + - filters: |
| 391 | + - name: envoy.filters.network.http_connection_manager |
| 392 | + typed_config: |
| 393 | + '@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager |
| 394 | + access_log: |
| 395 | + - name: envoy.access_loggers.stream |
| 396 | + typed_config: |
| 397 | + '@type': type.googleapis.com/envoy.extensions.access_loggers.stream.v3.StdoutAccessLog |
| 398 | + log_format: |
| 399 | + json_format: |
| 400 | + authority: '%REQ(:AUTHORITY)%' |
| 401 | + bytes_received: '%BYTES_RECEIVED%' |
| 402 | + bytes_sent: '%BYTES_SENT%' |
| 403 | + duration: '%DURATION%' |
| 404 | + method: '%REQ(:METHOD)%' |
| 405 | + path: '%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%' |
| 406 | + protocol: '%PROTOCOL%' |
| 407 | + request_id: '%REQ(X-REQUEST-ID)%' |
| 408 | + requested_server_name: '%REQUESTED_SERVER_NAME%' |
| 409 | + response_code: '%RESPONSE_CODE%' |
| 410 | + response_code_details: '%RESPONSE_CODE_DETAILS%' |
| 411 | + response_flags: '%RESPONSE_FLAGS%' |
| 412 | + start_time: '%START_TIME%' |
| 413 | + time_to_first_byte: '%RESPONSE_DURATION%' |
| 414 | + upstream_cluster: '%UPSTREAM_CLUSTER%' |
| 415 | + upstream_host: '%UPSTREAM_HOST%' |
| 416 | + upstream_service_time: '%RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)%' |
| 417 | + user_agent: '%REQ(USER-AGENT)%' |
| 418 | + x_forwarded_for: '%REQ(X-FORWARDED-FOR)%' |
| 419 | + http_filters: |
| 420 | + - name: http_router |
| 421 | + typed_config: |
| 422 | + '@type': type.googleapis.com/envoy.extensions.filters.http.router.v3.Router |
| 423 | + route_config: |
| 424 | + name: local_route |
| 425 | + virtual_hosts: |
| 426 | + - domains: |
| 427 | + - '*' |
| 428 | + name: local_service |
| 429 | + routes: |
| 430 | + - match: |
| 431 | + prefix: /osm-startup-probe/my-container-2 |
| 432 | + route: |
| 433 | + cluster: my-container-2_startup_cluster |
| 434 | + prefix_rewrite: /startup |
| 435 | + timeout: 1s |
| 436 | + - match: |
| 437 | + prefix: /osm-startup-probe/my-container |
| 438 | + route: |
| 439 | + cluster: my-container_startup_cluster |
| 440 | + prefix_rewrite: /startup |
| 441 | + timeout: 1s |
| 442 | + stat_prefix: health_probes_http |
| 443 | + listener_filters: |
| 444 | + - name: tls_inspector |
| 445 | + typed_config: |
| 446 | + '@type': type.googleapis.com/envoy.extensions.filters.listener.tls_inspector.v3.TlsInspector |
| 447 | + name: startup_listener |
| 448 | +` |
| 449 | + |
| 450 | + // Because OriginalHealthProbes is a map and not a slice, it's unordered, so we need to use a more complex assertion here |
| 451 | + assert.Conditionf(func() (success bool) { |
| 452 | + return tassert.ObjectsAreEqual(expectedYAML, string(actualYAML)) || tassert.ObjectsAreEqual(reversedExpectedYAML, string(actualYAML)) |
| 453 | + }, fmt.Sprintf("Not equal: \n"+ |
| 454 | + "expected:\n%s\n--------OR----------\n%s\n"+ |
| 455 | + "actual :\n%s\n", expectedYAML, reversedExpectedYAML, actualYAML)) |
108 | 456 | }
|
0 commit comments