From 7bf5aa4c605a3912c12de9e6c8503b769f9ccb6e Mon Sep 17 00:00:00 2001 From: Josh Vasilevsky <95491250+jvasilevsky@users.noreply.github.com> Date: Wed, 22 Jan 2025 13:47:15 -0500 Subject: [PATCH] LBASA-3620: add network_stack field to load balancers model (#775) --- load_balancers.go | 7 +++++++ load_balancers_test.go | 21 +++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/load_balancers.go b/load_balancers.go index a12729dd..54bec0c4 100644 --- a/load_balancers.go +++ b/load_balancers.go @@ -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. @@ -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. @@ -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 { @@ -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. diff --git a/load_balancers_test.go b/load_balancers_test.go index f1126ad4..51144d20 100644 --- a/load_balancers_test.go +++ b/load_balancers_test.go @@ -222,7 +222,8 @@ var lbCreateJSONResponse = ` "8268a81c-fcf5-423e-a337-bbfe95817f24", "8268a81c-fcf6-423e-a337-bbfe95817f24" ], - "network": "INTERNAL" + "network": "INTERNAL", + "network_stack": "IPV4" } } ` @@ -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", @@ -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", @@ -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" @@ -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