Skip to content

Commit a56f15e

Browse files
komer3Rahul Sharmalgarber-akamai
authored
Nodebalancer Config Changes for VPC integration (#689)
* Adding the funcs for the List VPC and Get VPC for Nodebalancers endpoints * Adding test cases - they don't work until we update some nodebalancer funcs to allow creation of nb with vpc options * IPv6 can sometime be empty so adding omiempty here * add vpcs config during nodebalancer create * update node config as well * add nb vpc test * Adding records for fixtures * add generated fixtures * fix cleanup failures * Update the fixture for nb vpc list and get * fix formatting * Update nodebalancer_config_vpc.go Co-authored-by: Lena Garber <114949949+lgarber-akamai@users.noreply.github.com> * Fix naming * Nodebalancer VPC config support * Add a integration test for testing the rebuild nodebalancer config endpoint * Fixing how region was selected for the new test * Adding disclaimer for letting users know this might not be available to everyone * Remove use of pointers with VPC options * Add some more integration test cases for nodebalancer node config methods * Lint fix * removing omitempty for VPCConfigID --------- Co-authored-by: Rahul Sharma <rahsharm@akamai.com> Co-authored-by: Lena Garber <114949949+lgarber-akamai@users.noreply.github.com>
1 parent c85a73f commit a56f15e

10 files changed

+5714
-13
lines changed

nodebalancer_config_nodes.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type NodeBalancerNode struct {
1414
Mode NodeMode `json:"mode"`
1515
ConfigID int `json:"config_id"`
1616
NodeBalancerID int `json:"nodebalancer_id"`
17+
VPCConfigID int `json:"vpc_config_id"`
1718
}
1819

1920
// NodeMode is the mode a NodeBalancer should use when sending traffic to a NodeBalancer Node
@@ -44,10 +45,11 @@ type NodeBalancerNodeCreateOptions struct {
4445

4546
// NodeBalancerNodeUpdateOptions fields are those accepted by UpdateNodeBalancerNode
4647
type NodeBalancerNodeUpdateOptions struct {
47-
Address string `json:"address,omitempty"`
48-
Label string `json:"label,omitempty"`
49-
Weight int `json:"weight,omitempty"`
50-
Mode NodeMode `json:"mode,omitempty"`
48+
Address string `json:"address,omitempty"`
49+
Label string `json:"label,omitempty"`
50+
Weight int `json:"weight,omitempty"`
51+
Mode NodeMode `json:"mode,omitempty"`
52+
SubnetID int `json:"subnet_id,omitempty"`
5153
}
5254

5355
// GetCreateOptions converts a NodeBalancerNode to NodeBalancerNodeCreateOptions for use in CreateNodeBalancerNode

test/integration/fixtures/TestNodeBalancerConfig_Rebuild_InVPCWithInstance.yaml

Lines changed: 1093 additions & 0 deletions
Large diffs are not rendered by default.

test/integration/fixtures/TestNodeBalancerNode_Create_InVPC.yaml

Lines changed: 1025 additions & 0 deletions
Large diffs are not rendered by default.

test/integration/fixtures/TestNodeBalancerNode_Get_InVPC.yaml

Lines changed: 1089 additions & 0 deletions
Large diffs are not rendered by default.

test/integration/fixtures/TestNodeBalancerNode_List_InVPC.yaml

Lines changed: 1089 additions & 0 deletions
Large diffs are not rendered by default.

test/integration/fixtures/TestNodeBalancerNode_Update_InVPC.yaml

Lines changed: 1088 additions & 0 deletions
Large diffs are not rendered by default.

test/integration/nodebalancer_config_nodes_test.go

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,194 @@ func TestNodeBalancer_Rebuild(t *testing.T) {
157157
}
158158
}
159159

160+
func TestNodeBalancerNode_Create_InVPC(t *testing.T) {
161+
client, nodebalancer, subnet, instanceVPCIP, teardown, err := setupNodeBalancerWithVPCAndInstance(t, "fixtures/TestNodeBalancerNode_Create_InVPC")
162+
defer teardown()
163+
if err != nil {
164+
t.Error(err)
165+
}
166+
167+
config, err := client.CreateNodeBalancerConfig(context.Background(), nodebalancer.ID, TestNodeBalancerConfigCreateOpts)
168+
if err != nil {
169+
t.Errorf("Error creating NodeBalancer Config, got error %v", err)
170+
}
171+
172+
// Create a nodebalancer node in the VPC
173+
node, err := client.CreateNodeBalancerNode(context.Background(), nodebalancer.ID, config.ID, linodego.NodeBalancerNodeCreateOptions{
174+
Address: instanceVPCIP + ":" + testNodePort,
175+
Mode: linodego.ModeAccept,
176+
Weight: 10,
177+
Label: "go-node-test-def",
178+
SubnetID: subnet.ID,
179+
})
180+
if err != nil {
181+
t.Fatalf("Error creating NodeBalancer Node, got error %v", err)
182+
}
183+
184+
// get nodebalancer vpc config - cross check the nodebalancer node VPC config ID
185+
vpcConfigs, err := client.ListNodeBalancerVPCConfigs(context.Background(), nodebalancer.ID, nil)
186+
if err != nil {
187+
t.Errorf("Error listing nodebalancer VPC configs: %s", err)
188+
}
189+
if len(vpcConfigs) != 1 {
190+
t.Errorf("Expected exactly one nodebalancer VPC config, got %d", len(vpcConfigs))
191+
}
192+
if vpcConfigs[0].ID != node.VPCConfigID {
193+
t.Errorf("Expected nodebalancer VPC config ID to be the same as the nodebalancer node VPC config ID, got %d", vpcConfigs[0].ID)
194+
}
195+
}
196+
197+
func TestNodeBalancerNode_List_InVPC(t *testing.T) {
198+
client, nodebalancer, subnet, instanceVPCIP, teardown, err := setupNodeBalancerWithVPCAndInstance(t, "fixtures/TestNodeBalancerNode_List_InVPC")
199+
defer teardown()
200+
if err != nil {
201+
t.Error(err)
202+
}
203+
204+
config, err := client.CreateNodeBalancerConfig(context.Background(), nodebalancer.ID, TestNodeBalancerConfigCreateOpts)
205+
if err != nil {
206+
t.Errorf("Error creating NodeBalancer Config, got error %v", err)
207+
}
208+
209+
node, err := client.CreateNodeBalancerNode(context.Background(), nodebalancer.ID, config.ID, linodego.NodeBalancerNodeCreateOptions{
210+
Address: instanceVPCIP + ":" + testNodePort,
211+
Mode: linodego.ModeAccept,
212+
Weight: 10,
213+
Label: "go-node-test-def",
214+
SubnetID: subnet.ID,
215+
})
216+
if err != nil {
217+
t.Errorf("Error creating NodeBalancer Node, got error %v", err)
218+
}
219+
220+
// Test listing nodebalancer nodes method
221+
nodes, err := client.ListNodeBalancerNodes(context.Background(), nodebalancer.ID, config.ID, nil)
222+
if err != nil {
223+
t.Fatalf("Error listing nodebalancer nodes: %s", err)
224+
}
225+
if len(nodes) != 1 {
226+
t.Errorf("Expected exactly one nodebalancer node, got %d", len(nodes))
227+
}
228+
if nodes[0].Address != instanceVPCIP+":"+testNodePort {
229+
t.Errorf("Expected nodebalancer node address to be the same as the instance VPC IP, got %s", nodes[0].Address)
230+
}
231+
if nodes[0].ID != node.ID {
232+
t.Errorf("Expected nodebalancer node ID to be the same as the nodebalancer node ID, got %d", nodes[0].ID)
233+
}
234+
if nodes[0].VPCConfigID != node.VPCConfigID {
235+
t.Errorf("Expected nodebalancer node VPC config ID to be the same as the nodebalancer node VPC config ID, got %d", nodes[0].VPCConfigID)
236+
}
237+
238+
vpcConfigs, err := client.ListNodeBalancerVPCConfigs(context.Background(), nodebalancer.ID, nil)
239+
if err != nil {
240+
t.Errorf("Error listing nodebalancer VPC configs: %s", err)
241+
}
242+
if len(vpcConfigs) != 1 {
243+
t.Errorf("Expected exactly one nodebalancer VPC config, got %d", len(vpcConfigs))
244+
}
245+
if vpcConfigs[0].ID != nodes[0].VPCConfigID {
246+
t.Errorf("Expected nodebalancer VPC config ID to be the same as the nodebalancer node VPC config ID, got %d", vpcConfigs[0].ID)
247+
}
248+
}
249+
250+
func TestNodeBalancerNode_Update_InVPC(t *testing.T) {
251+
client, nodebalancer, subnet, instanceVPCIP, teardown, err := setupNodeBalancerWithVPCAndInstance(t, "fixtures/TestNodeBalancerNode_Update_InVPC")
252+
defer teardown()
253+
if err != nil {
254+
t.Error(err)
255+
}
256+
257+
config, err := client.CreateNodeBalancerConfig(context.Background(), nodebalancer.ID, TestNodeBalancerConfigCreateOpts)
258+
if err != nil {
259+
t.Errorf("Error creating NodeBalancer Config, got error %v", err)
260+
}
261+
262+
node, err := client.CreateNodeBalancerNode(context.Background(), nodebalancer.ID, config.ID, linodego.NodeBalancerNodeCreateOptions{
263+
Address: instanceVPCIP + ":" + testNodePort,
264+
Mode: linodego.ModeAccept,
265+
Weight: 10,
266+
Label: "not-updated",
267+
SubnetID: subnet.ID,
268+
})
269+
if err != nil {
270+
t.Errorf("Error creating NodeBalancer Node, got error %v", err)
271+
}
272+
273+
updateOpts := linodego.NodeBalancerNodeUpdateOptions{
274+
Address: instanceVPCIP + ":" + testNodePort,
275+
Label: "updated",
276+
SubnetID: subnet.ID,
277+
}
278+
279+
node, err = client.UpdateNodeBalancerNode(context.Background(), nodebalancer.ID, config.ID, node.ID, updateOpts)
280+
if err != nil {
281+
t.Fatalf("Error updating NodeBalancer Node, got error %v", err)
282+
}
283+
if node.Label != "updated" {
284+
t.Errorf("Expected nodebalancer node label to be updated, got %s", node.Label)
285+
}
286+
287+
vpcConfigs, err := client.ListNodeBalancerVPCConfigs(context.Background(), nodebalancer.ID, nil)
288+
if err != nil {
289+
t.Errorf("Error listing nodebalancer VPC configs: %s", err)
290+
}
291+
if len(vpcConfigs) != 1 {
292+
t.Errorf("Expected exactly one nodebalancer VPC config, got %d", len(vpcConfigs))
293+
}
294+
if vpcConfigs[0].ID != node.VPCConfigID {
295+
t.Errorf("Expected nodebalancer VPC config ID to be the same as the nodebalancer node VPC config ID, got %d", vpcConfigs[0].ID)
296+
}
297+
}
298+
299+
func TestNodeBalancerNode_Get_InVPC(t *testing.T) {
300+
client, nodebalancer, subnet, instanceVPCIP, teardown, err := setupNodeBalancerWithVPCAndInstance(t, "fixtures/TestNodeBalancerNode_Get_InVPC")
301+
defer teardown()
302+
if err != nil {
303+
t.Error(err)
304+
}
305+
306+
config, err := client.CreateNodeBalancerConfig(context.Background(), nodebalancer.ID, TestNodeBalancerConfigCreateOpts)
307+
if err != nil {
308+
t.Errorf("Error creating NodeBalancer Config, got error %v", err)
309+
}
310+
311+
node, err := client.CreateNodeBalancerNode(context.Background(), nodebalancer.ID, config.ID, linodego.NodeBalancerNodeCreateOptions{
312+
Address: instanceVPCIP + ":" + testNodePort,
313+
Mode: linodego.ModeAccept,
314+
Weight: 10,
315+
Label: "go-node-test-def",
316+
SubnetID: subnet.ID,
317+
})
318+
if err != nil {
319+
t.Errorf("Error creating NodeBalancer Node, got error %v", err)
320+
}
321+
322+
nodeGot, err := client.GetNodeBalancerNode(context.Background(), nodebalancer.ID, config.ID, node.ID)
323+
if err != nil {
324+
t.Fatalf("Error getting NodeBalancer Node, got error %v", err)
325+
}
326+
if nodeGot.ID != node.ID {
327+
t.Errorf("Expected nodebalancer node ID to be the same as the nodebalancer node ID, got %d", nodeGot.ID)
328+
}
329+
if nodeGot.Address != node.Address {
330+
t.Errorf("Expected nodebalancer node address to be the same as the nodebalancer node address, got %s", nodeGot.Address)
331+
}
332+
if nodeGot.VPCConfigID != node.VPCConfigID {
333+
t.Errorf("Expected nodebalancer node VPC config ID to be the same as the nodebalancer node VPC config ID, got %d", nodeGot.VPCConfigID)
334+
}
335+
336+
vpcConfigs, err := client.ListNodeBalancerVPCConfigs(context.Background(), nodebalancer.ID, nil)
337+
if err != nil {
338+
t.Errorf("Error listing nodebalancer VPC configs: %s", err)
339+
}
340+
if len(vpcConfigs) != 1 {
341+
t.Errorf("Expected exactly one nodebalancer VPC config, got %d", len(vpcConfigs))
342+
}
343+
if vpcConfigs[0].ID != nodeGot.VPCConfigID {
344+
t.Errorf("Expected nodebalancer VPC config ID to be the same as the nodebalancer node VPC config ID, got %d", vpcConfigs[0].ID)
345+
}
346+
}
347+
160348
func setupNodeBalancerNode(t *testing.T, fixturesYaml string) (*linodego.Client, *linodego.NodeBalancer, *linodego.NodeBalancerConfig, *linodego.NodeBalancerNode, func(), error) {
161349
t.Helper()
162350
var fixtureTeardown func()

test/integration/nodebalancer_config_vpc_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
func TestNodeBalancerVPCConfig_List(t *testing.T) {
11-
client, nodebalancer, teardown, err := setupNodeBalancerWithVPC(t, "fixtures/TestNodeBalancerVpcConfig_List")
11+
client, nodebalancer, _, _, teardown, err := setupNodeBalancerWithVPC(t, "fixtures/TestNodeBalancerVpcConfig_List")
1212
if err != nil {
1313
t.Errorf("Error setting up nodebalancer: %s", err)
1414
}
@@ -25,7 +25,7 @@ func TestNodeBalancerVPCConfig_List(t *testing.T) {
2525
}
2626

2727
func TestNodeBalancerVPCConfig_Get(t *testing.T) {
28-
client, nodebalancer, teardown, err := setupNodeBalancerWithVPC(t, "fixtures/TestNodeBalancerVpcConfig_Get")
28+
client, nodebalancer, _, _, teardown, err := setupNodeBalancerWithVPC(t, "fixtures/TestNodeBalancerVpcConfig_Get")
2929
if err != nil {
3030
t.Errorf("Error setting up nodebalancer: %s", err)
3131
}

0 commit comments

Comments
 (0)