-
Notifications
You must be signed in to change notification settings - Fork 2
/
clusters.go
68 lines (62 loc) · 2.42 KB
/
clusters.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package templates
import (
"time"
"github.com/3scale-ops/marin3r/pkg/envoy"
saasv1alpha1 "github.com/3scale-ops/saas-operator/api/v1alpha1"
envoy_config_cluster_v3 "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
envoy_config_core_v3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
envoy_config_endpoint_v3 "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3"
envoy_extensions_upstreams_http_v3 "github.com/envoyproxy/go-control-plane/envoy/extensions/upstreams/http/v3"
"google.golang.org/protobuf/types/known/anypb"
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/wrapperspb"
)
func Cluster_v1(name string, opts interface{}) (envoy.Resource, error) {
o := opts.(*saasv1alpha1.Cluster)
cluster := &envoy_config_cluster_v3.Cluster{
Name: name,
ConnectTimeout: durationpb.New(1 * time.Second),
ClusterDiscoveryType: &envoy_config_cluster_v3.Cluster_Type{
Type: envoy_config_cluster_v3.Cluster_STRICT_DNS,
},
DnsLookupFamily: envoy_config_cluster_v3.Cluster_V4_ONLY,
LbPolicy: envoy_config_cluster_v3.Cluster_ROUND_ROBIN,
LoadAssignment: &envoy_config_endpoint_v3.ClusterLoadAssignment{
ClusterName: name,
Endpoints: []*envoy_config_endpoint_v3.LocalityLbEndpoints{
{
LbEndpoints: []*envoy_config_endpoint_v3.LbEndpoint{
{
HostIdentifier: &envoy_config_endpoint_v3.LbEndpoint_Endpoint{
Endpoint: &envoy_config_endpoint_v3.Endpoint{
Address: Address_v1(o.Host, o.Port),
},
},
},
},
},
},
},
}
if *o.IsHttp2 {
any, err := anypb.New(&envoy_extensions_upstreams_http_v3.HttpProtocolOptions{
UpstreamProtocolOptions: &envoy_extensions_upstreams_http_v3.HttpProtocolOptions_ExplicitHttpConfig_{
ExplicitHttpConfig: &envoy_extensions_upstreams_http_v3.HttpProtocolOptions_ExplicitHttpConfig{
ProtocolConfig: &envoy_extensions_upstreams_http_v3.HttpProtocolOptions_ExplicitHttpConfig_Http2ProtocolOptions{
Http2ProtocolOptions: &envoy_config_core_v3.Http2ProtocolOptions{
InitialStreamWindowSize: wrapperspb.UInt32(65536), // 64 KiB
InitialConnectionWindowSize: wrapperspb.UInt32(1048576), // 1 MiB
},
},
},
},
})
if err != nil {
panic(err)
}
cluster.TypedExtensionProtocolOptions = map[string]*anypb.Any{
"envoy.extensions.upstreams.http.v3.HttpProtocolOptions": any,
}
}
return cluster, nil
}