/
cluster.go
43 lines (39 loc) · 1.67 KB
/
cluster.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package controlplane
import (
"time"
"github.com/envoyproxy/go-control-plane/envoy/api/v2"
"github.com/envoyproxy/go-control-plane/envoy/api/v2/cluster"
"github.com/envoyproxy/go-control-plane/envoy/api/v2/core"
"github.com/envoyproxy/go-control-plane/envoy/api/v2/endpoint"
)
//StrictDNSLRCluster creates a strict dns cluster with lb policy as least request.
func StrictDNSLRCluster(name, svcAddress string, port uint32, timeoutms int, circuitBreaker *cluster.CircuitBreakers, outlierDetection *cluster.OutlierDetection) *v2.Cluster {
endpointAddress := TCPAddress(svcAddress, port)
return &v2.Cluster{
Name: name,
ConnectTimeout: time.Duration(timeoutms) * time.Millisecond,
ClusterDiscoveryType: &v2.Cluster_Type{Type: v2.Cluster_STRICT_DNS},
DnsLookupFamily: v2.Cluster_V4_ONLY,
LbPolicy: v2.Cluster_LEAST_REQUEST,
LoadAssignment: &v2.ClusterLoadAssignment{
ClusterName: name,
Endpoints: []endpoint.LocalityLbEndpoints{{
LbEndpoints: []endpoint.LbEndpoint{{
HostIdentifier: &endpoint.LbEndpoint_Endpoint{
Endpoint: &endpoint.Endpoint{
Address: &endpointAddress,
},
},
}},
}},
},
CircuitBreakers: circuitBreaker,
OutlierDetection: outlierDetection,
}
}
//StrictDNSLRHttp2Cluster creates an http2 strict dns cluster with lb policy as least request.
func StrictDNSLRHttp2Cluster(name, svcAddress string, port uint32, timeoutms int, circuitBreaker *cluster.CircuitBreakers, outlierDetection *cluster.OutlierDetection) *v2.Cluster {
c := StrictDNSLRCluster(name, svcAddress, port, timeoutms, circuitBreaker, outlierDetection)
c.Http2ProtocolOptions = &core.Http2ProtocolOptions{}
return c
}