From 925d1a72989885bd1d4af63fcb1f39e3a36a5e87 Mon Sep 17 00:00:00 2001 From: jbilski Date: Mon, 27 Apr 2026 15:20:18 +0200 Subject: [PATCH 1/3] TPT-3501 Support NodeBalancer lke_cluster field --- linode_api4/common.py | 12 ++++++++++++ linode_api4/objects/nodebalancer.py | 3 ++- test/fixtures/nodebalancers.json | 7 +++++++ test/fixtures/nodebalancers_123456.json | 6 ++++++ test/unit/objects/nodebalancers_test.py | 11 ++++++++++- 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/linode_api4/common.py b/linode_api4/common.py index 7e98b1977..73a641544 100644 --- a/linode_api4/common.py +++ b/linode_api4/common.py @@ -81,3 +81,15 @@ class RegionPrice(JSONObject): id: int = 0 hourly: int = 0 monthly: int = 0 + + +@dataclass +class LKECluster(JSONObject): + """ + LKECluster contains the core fields of a lke_Cluster object returned by various node balancer endpoints. + """ + + id: int = 0 + label: str = "" + type: str = "" + url: str = "" \ No newline at end of file diff --git a/linode_api4/objects/nodebalancer.py b/linode_api4/objects/nodebalancer.py index bae9621ff..851e9cd1d 100644 --- a/linode_api4/objects/nodebalancer.py +++ b/linode_api4/objects/nodebalancer.py @@ -1,7 +1,7 @@ import os from urllib import parse -from linode_api4.common import Price, RegionPrice +from linode_api4.common import Price, RegionPrice, LKECluster from linode_api4.errors import UnexpectedResponseError from linode_api4.objects.base import Base, MappedObject, Property from linode_api4.objects.dbase import DerivedBase @@ -276,6 +276,7 @@ class NodeBalancer(Base): "client_udp_sess_throttle": Property(mutable=True), "locks": Property(unordered=True), "type": Property(), + "lke_cluster": Property(json_object=LKECluster), "frontend_address_type": Property(), "frontend_vpc_subnet_id": Property(), } diff --git a/test/fixtures/nodebalancers.json b/test/fixtures/nodebalancers.json index 2ccbed4b1..aef3c473f 100644 --- a/test/fixtures/nodebalancers.json +++ b/test/fixtures/nodebalancers.json @@ -13,6 +13,12 @@ "tags": ["something"], "locks": ["cannot_delete_with_subresources"], "type": "common", + "lke_cluster": { + "id": 1234, + "type": "lkecluster", + "label": "test-cluster", + "url": "/v4/lke/clusters/1234" + }, "frontend_address_type": "vpc", "frontend_vpc_subnet_id": 5555 }, @@ -29,6 +35,7 @@ "tags": [], "locks": [], "type": "premium_40gb", + "lke_cluster": null, "frontend_address_type": "vpc", "frontend_vpc_subnet_id": 6666 } diff --git a/test/fixtures/nodebalancers_123456.json b/test/fixtures/nodebalancers_123456.json index d6d66233c..a78f1eccf 100644 --- a/test/fixtures/nodebalancers_123456.json +++ b/test/fixtures/nodebalancers_123456.json @@ -15,6 +15,12 @@ "cannot_delete_with_subresources" ], "type": "common", + "lke_cluster": { + "id": 1234, + "type": "lkecluster", + "label": "test-cluster", + "url": "/v4/lke/clusters/1234" + }, "frontend_address_type": "vpc", "frontend_vpc_subnet_id": 5555 } \ No newline at end of file diff --git a/test/unit/objects/nodebalancers_test.py b/test/unit/objects/nodebalancers_test.py index 2eae14664..b6ff86f37 100644 --- a/test/unit/objects/nodebalancers_test.py +++ b/test/unit/objects/nodebalancers_test.py @@ -208,7 +208,7 @@ def test_firewalls(self): def test_config_rebuild(self): """ - Test that you can rebuild the cofig of a node balancer. + Test that you can rebuild the config of a node balancer. """ config_rebuild_url = "/nodebalancers/12345/configs/4567/rebuild" with self.mock_post(config_rebuild_url) as m: @@ -279,12 +279,17 @@ def test_list_nodebalancers(self): self.assertEqual(nbs[0].id, 123456) self.assertEqual(nbs[0].label, "balancer123456") self.assertEqual(nbs[0].type, "common") + self.assertEqual(nbs[0].lke_cluster.id, 1234) + self.assertEqual(nbs[0].lke_cluster.type, "lkecluster") + self.assertEqual(nbs[0].lke_cluster.label, "test-cluster") + self.assertEqual(nbs[0].lke_cluster.url, "/v4/lke/clusters/1234") self.assertEqual(nbs[0].frontend_address_type, "vpc") self.assertEqual(nbs[0].frontend_vpc_subnet_id, 5555) self.assertEqual(nbs[1].id, 123457) self.assertEqual(nbs[1].label, "balancer123457") self.assertEqual(nbs[1].type, "premium_40gb") + self.assertEqual(nbs[1].lke_cluster, None) self.assertEqual(nbs[1].frontend_address_type, "vpc") self.assertEqual(nbs[1].frontend_vpc_subnet_id, 6666) @@ -297,6 +302,10 @@ def test_get_nodebalancer(self): self.assertEqual(nb.id, 123456) self.assertEqual(nb.label, "balancer123456") self.assertEqual(nb.type, "common") + self.assertEqual(nb.lke_cluster.id, 1234) + self.assertEqual(nb.lke_cluster.type, "lkecluster") + self.assertEqual(nb.lke_cluster.label, "test-cluster") + self.assertEqual(nb.lke_cluster.url, "/v4/lke/clusters/1234") self.assertEqual(nb.frontend_address_type, "vpc") self.assertEqual(nb.frontend_vpc_subnet_id, 5555) From 0ea8eb80d8312fe778dfbd8ce43d943f15ee9157 Mon Sep 17 00:00:00 2001 From: jbilski Date: Mon, 27 Apr 2026 16:19:43 +0200 Subject: [PATCH 2/3] Sort imports --- linode_api4/common.py | 2 +- linode_api4/objects/nodebalancer.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/linode_api4/common.py b/linode_api4/common.py index 73a641544..3bd9d9a01 100644 --- a/linode_api4/common.py +++ b/linode_api4/common.py @@ -92,4 +92,4 @@ class LKECluster(JSONObject): id: int = 0 label: str = "" type: str = "" - url: str = "" \ No newline at end of file + url: str = "" diff --git a/linode_api4/objects/nodebalancer.py b/linode_api4/objects/nodebalancer.py index 851e9cd1d..31d0f1a4d 100644 --- a/linode_api4/objects/nodebalancer.py +++ b/linode_api4/objects/nodebalancer.py @@ -1,7 +1,7 @@ import os from urllib import parse -from linode_api4.common import Price, RegionPrice, LKECluster +from linode_api4.common import LKECluster, Price, RegionPrice from linode_api4.errors import UnexpectedResponseError from linode_api4.objects.base import Base, MappedObject, Property from linode_api4.objects.dbase import DerivedBase From ea944b10a17a132a37345645d6204f346390c5b3 Mon Sep 17 00:00:00 2001 From: jbilski Date: Tue, 28 Apr 2026 10:35:09 +0200 Subject: [PATCH 3/3] TPT-3501 Correct docstring --- linode_api4/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linode_api4/common.py b/linode_api4/common.py index 3bd9d9a01..a093930b6 100644 --- a/linode_api4/common.py +++ b/linode_api4/common.py @@ -86,7 +86,7 @@ class RegionPrice(JSONObject): @dataclass class LKECluster(JSONObject): """ - LKECluster contains the core fields of a lke_Cluster object returned by various node balancer endpoints. + LKECluster contains the core fields of a lke_cluster object returned by various node balancer endpoints. """ id: int = 0