Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for NodeBalancers UDP #630

Open
wants to merge 5 commits into
base: proj/nb-udp
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 30 additions & 16 deletions nodebalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,28 @@ import (
type NodeBalancer struct {
// This NodeBalancer's unique ID.
ID int `json:"id"`

// This NodeBalancer's label. These must be unique on your Account.
Label *string `json:"label"`

// The Region where this NodeBalancer is located. NodeBalancers only support backends in the same Region.
Region string `json:"region"`

// This NodeBalancer's hostname, ending with .nodebalancer.linode.com
Hostname *string `json:"hostname"`

// This NodeBalancer's public IPv4 address.
IPv4 *string `json:"ipv4"`

// This NodeBalancer's public IPv6 address.
IPv6 *string `json:"ipv6"`

// Throttle connections per second (0-20). Set to 0 (zero) to disable throttling.
ClientConnThrottle int `json:"client_conn_throttle"`

// ClientUDPSessThrottle TODO.
ClientUDPSessThrottle int `json:"client_udp_sess_throttle"`

// Information about the amount of transfer this NodeBalancer has had so far this month.
Transfer NodeBalancerTransfer `json:"transfer"`

Expand All @@ -46,19 +56,21 @@ type NodeBalancerTransfer struct {

// NodeBalancerCreateOptions are the options permitted for CreateNodeBalancer
type NodeBalancerCreateOptions struct {
Label *string `json:"label,omitempty"`
Region string `json:"region,omitempty"`
ClientConnThrottle *int `json:"client_conn_throttle,omitempty"`
Configs []*NodeBalancerConfigCreateOptions `json:"configs,omitempty"`
Tags []string `json:"tags"`
FirewallID int `json:"firewall_id,omitempty"`
Label *string `json:"label,omitempty"`
Region string `json:"region,omitempty"`
ClientConnThrottle *int `json:"client_conn_throttle,omitempty"`
ClientUDPSessThrottle *int `json:"client_udp_sess_throttle,omitempty"`
Configs []*NodeBalancerConfigCreateOptions `json:"configs,omitempty"`
Tags []string `json:"tags"`
FirewallID int `json:"firewall_id,omitempty"`
}

// NodeBalancerUpdateOptions are the options permitted for UpdateNodeBalancer
type NodeBalancerUpdateOptions struct {
Label *string `json:"label,omitempty"`
ClientConnThrottle *int `json:"client_conn_throttle,omitempty"`
Tags *[]string `json:"tags,omitempty"`
Label *string `json:"label,omitempty"`
ClientConnThrottle *int `json:"client_conn_throttle,omitempty"`
ClientUDPSessThrottle *int `json:"client_udp_sess_throttle,omitempty"`
Tags *[]string `json:"tags,omitempty"`
}

// UnmarshalJSON implements the json.Unmarshaler interface
Expand Down Expand Up @@ -86,19 +98,21 @@ func (i *NodeBalancer) UnmarshalJSON(b []byte) error {
// GetCreateOptions converts a NodeBalancer to NodeBalancerCreateOptions for use in CreateNodeBalancer
func (i NodeBalancer) GetCreateOptions() NodeBalancerCreateOptions {
return NodeBalancerCreateOptions{
Label: i.Label,
Region: i.Region,
ClientConnThrottle: &i.ClientConnThrottle,
Tags: i.Tags,
Label: i.Label,
Region: i.Region,
ClientConnThrottle: &i.ClientConnThrottle,
ClientUDPSessThrottle: &i.ClientUDPSessThrottle,
Tags: i.Tags,
}
}

// GetUpdateOptions converts a NodeBalancer to NodeBalancerUpdateOptions for use in UpdateNodeBalancer
func (i NodeBalancer) GetUpdateOptions() NodeBalancerUpdateOptions {
return NodeBalancerUpdateOptions{
Label: i.Label,
ClientConnThrottle: &i.ClientConnThrottle,
Tags: &i.Tags,
Label: i.Label,
ClientConnThrottle: &i.ClientConnThrottle,
ClientUDPSessThrottle: &i.ClientUDPSessThrottle,
Tags: &i.Tags,
}
}

Expand Down
53 changes: 32 additions & 21 deletions nodebalancer_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,28 @@ import (

// NodeBalancerConfig objects allow a NodeBalancer to accept traffic on a new port
type NodeBalancerConfig struct {
ID int `json:"id"`
Port int `json:"port"`
Protocol ConfigProtocol `json:"protocol"`
ProxyProtocol ConfigProxyProtocol `json:"proxy_protocol"`
Algorithm ConfigAlgorithm `json:"algorithm"`
Stickiness ConfigStickiness `json:"stickiness"`
Check ConfigCheck `json:"check"`
CheckInterval int `json:"check_interval"`
CheckAttempts int `json:"check_attempts"`
CheckPath string `json:"check_path"`
CheckBody string `json:"check_body"`
CheckPassive bool `json:"check_passive"`
CheckTimeout int `json:"check_timeout"`
CipherSuite ConfigCipher `json:"cipher_suite"`
NodeBalancerID int `json:"nodebalancer_id"`
SSLCommonName string `json:"ssl_commonname"`
SSLFingerprint string `json:"ssl_fingerprint"`
SSLCert string `json:"ssl_cert"`
SSLKey string `json:"ssl_key"`
NodesStatus *NodeBalancerNodeStatus `json:"nodes_status"`
ID int `json:"id"`
Port int `json:"port"`
Protocol ConfigProtocol `json:"protocol"`
ProxyProtocol ConfigProxyProtocol `json:"proxy_protocol"`
Algorithm ConfigAlgorithm `json:"algorithm"`
Stickiness ConfigStickiness `json:"stickiness"`
Check ConfigCheck `json:"check"`
CheckInterval int `json:"check_interval"`
CheckAttempts int `json:"check_attempts"`
CheckPath string `json:"check_path"`
CheckBody string `json:"check_body"`
CheckPassive bool `json:"check_passive"`
CheckTimeout int `json:"check_timeout"`
UDPCheckPort int `json:"udp_check_port"`
UDPSessionTimeout int `json:"udp_session_timeout"`
CipherSuite ConfigCipher `json:"cipher_suite"`
NodeBalancerID int `json:"nodebalancer_id"`
SSLCommonName string `json:"ssl_commonname"`
SSLFingerprint string `json:"ssl_fingerprint"`
SSLCert string `json:"ssl_cert"`
SSLKey string `json:"ssl_key"`
NodesStatus *NodeBalancerNodeStatus `json:"nodes_status"`
}

// ConfigAlgorithm constants start with Algorithm and include Linode API NodeBalancer Config Algorithms
Expand All @@ -36,6 +38,7 @@ const (
AlgorithmRoundRobin ConfigAlgorithm = "roundrobin"
AlgorithmLeastConn ConfigAlgorithm = "leastconn"
AlgorithmSource ConfigAlgorithm = "source"
AlgorithmRingHash ConfigAlgorithm = "ring_hash"
)

// ConfigStickiness constants start with Stickiness and include Linode API NodeBalancer Config Stickiness
Expand All @@ -44,8 +47,10 @@ type ConfigStickiness string
// ConfigStickiness constants reflect the node stickiness method for a NodeBalancer Config
const (
StickinessNone ConfigStickiness = "none"
StickinessSession ConfigStickiness = "session"
StickinessTable ConfigStickiness = "table"
StickinessHTTPCookie ConfigStickiness = "http_cookie"
StickinessSourceIP ConfigStickiness = "source_ip"
)

// ConfigCheck constants start with Check and include Linode API NodeBalancer Config Check methods
Expand All @@ -67,12 +72,13 @@ const (
ProtocolHTTP ConfigProtocol = "http"
ProtocolHTTPS ConfigProtocol = "https"
ProtocolTCP ConfigProtocol = "tcp"
ProtocolUDP ConfigProtocol = "udp"
)

// ConfigProxyProtocol constants start with ProxyProtocol and include Linode API NodeBalancer Config proxy protocol versions
type ConfigProxyProtocol string

// ConfigProxyProtocol constatns reflect the proxy protocol version used by a NodeBalancer Config
// ConfigProxyProtocol constants reflect the proxy protocol version used by a NodeBalancer Config
const (
ProxyProtocolNone ConfigProxyProtocol = "none"
ProxyProtocolV1 ConfigProxyProtocol = "v1"
Expand Down Expand Up @@ -108,6 +114,7 @@ type NodeBalancerConfigCreateOptions struct {
CheckBody string `json:"check_body,omitempty"`
CheckPassive *bool `json:"check_passive,omitempty"`
CheckTimeout int `json:"check_timeout,omitempty"`
UDPCheckPort *int `json:"udp_check_port,omitempty"`
CipherSuite ConfigCipher `json:"cipher_suite,omitempty"`
SSLCert string `json:"ssl_cert,omitempty"`
SSLKey string `json:"ssl_key,omitempty"`
Expand All @@ -128,6 +135,7 @@ type NodeBalancerConfigRebuildOptions struct {
CheckBody string `json:"check_body,omitempty"`
CheckPassive *bool `json:"check_passive,omitempty"`
CheckTimeout int `json:"check_timeout,omitempty"`
UDPCheckPort *int `json:"udp_check_port,omitempty"`
CipherSuite ConfigCipher `json:"cipher_suite,omitempty"`
SSLCert string `json:"ssl_cert,omitempty"`
SSLKey string `json:"ssl_key,omitempty"`
Expand Down Expand Up @@ -160,6 +168,7 @@ func (i NodeBalancerConfig) GetCreateOptions() NodeBalancerConfigCreateOptions {
CheckPath: i.CheckPath,
CheckBody: i.CheckBody,
CheckPassive: copyBool(&i.CheckPassive),
UDPCheckPort: &i.UDPCheckPort,
CipherSuite: i.CipherSuite,
SSLCert: i.SSLCert,
SSLKey: i.SSLKey,
Expand All @@ -181,6 +190,7 @@ func (i NodeBalancerConfig) GetUpdateOptions() NodeBalancerConfigUpdateOptions {
CheckBody: i.CheckBody,
CheckPassive: copyBool(&i.CheckPassive),
CheckTimeout: i.CheckTimeout,
UDPCheckPort: copyInt(&i.UDPCheckPort),
CipherSuite: i.CipherSuite,
SSLCert: i.SSLCert,
SSLKey: i.SSLKey,
Expand All @@ -202,6 +212,7 @@ func (i NodeBalancerConfig) GetRebuildOptions() NodeBalancerConfigRebuildOptions
CheckPath: i.CheckPath,
CheckBody: i.CheckBody,
CheckPassive: copyBool(&i.CheckPassive),
UDPCheckPort: copyInt(&i.UDPCheckPort),
CipherSuite: i.CipherSuite,
SSLCert: i.SSLCert,
SSLKey: i.SSLKey,
Expand Down
Loading
Loading