-
Notifications
You must be signed in to change notification settings - Fork 109
/
virtualgateway.go
91 lines (79 loc) · 2.51 KB
/
virtualgateway.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package manifest
import (
appmesh "github.com/aws/aws-app-mesh-controller-for-k8s/apis/appmesh/v1beta2"
"github.com/aws/aws-sdk-go/aws"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type VGBuilder struct {
Namespace string
}
func (b *VGBuilder) BuildVirtualGateway(instanceName string, listeners []appmesh.VirtualGatewayListener, nsSelector map[string]string) *appmesh.VirtualGateway {
vgName := b.buildServiceName(instanceName)
vg := &appmesh.VirtualGateway{
ObjectMeta: metav1.ObjectMeta{
Namespace: b.Namespace,
Name: vgName,
},
Spec: appmesh.VirtualGatewaySpec{
NamespaceSelector: &metav1.LabelSelector{
MatchLabels: nsSelector,
},
Listeners: listeners,
Logging: &appmesh.VirtualGatewayLogging{
AccessLog: &appmesh.VirtualGatewayAccessLog{
File: &appmesh.VirtualGatewayFileAccessLog{
Path: "/",
},
},
},
MeshRef: nil,
},
}
return vg
}
func (b *VGBuilder) BuildVGListener(protocol appmesh.VirtualGatewayPortProtocol, port appmesh.PortNumber, healthCheckPath string) appmesh.VirtualGatewayListener {
return appmesh.VirtualGatewayListener{
PortMapping: appmesh.VirtualGatewayPortMapping{
Port: port,
Protocol: protocol,
},
HealthCheck: b.BuildHealthCheckPolicy(healthCheckPath, protocol, port),
}
}
func (b *VGBuilder) BuildListenerWithConnectionPools(protocol appmesh.VirtualGatewayPortProtocol, port appmesh.PortNumber, http *appmesh.HTTPConnectionPool,
http2 *appmesh.HTTP2ConnectionPool, grpc *appmesh.GRPCConnectionPool) appmesh.VirtualGatewayListener {
vgConnectionPool := &appmesh.VirtualGatewayConnectionPool{}
if http != nil {
vgConnectionPool.HTTP = http
}
if http2 != nil {
vgConnectionPool.HTTP2 = http2
}
if grpc != nil {
vgConnectionPool.GRPC = grpc
}
return appmesh.VirtualGatewayListener{
PortMapping: appmesh.VirtualGatewayPortMapping{
Port: port,
Protocol: protocol,
},
ConnectionPool: vgConnectionPool,
}
}
func (b *VGBuilder) BuildHealthCheckPolicy(path string, protocol appmesh.VirtualGatewayPortProtocol, port appmesh.PortNumber) *appmesh.VirtualGatewayHealthCheckPolicy {
return &appmesh.VirtualGatewayHealthCheckPolicy{
HealthyThreshold: 3,
IntervalMillis: 6000,
Path: aws.String(path),
Port: &port,
Protocol: protocol,
TimeoutMillis: 3000,
UnhealthyThreshold: 2,
}
}
func (b *VGBuilder) buildName(instanceName string) string {
return instanceName
}
func (b *VGBuilder) buildServiceName(instanceName string) string {
return instanceName
}