2018-10-03 19:37:53 +00:00
package envoy
2019-04-29 16:27:57 +00:00
// BootstrapTplArgs is the set of arguments that may be interpolated into the
// Envoy bootstrap template.
type BootstrapTplArgs struct {
2020-04-07 20:33:22 +00:00
GRPC
2019-04-29 16:27:57 +00:00
// ProxyCluster is the cluster name for the the Envoy `node` specification and
// is typically the same as the ProxyID.
ProxyCluster string
// ProxyID is the ID of the proxy service instance as registered with the
// local Consul agent. This must be used as the Envoy `node.id` in order for
// the agent to deliver the correct configuration.
ProxyID string
2022-06-06 16:23:08 +00:00
// NodeName is the name of the node on which the proxy service instance is registered.
NodeName string
2020-11-16 23:37:19 +00:00
// ProxySourceService is the Consul service name to report for this proxy
// instance's source service label. For sidecars it should be the
// Proxy.DestinationServiceName. For gateways and similar it is the service
// name of the proxy service itself.
ProxySourceService string
2019-12-13 16:44:48 +00:00
// AgentCAPEM is the CA to use to verify the local agent gRPC service if
2019-04-29 16:27:57 +00:00
// TLS is enabled.
2020-01-10 14:57:54 +00:00
AgentCAPEM string
2019-04-29 16:27:57 +00:00
2023-01-09 20:16:00 +00:00
// AdminAccessLogConfig string representations of Envoy access log
// configurations for the admin interface.
AdminAccessLogConfig [ ] string
2019-06-07 09:26:43 +00:00
// AdminAccessLogPath The path to write the access log for the
// administration server. If no access log is desired specify
2023-01-09 20:16:00 +00:00
// "/dev/null". By default it will use "/dev/null". Will be overriden by
// AdminAccessLogConfig.
// DEPRECATED: use AdminAccessLogConfig
2019-06-07 09:26:43 +00:00
AdminAccessLogPath string
2019-04-29 16:27:57 +00:00
// AdminBindAddress is the address the Envoy admin server should bind to.
AdminBindAddress string
// AdminBindPort is the port the Envoy admin server should bind to.
AdminBindPort string
// LocalAgentClusterName is the name reserved for the local Consul agent gRPC
// service and is expected to be used for that purpose.
2018-10-03 19:37:53 +00:00
LocalAgentClusterName string
2019-04-29 16:27:57 +00:00
// Token is the Consul ACL token provided which is required to make gRPC
// discovery requests. If non-empty, this must be configured as the gRPC
// service "initial_metadata" with the key "x-consul-token" in order to
// authorize the discovery streaming RPCs.
Token string
// StaticClustersJSON is JSON string, each is expected to be a valid Cluster
// definition. They are appended to the "static_resources.clusters" list. Note
// that cluster names should be chosen in such a way that they won't collide
// with service names since we use plain service names as cluster names in xDS
// to make metrics population simpler and cluster names mush be unique. See
// https://www.envoyproxy.io/docs/envoy/v1.9.0/api-v2/api/v2/cds.proto.
StaticClustersJSON string
// StaticListenersJSON is a JSON string containing zero or more Listener
// definitions. They are appended to the "static_resources.listeners" list. A
// single listener should be given as a plain object, if more than one is to
// be added, they should be separated by a comma suitable for direct injection
// into a JSON array.
// See https://www.envoyproxy.io/docs/envoy/v1.9.0/api-v2/api/v2/lds.proto.
StaticListenersJSON string
// StatsSinksJSON is a JSON string containing an array in the right format
// to be rendered as the body of the `stats_sinks` field at the top level of
// the bootstrap config. It's format may vary based on Envoy version used. See
// https://www.envoyproxy.io/docs/envoy/v1.9.0/api-v2/config/metrics/v2/stats.proto#config-metrics-v2-statssink.
StatsSinksJSON string
// StatsConfigJSON is a JSON string containing an object in the right format
// to be rendered as the body of the `stats_config` field at the top level of
// the bootstrap config. It's format may vary based on Envoy version used. See
// https://www.envoyproxy.io/docs/envoy/v1.9.0/api-v2/config/metrics/v2/stats.proto#envoy-api-msg-config-metrics-v2-statsconfig.
StatsConfigJSON string
2022-06-17 00:18:37 +00:00
// StaticSecretsJSON is a JSON string containing zero or more Secret definitions.
// See https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/transport_sockets/tls/v3/secret.proto#envoy-v3-api-msg-extensions-transport-sockets-tls-v3-secret
StaticSecretsJSON string
2019-04-29 16:27:57 +00:00
// StatsFlushInterval is the time duration between Envoy stats flushes. It is
// in proto3 "duration" string format for example "1.12s" See
// https://developers.google.com/protocol-buffers/docs/proto3#json and
// https://www.envoyproxy.io/docs/envoy/v1.9.0/api-v2/config/bootstrap/v2/bootstrap.proto#bootstrap
StatsFlushInterval string
// TracingConfigJSON is a JSON string containing an object in the right format
// to be rendered as the body of the `tracing` field at the top level of
// the bootstrap config. It's format may vary based on Envoy version used.
// See https://www.envoyproxy.io/docs/envoy/v1.9.0/api-v2/config/trace/v2/trace.proto.
TracingConfigJSON string
2020-01-24 15:04:58 +00:00
2020-11-16 23:37:19 +00:00
// Namespace is the Consul Enterprise Namespace of the proxy service instance
// as registered with the Consul agent.
2020-01-24 15:04:58 +00:00
Namespace string
2020-02-10 19:53:04 +00:00
2021-09-15 01:37:11 +00:00
// Partition is the Consul Enterprise Partition of the proxy service instance
// as registered with the Consul agent.
Partition string
2020-11-16 23:37:19 +00:00
// Datacenter is the datacenter where the proxy service instance is registered.
Datacenter string
2021-03-04 22:15:47 +00:00
// PrometheusBackendPort will configure a "prometheus_backend" cluster which
// envoy_prometheus_bind_addr will point to.
PrometheusBackendPort string
// PrometheusScrapePath will configure the path where metrics are exposed on
// the envoy_prometheus_bind_addr listener.
PrometheusScrapePath string
2022-06-17 00:18:37 +00:00
2022-10-19 19:44:19 +00:00
// PrometheusCAFile is the path to a CA file for Envoy to use when serving TLS on the Prometheius metrics
// endpoint. Only applicable when envoy_prometheus_bind_addr is set in the proxy config.
PrometheusCAFile string
// PrometheusCAPath is the path to a directory of CA certificates for Envoy to use when serving the Prometheus
// metrics endpoint. Only applicable when envoy_prometheus_bind_addr is set in the proxy config.
PrometheusCAPath string
// PrometheusCertFile is the path to a certificate file for Envoy to use when serving TLS on the Prometheus
// metrics endpoint. Only applicable when envoy_prometheus_bind_addr is set in the proxy config.
2022-06-17 00:18:37 +00:00
PrometheusCertFile string
2022-10-19 19:44:19 +00:00
2022-10-19 19:52:10 +00:00
// PrometheusKeyFile is the path to a private key file Envoy to use when serving TLS on the Prometheus metrics
2022-10-19 19:44:19 +00:00
// endpoint. Only applicable when envoy_prometheus_bind_addr is set in the proxy config.
PrometheusKeyFile string
2018-10-03 19:37:53 +00:00
}
2020-04-07 20:33:22 +00:00
// GRPC settings used in the bootstrap template.
type GRPC struct {
// AgentAddress is the IP address of the local agent where the proxy instance
// is registered.
AgentAddress string
// AgentPort is the gRPC port exposed on the local agent.
AgentPort string
// AgentTLS is true if the local agent gRPC service should be accessed over
// TLS.
AgentTLS bool
// AgentSocket is the path to a Unix Socket for communicating with the
// local agent's gRPC endpoint. Disabled if the empty (the default),
// but overrides AgentAddress and AgentPort if set.
AgentSocket string
}
2021-02-26 22:23:15 +00:00
// bootstrapTemplate sets '"ignore_health_on_host_removal": false' JUST to force this to be detected as a v3 bootstrap
// config.
2018-10-09 09:57:26 +00:00
const bootstrapTemplate = ` {
2018-10-05 20:08:01 +00:00
"admin" : {
2023-01-09 20:16:00 +00:00
{ { - if ( not . AdminAccessLogConfig ) } }
2019-06-07 09:26:43 +00:00
"access_log_path" : "{{ .AdminAccessLogPath }}" ,
2023-01-09 20:16:00 +00:00
{ { - end } }
{ { - if . AdminAccessLogConfig } }
"access_log" : [
{ { - range $ index , $ element := . AdminAccessLogConfig } }
{ { if $ index } } , { { end } }
{ { $ element } }
{ { end } } ] ,
{ { - end } }
2018-10-05 20:08:01 +00:00
"address" : {
"socket_address" : {
"address" : "{{ .AdminBindAddress }}" ,
"port_value" : { { . AdminBindPort } }
}
}
} ,
"node" : {
"cluster" : "{{ .ProxyCluster }}" ,
2020-01-24 15:04:58 +00:00
"id" : "{{ .ProxyID }}" ,
"metadata" : {
2022-06-06 16:23:08 +00:00
{ { - if . NodeName } }
"node_name" : "{{ .NodeName }}" ,
{ { - end } }
2020-02-10 19:53:04 +00:00
"namespace" : "{{if ne .Namespace " "}}{{ .Namespace }}{{else}}default{{end}}" ,
2021-10-12 02:18:56 +00:00
"partition" : "{{if ne .Partition " "}}{{ .Partition }}{{else}}default{{end}}"
2020-01-24 15:04:58 +00:00
}
2018-10-05 20:08:01 +00:00
} ,
2022-06-29 15:29:54 +00:00
"layered_runtime" : {
"layers" : [
{
"name" : "base" ,
"static_layer" : {
"re2.max_program_size.error_level" : 1048576
}
}
]
} ,
2018-10-05 20:08:01 +00:00
"static_resources" : {
"clusters" : [
{
"name" : "{{ .LocalAgentClusterName }}" ,
2021-02-26 22:23:15 +00:00
"ignore_health_on_host_removal" : false ,
2018-10-05 20:08:01 +00:00
"connect_timeout" : "1s" ,
"type" : "STATIC" ,
2018-10-09 09:57:26 +00:00
{ { - if . AgentTLS - } }
2021-02-22 21:00:15 +00:00
"transport_socket" : {
"name" : "tls" ,
"typed_config" : {
2021-02-26 22:23:15 +00:00
"@type" : "type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext" ,
2021-02-22 21:00:15 +00:00
"common_tls_context" : {
"validation_context" : {
"trusted_ca" : {
"inline_string" : "{{ .AgentCAPEM }}"
}
2021-02-26 22:23:15 +00:00
}
}
2018-10-05 20:08:01 +00:00
}
} ,
{ { - end } }
"http2_protocol_options" : { } ,
2021-02-22 21:00:15 +00:00
"loadAssignment" : {
"clusterName" : "{{ .LocalAgentClusterName }}" ,
"endpoints" : [
{
"lbEndpoints" : [
{
"endpoint" : {
"address" : {
{ { - if . AgentSocket - } }
"pipe" : {
"path" : "{{ .AgentSocket }}"
}
{ { - else - } }
"socket_address" : {
"address" : "{{ .AgentAddress }}" ,
"port_value" : { { . AgentPort } }
}
{ { - end - } }
}
}
}
]
2021-02-26 22:23:15 +00:00
}
2021-02-22 21:00:15 +00:00
]
}
2018-10-05 20:08:01 +00:00
}
2019-04-29 16:27:57 +00:00
{ { - if . StaticClustersJSON - } }
,
{ { . StaticClustersJSON } }
{ { - end } }
] { { - if . StaticListenersJSON - } }
,
"listeners" : [
{ { . StaticListenersJSON } }
2018-10-05 20:08:01 +00:00
]
2019-04-29 16:27:57 +00:00
{ { - end } }
2022-06-17 00:18:37 +00:00
{ { - if . StaticSecretsJSON - } }
,
"secrets" : [
{ { . StaticSecretsJSON } }
]
{ { - end } }
2018-10-05 20:08:01 +00:00
} ,
2019-04-29 16:27:57 +00:00
{ { - if . StatsSinksJSON } }
2023-03-10 21:50:30 +00:00
"stats_sinks" : [
{ { . StatsSinksJSON } }
] ,
2019-04-29 16:27:57 +00:00
{ { - end } }
{ { - if . StatsConfigJSON } }
"stats_config" : { { . StatsConfigJSON } } ,
{ { - end } }
{ { - if . StatsFlushInterval } }
"stats_flush_interval" : "{{ .StatsFlushInterval }}" ,
{ { - end } }
{ { - if . TracingConfigJSON } }
"tracing" : { { . TracingConfigJSON } } ,
{ { - end } }
2018-10-05 20:08:01 +00:00
"dynamic_resources" : {
2021-02-26 22:23:15 +00:00
"lds_config" : {
"ads" : { } ,
"resource_api_version" : "V3"
} ,
"cds_config" : {
"ads" : { } ,
"resource_api_version" : "V3"
} ,
2018-10-05 20:08:01 +00:00
"ads_config" : {
2021-04-29 18:54:05 +00:00
"api_type" : "DELTA_GRPC" ,
2021-02-26 22:23:15 +00:00
"transport_api_version" : "V3" ,
2018-10-05 20:08:01 +00:00
"grpc_services" : {
"initial_metadata" : [
{
"key" : "x-consul-token" ,
"value" : "{{ .Token }}"
}
] ,
"envoy_grpc" : {
"cluster_name" : "{{ .LocalAgentClusterName }}"
}
}
}
}
}
2018-10-03 19:37:53 +00:00
`