Skip to content

Commit

Permalink
LBASA-3620: add network_stack field to load balancers model (#775)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvasilevsky authored Jan 22, 2025
1 parent 19442a2 commit 7bf5aa4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
7 changes: 7 additions & 0 deletions load_balancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const (
// Load Balancer network types
LoadBalancerNetworkTypeExternal = "EXTERNAL"
LoadBalancerNetworkTypeInternal = "INTERNAL"

// Load Balancer network_stack types
LoadBalancerNetworkStackIPv4 = "IPV4"
LoadBalancerNetworkStackDualstack = "DUALSTACK"
)

// LoadBalancersService is an interface for managing load balancers with the DigitalOcean API.
Expand Down Expand Up @@ -74,6 +78,7 @@ type LoadBalancer struct {
GLBSettings *GLBSettings `json:"glb_settings,omitempty"`
TargetLoadBalancerIDs []string `json:"target_load_balancer_ids,omitempty"`
Network string `json:"network,omitempty"`
NetworkStack string `json:"network_stack,omitempty"`
}

// String creates a human-readable description of a LoadBalancer.
Expand Down Expand Up @@ -108,6 +113,7 @@ func (l LoadBalancer) AsRequest() *LoadBalancerRequest {
HTTPIdleTimeoutSeconds: l.HTTPIdleTimeoutSeconds,
TargetLoadBalancerIDs: append([]string(nil), l.TargetLoadBalancerIDs...),
Network: l.Network,
NetworkStack: l.NetworkStack,
}

if l.DisableLetsEncryptDNSRecords != nil {
Expand Down Expand Up @@ -247,6 +253,7 @@ type LoadBalancerRequest struct {
GLBSettings *GLBSettings `json:"glb_settings,omitempty"`
TargetLoadBalancerIDs []string `json:"target_load_balancer_ids,omitempty"`
Network string `json:"network,omitempty"`
NetworkStack string `json:"network_stack,omitempty"`
}

// String creates a human-readable description of a LoadBalancerRequest.
Expand Down
21 changes: 13 additions & 8 deletions load_balancers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ var lbCreateJSONResponse = `
"8268a81c-fcf5-423e-a337-bbfe95817f24",
"8268a81c-fcf6-423e-a337-bbfe95817f24"
],
"network": "INTERNAL"
"network": "INTERNAL",
"network_stack": "IPV4"
}
}
`
Expand All @@ -234,6 +235,7 @@ var lbGetJSONResponse = `
"name": "example-lb-01",
"ip": "46.214.185.203",
"ipv6": "fd53:616d:6d60::d2c:b001",
"network_stack": "DUALSTACK",
"algorithm": "round_robin",
"status": "active",
"created_at": "2016-12-15T14:16:36Z",
Expand Down Expand Up @@ -437,13 +439,14 @@ func TestLoadBalancers_Get(t *testing.T) {
expectedTimeout := uint64(60)

expected := &LoadBalancer{
ID: "37e6be88-01ec-4ec7-9bc6-a514d4719057",
Name: "example-lb-01",
IP: "46.214.185.203",
IPv6: "fd53:616d:6d60::d2c:b001",
Algorithm: "round_robin",
Status: "active",
Created: "2016-12-15T14:16:36Z",
ID: "37e6be88-01ec-4ec7-9bc6-a514d4719057",
Name: "example-lb-01",
IP: "46.214.185.203",
IPv6: "fd53:616d:6d60::d2c:b001",
NetworkStack: LoadBalancerNetworkStackDualstack,
Algorithm: "round_robin",
Status: "active",
Created: "2016-12-15T14:16:36Z",
ForwardingRules: []ForwardingRule{
{
EntryProtocol: "https",
Expand Down Expand Up @@ -555,6 +558,7 @@ func TestLoadBalancers_Create(t *testing.T) {
},
TargetLoadBalancerIDs: []string{"8268a81c-fcf5-423e-a337-bbfe95817f24", "8268a81c-fcf6-423e-a337-bbfe95817f24"},
Network: LoadBalancerNetworkTypeInternal,
NetworkStack: LoadBalancerNetworkStackIPv4,
}

path := "/v2/load_balancers"
Expand Down Expand Up @@ -643,6 +647,7 @@ func TestLoadBalancers_Create(t *testing.T) {
},
TargetLoadBalancerIDs: []string{"8268a81c-fcf5-423e-a337-bbfe95817f24", "8268a81c-fcf6-423e-a337-bbfe95817f24"},
Network: LoadBalancerNetworkTypeInternal,
NetworkStack: LoadBalancerNetworkStackIPv4,
}

disableLetsEncryptDNSRecords := true
Expand Down

0 comments on commit 7bf5aa4

Please sign in to comment.