Skip to content

Commit 293db7e

Browse files
committed
TPT-3499 Support NodeBalancer lke_cluster field
Signed-off-by: jbilski <jbilski@akamai.com>
1 parent ad25985 commit 293db7e

5 files changed

Lines changed: 101 additions & 15 deletions

File tree

nodebalancer.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ type NodeBalancer struct {
3737
// An array of tags applied to this object. Tags are for organizational purposes only.
3838
Tags []string `json:"tags"`
3939

40+
// This NodeBalancer's related LKE cluster, if any. The value is null if this NodeBalancer is not related to an LKE cluster.
41+
LKECluster *NodeBalancerLKECluster `json:"lke_cluster"`
42+
4043
// An array of locks applied to this NodeBalancer for deletion protection.
4144
// Locks prevent the NodeBalancer or its subresources from being deleted.
4245
// NOTE: Locks can only be used with v4beta.
@@ -91,6 +94,17 @@ type NodeBalancerUpdateOptions struct {
9194
Tags *[]string `json:"tags,omitempty"`
9295
}
9396

97+
type NodeBalancerLKECluster struct {
98+
// The ID of the related LKE cluster.
99+
ID int `json:"id"`
100+
// The label of the related LKE cluster.
101+
Label string `json:"label"`
102+
// The type for LKE clusters.
103+
Type string `json:"type"`
104+
// The URL where you can access the related LKE cluster.
105+
URL string `json:"url"`
106+
}
107+
94108
// NodeBalancerPlanType constants start with NBType and include Linode API NodeBalancer's plan types
95109
type NodeBalancerPlanType string
96110

test/unit/fixtures/nodebalancer_get.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"in": 1000.0,
1212
"out": 1000.0
1313
},
14+
"lke_cluster": null,
1415
"tags": ["production"],
1516
"locks": ["cannot_delete_with_subresources"],
1617
"created": "2025-01-15T08:00:00",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"id": 123,
3+
"label": "Existing NodeBalancer",
4+
"region": "us-west",
5+
"hostname": "existing.nodebalancer.linode.com",
6+
"ipv4": "192.0.2.2",
7+
"ipv6": "2600:3c03::f03c:91ff:fe24:abcd",
8+
"client_conn_throttle": 20,
9+
"transfer": {
10+
"total": 2000.0,
11+
"in": 1000.0,
12+
"out": 1000.0
13+
},
14+
"type": "common",
15+
"lke_cluster": {
16+
"id": 1234,
17+
"type": "lkecluster",
18+
"label": "test-cluster",
19+
"url": "/v4/lke/clusters/1234"
20+
},
21+
"tags": ["production"],
22+
"locks": ["cannot_delete_with_subresources"],
23+
"created": "2025-01-15T08:00:00",
24+
"updated": "2025-02-05T12:00:00"
25+
}
26+

test/unit/fixtures/nodebalancers_list.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,21 @@
55
"label": "NodeBalancer A",
66
"region": "us-east",
77
"tags": ["tag1", "tag2"],
8-
"locks": ["cannot_delete"]
8+
"locks": ["cannot_delete"],
9+
"lke_cluster": null
910
},
1011
{
1112
"id": 456,
1213
"label": "NodeBalancer B",
1314
"region": "us-west",
1415
"tags": ["tag3"],
15-
"locks": []
16+
"locks": [],
17+
"lke_cluster": {
18+
"id": 1234,
19+
"type": "lkecluster",
20+
"label": "test-cluster",
21+
"url": "/v4/lke/clusters/1234"
22+
}
1623
}
1724
],
1825
"page": 1,

test/unit/nodebalancer_test.go

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package unit
22

33
import (
44
"context"
5+
"fmt"
56
"testing"
67

78
"github.com/linode/linodego"
@@ -66,23 +67,53 @@ func String(s string) *string {
6667
}
6768

6869
func TestNodeBalancer_Get(t *testing.T) {
69-
fixtureData, err := fixtures.GetFixture("nodebalancer_get")
70-
assert.NoError(t, err)
70+
tests := []struct {
71+
name string
72+
nodeBalancerID int
73+
fixture string
74+
expectedLKECluster *linodego.NodeBalancerLKECluster
75+
}{
76+
{
77+
name: "basic get",
78+
nodeBalancerID: 123,
79+
fixture: "nodebalancer_get",
80+
expectedLKECluster: nil,
81+
},
82+
{
83+
name: "get with lke_cluster",
84+
nodeBalancerID: 123,
85+
fixture: "nodebalancer_get_with_lke_cluster",
86+
expectedLKECluster: &linodego.NodeBalancerLKECluster{
87+
ID: 1234,
88+
Type: "lkecluster",
89+
Label: "test-cluster",
90+
URL: "/v4/lke/clusters/1234",
91+
},
92+
},
93+
}
7194

72-
var base ClientBaseCase
73-
base.SetUp(t)
74-
defer base.TearDown(t)
95+
for _, tt := range tests {
96+
t.Run(tt.name, func(t *testing.T) {
97+
fixtureData, err := fixtures.GetFixture(tt.fixture)
98+
assert.NoError(t, err)
7599

76-
// Mock the GET request with the fixture response
77-
base.MockGet("nodebalancers/123", fixtureData)
100+
var base ClientBaseCase
101+
base.SetUp(t)
102+
defer base.TearDown(t)
78103

79-
nodebalancer, err := base.Client.GetNodeBalancer(context.Background(), 123)
80-
assert.NoError(t, err)
104+
// Mock the GET request with the fixture response
105+
base.MockGet(fmt.Sprintf("nodebalancers/%d", tt.nodeBalancerID), fixtureData)
81106

82-
assert.Equal(t, 123, nodebalancer.ID, "Expected NodeBalancer ID to match")
83-
assert.Equal(t, "Existing NodeBalancer", *nodebalancer.Label, "Expected NodeBalancer label to match")
84-
assert.Equal(t, "us-west", nodebalancer.Region, "Expected NodeBalancer region to match")
85-
assert.Equal(t, []linodego.LockType{linodego.LockTypeCannotDeleteWithSubresources}, nodebalancer.Locks, "Expected NodeBalancer locks to match")
107+
nodebalancer, err := base.Client.GetNodeBalancer(context.Background(), tt.nodeBalancerID)
108+
assert.NoError(t, err)
109+
110+
assert.Equal(t, tt.nodeBalancerID, nodebalancer.ID, "Expected NodeBalancer ID to match")
111+
assert.Equal(t, "Existing NodeBalancer", *nodebalancer.Label, "Expected NodeBalancer label to match")
112+
assert.Equal(t, "us-west", nodebalancer.Region, "Expected NodeBalancer region to match")
113+
assert.Equal(t, []linodego.LockType{linodego.LockTypeCannotDeleteWithSubresources}, nodebalancer.Locks, "Expected NodeBalancer locks to match")
114+
assert.Equal(t, tt.expectedLKECluster, nodebalancer.LKECluster, "Expected NodeBalancer LKECluster to match")
115+
})
116+
}
86117
}
87118

88119
func TestNodeBalancer_List(t *testing.T) {
@@ -107,13 +138,20 @@ func TestNodeBalancer_List(t *testing.T) {
107138
assert.Equal(t, "us-east", nodebalancers[0].Region, "Expected first NodeBalancer region to match")
108139
assert.Equal(t, []string{"tag1", "tag2"}, nodebalancers[0].Tags, "Expected first NodeBalancer tags to match")
109140
assert.Equal(t, []linodego.LockType{linodego.LockTypeCannotDelete}, nodebalancers[0].Locks, "Expected first NodeBalancer locks to match")
141+
assert.Nil(t, nodebalancers[0].LKECluster, "Expected first NodeBalancer LKECluster to match")
110142

111143
// Verify details of the second NodeBalancer
112144
assert.Equal(t, 456, nodebalancers[1].ID, "Expected second NodeBalancer ID to match")
113145
assert.Equal(t, "NodeBalancer B", *nodebalancers[1].Label, "Expected second NodeBalancer label to match")
114146
assert.Equal(t, "us-west", nodebalancers[1].Region, "Expected second NodeBalancer region to match")
115147
assert.Equal(t, []string{"tag3"}, nodebalancers[1].Tags, "Expected second NodeBalancer tags to match")
116148
assert.Empty(t, nodebalancers[1].Locks, "Expected second NodeBalancer to have no locks")
149+
assert.Equal(t, &linodego.NodeBalancerLKECluster{
150+
ID: 1234,
151+
Type: "lkecluster",
152+
Label: "test-cluster",
153+
URL: "/v4/lke/clusters/1234",
154+
}, nodebalancers[1].LKECluster, "Expected second NodeBalancer LKECluster to match")
117155
}
118156

119157
func TestNodeBalancer_Update(t *testing.T) {

0 commit comments

Comments
 (0)