Skip to content

Commit

Permalink
Add support for NodeBalancers UDP (#630)
Browse files Browse the repository at this point in the history
* WIP

* Finish up

* Add integration tests

* Add NB unit test

* Add config unit test

* Replace TODO

* Render fixtures

* Re-render unrelated fixture
  • Loading branch information
lgarber-akamai authored Jan 13, 2025
1 parent 857b24b commit b406ec9
Show file tree
Hide file tree
Showing 30 changed files with 5,741 additions and 4,783 deletions.
1 change: 1 addition & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
golang.org/x/crypto v0.30.0 h1:RwoQn3GkWiMkzlX562cLB7OxWvjH1L8xutO2WoJcRoY=
golang.org/x/crypto v0.30.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
Expand Down
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 throttles UDP sessions per second. Set to 0 (zero) to disable throttling.
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

0 comments on commit b406ec9

Please sign in to comment.