Skip to content

Commit

Permalink
Nodebalancer Config Changes for VPC integration (#689)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored Mar 3, 2025
1 parent c85a73f commit a56f15e
Show file tree
Hide file tree
Showing 10 changed files with 5,714 additions and 13 deletions.
10 changes: 6 additions & 4 deletions nodebalancer_config_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type NodeBalancerNode struct {
Mode NodeMode `json:"mode"`
ConfigID int `json:"config_id"`
NodeBalancerID int `json:"nodebalancer_id"`
VPCConfigID int `json:"vpc_config_id"`
}

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

// NodeBalancerNodeUpdateOptions fields are those accepted by UpdateNodeBalancerNode
type NodeBalancerNodeUpdateOptions struct {
Address string `json:"address,omitempty"`
Label string `json:"label,omitempty"`
Weight int `json:"weight,omitempty"`
Mode NodeMode `json:"mode,omitempty"`
Address string `json:"address,omitempty"`
Label string `json:"label,omitempty"`
Weight int `json:"weight,omitempty"`
Mode NodeMode `json:"mode,omitempty"`
SubnetID int `json:"subnet_id,omitempty"`
}

// GetCreateOptions converts a NodeBalancerNode to NodeBalancerNodeCreateOptions for use in CreateNodeBalancerNode
Expand Down
1,093 changes: 1,093 additions & 0 deletions test/integration/fixtures/TestNodeBalancerConfig_Rebuild_InVPCWithInstance.yaml

Large diffs are not rendered by default.

1,025 changes: 1,025 additions & 0 deletions test/integration/fixtures/TestNodeBalancerNode_Create_InVPC.yaml

Large diffs are not rendered by default.

1,089 changes: 1,089 additions & 0 deletions test/integration/fixtures/TestNodeBalancerNode_Get_InVPC.yaml

Large diffs are not rendered by default.

1,089 changes: 1,089 additions & 0 deletions test/integration/fixtures/TestNodeBalancerNode_List_InVPC.yaml

Large diffs are not rendered by default.

1,088 changes: 1,088 additions & 0 deletions test/integration/fixtures/TestNodeBalancerNode_Update_InVPC.yaml

Large diffs are not rendered by default.

188 changes: 188 additions & 0 deletions test/integration/nodebalancer_config_nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,194 @@ func TestNodeBalancer_Rebuild(t *testing.T) {
}
}

func TestNodeBalancerNode_Create_InVPC(t *testing.T) {
client, nodebalancer, subnet, instanceVPCIP, teardown, err := setupNodeBalancerWithVPCAndInstance(t, "fixtures/TestNodeBalancerNode_Create_InVPC")
defer teardown()
if err != nil {
t.Error(err)
}

config, err := client.CreateNodeBalancerConfig(context.Background(), nodebalancer.ID, TestNodeBalancerConfigCreateOpts)
if err != nil {
t.Errorf("Error creating NodeBalancer Config, got error %v", err)
}

// Create a nodebalancer node in the VPC
node, err := client.CreateNodeBalancerNode(context.Background(), nodebalancer.ID, config.ID, linodego.NodeBalancerNodeCreateOptions{
Address: instanceVPCIP + ":" + testNodePort,
Mode: linodego.ModeAccept,
Weight: 10,
Label: "go-node-test-def",
SubnetID: subnet.ID,
})
if err != nil {
t.Fatalf("Error creating NodeBalancer Node, got error %v", err)
}

// get nodebalancer vpc config - cross check the nodebalancer node VPC config ID
vpcConfigs, err := client.ListNodeBalancerVPCConfigs(context.Background(), nodebalancer.ID, nil)
if err != nil {
t.Errorf("Error listing nodebalancer VPC configs: %s", err)
}
if len(vpcConfigs) != 1 {
t.Errorf("Expected exactly one nodebalancer VPC config, got %d", len(vpcConfigs))
}
if vpcConfigs[0].ID != node.VPCConfigID {
t.Errorf("Expected nodebalancer VPC config ID to be the same as the nodebalancer node VPC config ID, got %d", vpcConfigs[0].ID)
}
}

func TestNodeBalancerNode_List_InVPC(t *testing.T) {
client, nodebalancer, subnet, instanceVPCIP, teardown, err := setupNodeBalancerWithVPCAndInstance(t, "fixtures/TestNodeBalancerNode_List_InVPC")
defer teardown()
if err != nil {
t.Error(err)
}

config, err := client.CreateNodeBalancerConfig(context.Background(), nodebalancer.ID, TestNodeBalancerConfigCreateOpts)
if err != nil {
t.Errorf("Error creating NodeBalancer Config, got error %v", err)
}

node, err := client.CreateNodeBalancerNode(context.Background(), nodebalancer.ID, config.ID, linodego.NodeBalancerNodeCreateOptions{
Address: instanceVPCIP + ":" + testNodePort,
Mode: linodego.ModeAccept,
Weight: 10,
Label: "go-node-test-def",
SubnetID: subnet.ID,
})
if err != nil {
t.Errorf("Error creating NodeBalancer Node, got error %v", err)
}

// Test listing nodebalancer nodes method
nodes, err := client.ListNodeBalancerNodes(context.Background(), nodebalancer.ID, config.ID, nil)
if err != nil {
t.Fatalf("Error listing nodebalancer nodes: %s", err)
}
if len(nodes) != 1 {
t.Errorf("Expected exactly one nodebalancer node, got %d", len(nodes))
}
if nodes[0].Address != instanceVPCIP+":"+testNodePort {
t.Errorf("Expected nodebalancer node address to be the same as the instance VPC IP, got %s", nodes[0].Address)
}
if nodes[0].ID != node.ID {
t.Errorf("Expected nodebalancer node ID to be the same as the nodebalancer node ID, got %d", nodes[0].ID)
}
if nodes[0].VPCConfigID != node.VPCConfigID {
t.Errorf("Expected nodebalancer node VPC config ID to be the same as the nodebalancer node VPC config ID, got %d", nodes[0].VPCConfigID)
}

vpcConfigs, err := client.ListNodeBalancerVPCConfigs(context.Background(), nodebalancer.ID, nil)
if err != nil {
t.Errorf("Error listing nodebalancer VPC configs: %s", err)
}
if len(vpcConfigs) != 1 {
t.Errorf("Expected exactly one nodebalancer VPC config, got %d", len(vpcConfigs))
}
if vpcConfigs[0].ID != nodes[0].VPCConfigID {
t.Errorf("Expected nodebalancer VPC config ID to be the same as the nodebalancer node VPC config ID, got %d", vpcConfigs[0].ID)
}
}

func TestNodeBalancerNode_Update_InVPC(t *testing.T) {
client, nodebalancer, subnet, instanceVPCIP, teardown, err := setupNodeBalancerWithVPCAndInstance(t, "fixtures/TestNodeBalancerNode_Update_InVPC")
defer teardown()
if err != nil {
t.Error(err)
}

config, err := client.CreateNodeBalancerConfig(context.Background(), nodebalancer.ID, TestNodeBalancerConfigCreateOpts)
if err != nil {
t.Errorf("Error creating NodeBalancer Config, got error %v", err)
}

node, err := client.CreateNodeBalancerNode(context.Background(), nodebalancer.ID, config.ID, linodego.NodeBalancerNodeCreateOptions{
Address: instanceVPCIP + ":" + testNodePort,
Mode: linodego.ModeAccept,
Weight: 10,
Label: "not-updated",
SubnetID: subnet.ID,
})
if err != nil {
t.Errorf("Error creating NodeBalancer Node, got error %v", err)
}

updateOpts := linodego.NodeBalancerNodeUpdateOptions{
Address: instanceVPCIP + ":" + testNodePort,
Label: "updated",
SubnetID: subnet.ID,
}

node, err = client.UpdateNodeBalancerNode(context.Background(), nodebalancer.ID, config.ID, node.ID, updateOpts)
if err != nil {
t.Fatalf("Error updating NodeBalancer Node, got error %v", err)
}
if node.Label != "updated" {
t.Errorf("Expected nodebalancer node label to be updated, got %s", node.Label)
}

vpcConfigs, err := client.ListNodeBalancerVPCConfigs(context.Background(), nodebalancer.ID, nil)
if err != nil {
t.Errorf("Error listing nodebalancer VPC configs: %s", err)
}
if len(vpcConfigs) != 1 {
t.Errorf("Expected exactly one nodebalancer VPC config, got %d", len(vpcConfigs))
}
if vpcConfigs[0].ID != node.VPCConfigID {
t.Errorf("Expected nodebalancer VPC config ID to be the same as the nodebalancer node VPC config ID, got %d", vpcConfigs[0].ID)
}
}

func TestNodeBalancerNode_Get_InVPC(t *testing.T) {
client, nodebalancer, subnet, instanceVPCIP, teardown, err := setupNodeBalancerWithVPCAndInstance(t, "fixtures/TestNodeBalancerNode_Get_InVPC")
defer teardown()
if err != nil {
t.Error(err)
}

config, err := client.CreateNodeBalancerConfig(context.Background(), nodebalancer.ID, TestNodeBalancerConfigCreateOpts)
if err != nil {
t.Errorf("Error creating NodeBalancer Config, got error %v", err)
}

node, err := client.CreateNodeBalancerNode(context.Background(), nodebalancer.ID, config.ID, linodego.NodeBalancerNodeCreateOptions{
Address: instanceVPCIP + ":" + testNodePort,
Mode: linodego.ModeAccept,
Weight: 10,
Label: "go-node-test-def",
SubnetID: subnet.ID,
})
if err != nil {
t.Errorf("Error creating NodeBalancer Node, got error %v", err)
}

nodeGot, err := client.GetNodeBalancerNode(context.Background(), nodebalancer.ID, config.ID, node.ID)
if err != nil {
t.Fatalf("Error getting NodeBalancer Node, got error %v", err)
}
if nodeGot.ID != node.ID {
t.Errorf("Expected nodebalancer node ID to be the same as the nodebalancer node ID, got %d", nodeGot.ID)
}
if nodeGot.Address != node.Address {
t.Errorf("Expected nodebalancer node address to be the same as the nodebalancer node address, got %s", nodeGot.Address)
}
if nodeGot.VPCConfigID != node.VPCConfigID {
t.Errorf("Expected nodebalancer node VPC config ID to be the same as the nodebalancer node VPC config ID, got %d", nodeGot.VPCConfigID)
}

vpcConfigs, err := client.ListNodeBalancerVPCConfigs(context.Background(), nodebalancer.ID, nil)
if err != nil {
t.Errorf("Error listing nodebalancer VPC configs: %s", err)
}
if len(vpcConfigs) != 1 {
t.Errorf("Expected exactly one nodebalancer VPC config, got %d", len(vpcConfigs))
}
if vpcConfigs[0].ID != nodeGot.VPCConfigID {
t.Errorf("Expected nodebalancer VPC config ID to be the same as the nodebalancer node VPC config ID, got %d", vpcConfigs[0].ID)
}
}

func setupNodeBalancerNode(t *testing.T, fixturesYaml string) (*linodego.Client, *linodego.NodeBalancer, *linodego.NodeBalancerConfig, *linodego.NodeBalancerNode, func(), error) {
t.Helper()
var fixtureTeardown func()
Expand Down
4 changes: 2 additions & 2 deletions test/integration/nodebalancer_config_vpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

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

func TestNodeBalancerVPCConfig_Get(t *testing.T) {
client, nodebalancer, teardown, err := setupNodeBalancerWithVPC(t, "fixtures/TestNodeBalancerVpcConfig_Get")
client, nodebalancer, _, _, teardown, err := setupNodeBalancerWithVPC(t, "fixtures/TestNodeBalancerVpcConfig_Get")
if err != nil {
t.Errorf("Error setting up nodebalancer: %s", err)
}
Expand Down
Loading

0 comments on commit a56f15e

Please sign in to comment.