-
Notifications
You must be signed in to change notification settings - Fork 3
/
edsyaml.go
47 lines (42 loc) · 1.49 KB
/
edsyaml.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
package xds
import (
corev3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
)
type EDSConfig struct {
ClusterName string `yaml:"name" validate:"required"`
BalancingPolicy string `yaml:"balancing-policy" validate:"required"`
Instances []EDSInstanceConfig `yaml:"instances" validate:"required"`
}
type EDSInstanceConfig struct {
InstanceName string `yaml:"instance-name" validate:"required"`
IP string `yaml:"ip" validate:"required,ip"`
Port uint32 `yaml:"port" validate:"required,gte=1,lte=65535"`
Region string `yaml:"region" validate:"required"`
Zone string `yaml:"zone" validate:"zone"`
Protocol string `yaml:"protocol" validate:"required"`
Weight uint32 `yaml:"weight"`
}
func (c EDSInstanceConfig) Address() *corev3.Address {
switch c.Protocol {
case "tcp":
return c.addr(corev3.SocketAddress_TCP)
case "udp":
return c.addr(corev3.SocketAddress_UDP)
default:
return c.addr(corev3.SocketAddress_TCP)
}
}
func (c EDSInstanceConfig) addr(protocol corev3.SocketAddress_Protocol) *corev3.Address {
return &corev3.Address{
Address: &corev3.Address_SocketAddress{
SocketAddress: &corev3.SocketAddress{
//ResolverName: "STRICT_DNS", // if hostname is included in the IP specification, use DNS.
Protocol: protocol,
Address: c.IP,
PortSpecifier: &corev3.SocketAddress_PortValue{
PortValue: c.Port,
},
},
},
}
}