Skip to content

Commit

Permalink
Use static local cluster endpoints to hit listeners with rds config
Browse files Browse the repository at this point in the history
  • Loading branch information
ffilippopoulos committed Dec 3, 2024
1 parent 8cea9fd commit b12bcbc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
42 changes: 32 additions & 10 deletions envoy-sidecar/configurer/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,31 @@ type MainListener struct {
}

type RouteDomain struct {
Name string
Domain string
Port int
Cluster string
Domain string
Name string
Port int
}
type TargetListener struct {
Name string
Port int
RouteConfigName string
}

type Cluster struct {
type StaticCluster struct {
Name string
Port int
}

type DynamicCluster struct {
Name string
}

type Clusters struct {
Dynamic []DynamicCluster
Static []StaticCluster
}

type XdsCluster struct {
XdsServerAddress string
XdsServerPort string
Expand Down Expand Up @@ -133,13 +144,14 @@ func makeEnvoyConfig(nodeID, envoySidecarTargets, XdsServerAddress, XdsServerPor
// and routeConfig names. Clusters names should be derived from the above and
// follow the form: service.namespace.port to comply with the xds naming
// limitations and how semaphore-xds configures cluster names.
func extractConfigFromTargets(envoySidecarTargets string) (MainListener, []TargetListener, []Cluster) {
func extractConfigFromTargets(envoySidecarTargets string) (MainListener, []TargetListener, Clusters) {
port := EnvoyMainListenPort
main := MainListener{
Port: port,
}
domains := []RouteDomain{}
listeners := []TargetListener{}
staticClusters := []StaticCluster{}
for _, target := range strings.Split(envoySidecarTargets, ",") {
port++
lName := fmt.Sprintf("listener_%d", port)
Expand All @@ -149,20 +161,30 @@ func extractConfigFromTargets(envoySidecarTargets string) (MainListener, []Targe
RouteConfigName: target,
})
rName := fmt.Sprintf("route_%d", port)
cName := fmt.Sprintf("localhost_%d", port)
domains = append(domains, RouteDomain{
Name: rName,
Domain: target,
Port: port,
Cluster: cName,
Domain: target,
Name: rName,
Port: port,
})
staticClusters = append(staticClusters, StaticCluster{
Name: cName,
Port: port,
})
}
main.Domains = domains

clusters := []Cluster{}
dynamicClusters := []DynamicCluster{}
for _, l := range listeners {
clusterName := strings.Join(strings.Split(l.RouteConfigName, ":"), ".")
clusters = append(clusters, Cluster{
dynamicClusters = append(dynamicClusters, DynamicCluster{
Name: clusterName,
})
}
clusters := Clusters{
Dynamic: dynamicClusters,
Static: staticClusters,
}
return main, listeners, clusters
}
16 changes: 15 additions & 1 deletion envoy-sidecar/configurer/templates/clusters.tmpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- range . }}
{{- range .Dynamic }}
- name: {{ .Name }}
http2_protocol_options: {}
type: EDS
Expand All @@ -12,3 +12,17 @@
- envoy_grpc:
cluster_name: xds_cluster
{{- end }}
{{- range .Static }}
- name: {{ .Name }}
connect_timeout: 5s
type: STATIC
load_assignment:
cluster_name: {{ .Name }}
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: 127.0.0.1
port_value: {{ .Port }}
{{- end }}
6 changes: 4 additions & 2 deletions envoy-sidecar/configurer/templates/main-listener.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
- name: {{ .Name }}
domains: ["{{ .Domain }}"]
routes:
- match: { prefix: "" }
redirect: { port_redirect: {{ .Port }} }
- match:
prefix: ""
route:
cluster: {{ .Cluster }}
{{- end }}
http_filters:
- name: envoy.filters.http.router
Expand Down

0 comments on commit b12bcbc

Please sign in to comment.