Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5cd1e22
Adding the funcs for the List VPC and Get VPC for Nodebalancers endpo…
komer3 Feb 11, 2025
230f4dc
Adding test cases - they don't work until we update some nodebalance…
komer3 Feb 11, 2025
e075874
IPv6 can sometime be empty so adding omiempty here
komer3 Feb 11, 2025
94aa731
add vpcs config during nodebalancer create
Feb 11, 2025
662422b
update node config as well
Feb 11, 2025
c42984f
Merge pull request #1 from rahulait/nb-vpc-updates
komer3 Feb 12, 2025
eff3930
add nb vpc test
Feb 13, 2025
1f6cf9d
Adding records for fixtures
komer3 Feb 13, 2025
66f7ae7
add generated fixtures
Feb 13, 2025
8bab48f
fix cleanup failures
Feb 13, 2025
4729ea7
Update the fixture for nb vpc list and get
komer3 Feb 13, 2025
e46f739
Merge branch 'main' into listnbvpc
komer3 Feb 13, 2025
2d5a46d
fix formatting
Feb 13, 2025
7b94319
Update nodebalancer_config_vpc.go
komer3 Feb 18, 2025
feb92c8
Fix naming
komer3 Feb 18, 2025
96a33af
Nodebalancer VPC config support
komer3 Feb 19, 2025
10b0776
Merge branch 'listnbvpc' into nb-vpc-config
komer3 Feb 19, 2025
34dfcff
Add a integration test for testing the rebuild nodebalancer config en…
komer3 Feb 19, 2025
99be523
Fixing how region was selected for the new test
komer3 Feb 19, 2025
c3fe2ac
Adding disclaimer for letting users know this might not be available …
komer3 Feb 20, 2025
a5cae30
Remove use of pointers with VPC options
komer3 Feb 24, 2025
f4d576f
Merge branch 'main' into listnbvpc
komer3 Feb 24, 2025
d74c3ed
Merge branch 'listnbvpc' into nb-vpc-config
komer3 Feb 25, 2025
deb0ef3
Add some more integration test cases for nodebalancer node config met…
komer3 Feb 25, 2025
bc3cbaf
Merge branch 'main' into nb-vpc-config
komer3 Feb 25, 2025
67e4203
Lint fix
komer3 Feb 25, 2025
f00e52b
removing omitempty for VPCConfigID
komer3 Feb 27, 2025
52b6893
Merge branch 'linode:main' into nb-vpc-config
komer3 Feb 27, 2025
49e357c
Merge branch 'linode:main' into nb-vpc-config
komer3 Mar 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

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