Skip to content

Commit

Permalink
feat: make egctl x translate output struct
Browse files Browse the repository at this point in the history
Signed-off-by: bitliu <bitliu@tencent.com>
  • Loading branch information
Xunzhuo committed Feb 21, 2023
1 parent b97859d commit 42852c1
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 177 deletions.
160 changes: 79 additions & 81 deletions docs/latest/user/egctl.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This subcommand allows users to translate from an input configuration type to an
In the below example, we will translate the Kubernetes resources (including the Gateway API resources) into xDS
resources.

```
```shell
cat <<EOF | egctl x translate --from gateway-api --to xds -f -
apiVersion: gateway.networking.k8s.io/v1beta1
kind: GatewayClass
Expand Down Expand Up @@ -76,98 +76,96 @@ spec:
type: PathPrefix
value: /
EOF
```

```

xDS
```yaml
type: xDS

Key: default-eg
key: default-eg

Bootstrap:
admin:
access_log:
- name: envoy.access_loggers.file
typed_config:
"@type": type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/null
address:
socket_address:
address: 127.0.0.1
port_value: 19000
dynamic_resources:
cds_config:
resource_api_version: V3
api_config_source:
api_type: DELTA_GRPC
transport_api_version: V3
grpc_services:
- envoy_grpc:
cluster_name: xds_cluster
set_node_on_first_message_only: true
lds_config:
resource_api_version: V3
api_config_source:
api_type: DELTA_GRPC
transport_api_version: V3
grpc_services:
- envoy_grpc:
cluster_name: xds_cluster
set_node_on_first_message_only: true
static_resources:
clusters:
- connect_timeout: 1s
load_assignment:
cluster_name: xds_cluster
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: envoy-gateway
port_value: 18000
typed_extension_protocol_options:
"envoy.extensions.upstreams.http.v3.HttpProtocolOptions":
"@type": "type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions"
"explicit_http_config":
"http2_protocol_options": {}
name: xds_cluster
type: STRICT_DNS
transport_socket:
name: envoy.transport_sockets.tls
bootstrap:
admin:
access_log:
- name: envoy.access_loggers.file
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
common_tls_context:
tls_params:
tls_maximum_protocol_version: TLSv1_3
tls_certificate_sds_secret_configs:
- name: xds_certificate
sds_config:
path_config_source:
path: "/sds/xds-certificate.json"
resource_api_version: V3
validation_context_sds_secret_config:
name: xds_trusted_ca
sds_config:
path_config_source:
path: "/sds/xds-trusted-ca.json"
resource_api_version: V3
layered_runtime:
layers:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/null
address:
socket_address:
address: 127.0.0.1
port_value: 19000
dynamic_resources:
cds_config:
api_config_source:
api_type: DELTA_GRPC
grpc_services:
- envoy_grpc:
cluster_name: xds_cluster
set_node_on_first_message_only: true
transport_api_version: V3
resource_api_version: V3
lds_config:
api_config_source:
api_type: DELTA_GRPC
grpc_services:
- envoy_grpc:
cluster_name: xds_cluster
set_node_on_first_message_only: true
transport_api_version: V3
resource_api_version: V3
layered_runtime:
layers:
- name: runtime-0
rtds_layer:
name: runtime-0
rtds_config:
resource_api_version: V3
api_config_source:
transport_api_version: V3
api_type: DELTA_GRPC
grpc_services:
envoy_grpc:
cluster_name: xds_cluster
name: runtime-0
transport_api_version: V3
resource_api_version: V3
static_resources:
clusters:
- connect_timeout: 1s
load_assignment:
cluster_name: xds_cluster
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: envoy-gateway
port_value: 18000
name: xds_cluster
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
'@type': type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
common_tls_context:
tls_certificate_sds_secret_configs:
- name: xds_certificate
sds_config:
path_config_source:
path: /sds/xds-certificate.json
resource_api_version: V3
tls_params:
tls_maximum_protocol_version: TLSv1_3
validation_context_sds_secret_config:
name: xds_trusted_ca
sds_config:
path_config_source:
path: /sds/xds-trusted-ca.json
resource_api_version: V3
type: STRICT_DNS
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
'@type': type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
explicit_http_config:
http2_protocol_options: {}

Listeners:
listeners:
- accessLog:
- filter:
responseFlagFilter:
Expand Down Expand Up @@ -212,7 +210,7 @@ Listeners:
useRemoteAddress: true
name: default-eg-http

Routes:
routes:
- name: default-eg-http
virtualHosts:
- domains:
Expand All @@ -228,7 +226,7 @@ Routes:
route:
cluster: default-backend-rule-0-match-0-www.example.com

Clusters:
clusters:
- commonLbConfig:
localityWeightedLbConfig: {}
connectTimeout: 5s
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"bootstrap":{"admin":{"access_log":[{"name":"envoy.access_loggers.file","typed_config":{"@type":"type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog","path":"/dev/null"}}],"address":{"socket_address":{"address":"127.0.0.1","port_value":19000}}},"dynamic_resources":{"cds_config":{"api_config_source":{"api_type":"DELTA_GRPC","grpc_services":[{"envoy_grpc":{"cluster_name":"xds_cluster"}}],"set_node_on_first_message_only":true,"transport_api_version":"V3"},"resource_api_version":"V3"},"lds_config":{"api_config_source":{"api_type":"DELTA_GRPC","grpc_services":[{"envoy_grpc":{"cluster_name":"xds_cluster"}}],"set_node_on_first_message_only":true,"transport_api_version":"V3"},"resource_api_version":"V3"}},"layered_runtime":{"layers":[{"name":"runtime-0","rtds_layer":{"name":"runtime-0","rtds_config":{"api_config_source":{"api_type":"DELTA_GRPC","grpc_services":{"envoy_grpc":{"cluster_name":"xds_cluster"}},"transport_api_version":"V3"},"resource_api_version":"V3"}}}]},"static_resources":{"clusters":[{"connect_timeout":"1s","load_assignment":{"cluster_name":"xds_cluster","endpoints":[{"lb_endpoints":[{"endpoint":{"address":{"socket_address":{"address":"envoy-gateway","port_value":18000}}}}]}]},"name":"xds_cluster","transport_socket":{"name":"envoy.transport_sockets.tls","typed_config":{"@type":"type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext","common_tls_context":{"tls_certificate_sds_secret_configs":[{"name":"xds_certificate","sds_config":{"path_config_source":{"path":"/sds/xds-certificate.json"},"resource_api_version":"V3"}}],"tls_params":{"tls_maximum_protocol_version":"TLSv1_3"},"validation_context_sds_secret_config":{"name":"xds_trusted_ca","sds_config":{"path_config_source":{"path":"/sds/xds-trusted-ca.json"},"resource_api_version":"V3"}}}}},"type":"STRICT_DNS","typed_extension_protocol_options":{"envoy.extensions.upstreams.http.v3.HttpProtocolOptions":{"@type":"type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions","explicit_http_config":{"http2_protocol_options":{}}}}}]}},"clusters":[{"commonLbConfig":{"localityWeightedLbConfig":{}},"connectTimeout":"5s","dnsLookupFamily":"V4_ONLY","loadAssignment":{"clusterName":"default-backend-rule-0-match-0-www.example.com","endpoints":[{"lbEndpoints":[{"endpoint":{"address":{"socketAddress":{"address":"1.1.1.1","portValue":3000}}},"loadBalancingWeight":1}],"loadBalancingWeight":1,"locality":{}}]},"name":"default-backend-rule-0-match-0-www.example.com","outlierDetection":{},"type":"STATIC"}],"key":"default-eg","listeners":[{"accessLog":[{"filter":{"responseFlagFilter":{"flags":["NR"]}},"name":"envoy.access_loggers.file","typedConfig":{"@type":"type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog","path":"/dev/stdout"}}],"address":{"socketAddress":{"address":"0.0.0.0","portValue":10080}},"defaultFilterChain":{"filters":[{"name":"envoy.filters.network.http_connection_manager","typedConfig":{"@type":"type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager","accessLog":[{"name":"envoy.access_loggers.file","typedConfig":{"@type":"type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog","path":"/dev/stdout"}}],"httpFilters":[{"name":"envoy.filters.http.router","typedConfig":{"@type":"type.googleapis.com/envoy.extensions.filters.http.router.v3.Router"}}],"rds":{"configSource":{"apiConfigSource":{"apiType":"DELTA_GRPC","grpcServices":[{"envoyGrpc":{"clusterName":"xds_cluster"}}],"setNodeOnFirstMessageOnly":true,"transportApiVersion":"V3"},"resourceApiVersion":"V3"},"routeConfigName":"default-eg-http"},"statPrefix":"http","upgradeConfigs":[{"upgradeType":"websocket"}],"useRemoteAddress":true}}]},"name":"default-eg-http"}],"routes":[{"name":"default-eg-http","virtualHosts":[{"domains":["*"],"name":"default-eg-http","routes":[{"match":{"headers":[{"name":":authority","stringMatch":{"exact":"www.example.com"}}],"prefix":"/"},"route":{"cluster":"default-backend-rule-0-match-0-www.example.com"}}]}]}],"type":"xDS"}
156 changes: 78 additions & 78 deletions internal/cmd/egctl/testdata/out/from-gateway-api-to-xds.out
Original file line number Diff line number Diff line change
@@ -1,91 +1,90 @@
type: xDS

xDS
key: default-eg

Key: default-eg

Bootstrap:
admin:
access_log:
- name: envoy.access_loggers.file
typed_config:
"@type": type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/null
address:
socket_address:
address: 127.0.0.1
port_value: 19000
dynamic_resources:
cds_config:
resource_api_version: V3
api_config_source:
api_type: DELTA_GRPC
transport_api_version: V3
grpc_services:
- envoy_grpc:
cluster_name: xds_cluster
set_node_on_first_message_only: true
lds_config:
resource_api_version: V3
api_config_source:
api_type: DELTA_GRPC
transport_api_version: V3
grpc_services:
- envoy_grpc:
cluster_name: xds_cluster
set_node_on_first_message_only: true
static_resources:
clusters:
- connect_timeout: 1s
load_assignment:
cluster_name: xds_cluster
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: envoy-gateway
port_value: 18000
typed_extension_protocol_options:
"envoy.extensions.upstreams.http.v3.HttpProtocolOptions":
"@type": "type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions"
"explicit_http_config":
"http2_protocol_options": {}
name: xds_cluster
type: STRICT_DNS
transport_socket:
name: envoy.transport_sockets.tls
bootstrap:
admin:
access_log:
- name: envoy.access_loggers.file
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
common_tls_context:
tls_params:
tls_maximum_protocol_version: TLSv1_3
tls_certificate_sds_secret_configs:
- name: xds_certificate
sds_config:
path_config_source:
path: "/sds/xds-certificate.json"
resource_api_version: V3
validation_context_sds_secret_config:
name: xds_trusted_ca
sds_config:
path_config_source:
path: "/sds/xds-trusted-ca.json"
resource_api_version: V3
layered_runtime:
layers:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/null
address:
socket_address:
address: 127.0.0.1
port_value: 19000
dynamic_resources:
cds_config:
api_config_source:
api_type: DELTA_GRPC
grpc_services:
- envoy_grpc:
cluster_name: xds_cluster
set_node_on_first_message_only: true
transport_api_version: V3
resource_api_version: V3
lds_config:
api_config_source:
api_type: DELTA_GRPC
grpc_services:
- envoy_grpc:
cluster_name: xds_cluster
set_node_on_first_message_only: true
transport_api_version: V3
resource_api_version: V3
layered_runtime:
layers:
- name: runtime-0
rtds_layer:
name: runtime-0
rtds_config:
resource_api_version: V3
api_config_source:
transport_api_version: V3
api_type: DELTA_GRPC
grpc_services:
envoy_grpc:
cluster_name: xds_cluster
name: runtime-0
transport_api_version: V3
resource_api_version: V3
static_resources:
clusters:
- connect_timeout: 1s
load_assignment:
cluster_name: xds_cluster
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: envoy-gateway
port_value: 18000
name: xds_cluster
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
'@type': type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
common_tls_context:
tls_certificate_sds_secret_configs:
- name: xds_certificate
sds_config:
path_config_source:
path: /sds/xds-certificate.json
resource_api_version: V3
tls_params:
tls_maximum_protocol_version: TLSv1_3
validation_context_sds_secret_config:
name: xds_trusted_ca
sds_config:
path_config_source:
path: /sds/xds-trusted-ca.json
resource_api_version: V3
type: STRICT_DNS
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
'@type': type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
explicit_http_config:
http2_protocol_options: {}

Listeners:
listeners:
- accessLog:
- filter:
responseFlagFilter:
Expand Down Expand Up @@ -130,7 +129,7 @@ Listeners:
useRemoteAddress: true
name: default-eg-http

Routes:
routes:
- name: default-eg-http
virtualHosts:
- domains:
Expand All @@ -146,7 +145,7 @@ Routes:
route:
cluster: default-backend-rule-0-match-0-www.example.com

Clusters:
clusters:
- commonLbConfig:
localityWeightedLbConfig: {}
connectTimeout: 5s
Expand All @@ -166,3 +165,4 @@ Clusters:
name: default-backend-rule-0-match-0-www.example.com
outlierDetection: {}
type: STATIC

Loading

0 comments on commit 42852c1

Please sign in to comment.