Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
2 changes: 1 addition & 1 deletion linode_api4/groups/lke.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def cluster_create(

result = self.client.post(
"/lke/clusters",
data=_flatten_request_body_recursive(drop_null_keys(params)),
data=drop_null_keys(_flatten_request_body_recursive(params)),
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop_null_keys(...) needed to be moved outside of the _flatten_request_body_recursive(...) call because it doesn't have handling for JSONObjects.

)

if "id" not in result:
Expand Down
3 changes: 2 additions & 1 deletion linode_api4/objects/lke.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Region,
Type,
)
from linode_api4.util import drop_null_keys


class LKEType(Base):
Expand Down Expand Up @@ -574,7 +575,7 @@ def control_plane_acl_update(
result = self._client.put(
f"{LKECluster.api_endpoint}/control_plane_acl",
model=self,
data={"acl": acl},
data={"acl": drop_null_keys(acl)},
)

acl = result.get("acl")
Expand Down
14 changes: 14 additions & 0 deletions test/integration/models/lke/test_lke.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,20 @@ def test_lke_cluster_acl(lke_cluster_with_acl):
assert acl.addresses.ipv4 == ["10.0.0.2/32"]


def test_lke_cluster_update_acl_null_addresses(lke_cluster_with_acl):
cluster = lke_cluster_with_acl

# Addresses should not be included in the request if it's null,
# else an error will be returned by the API.
# See: TPT-3489
acl = cluster.control_plane_acl_update(
{"enabled": False, "addresses": None}
)

assert acl == cluster.control_plane_acl
assert acl.addresses.ipv4 == ["10.0.0.1/32"]


def test_lke_cluster_disable_acl(lke_cluster_with_acl):
cluster = lke_cluster_with_acl

Expand Down
38 changes: 38 additions & 0 deletions test/unit/objects/lke_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,3 +498,41 @@ def test_populate_with_mixed_types(self):
assert self.pool.nodes[0].id == "node7"
assert self.pool.nodes[1].id == "node8"
assert self.pool.nodes[2].id == "node9"

def test_cluster_create_acl_null_addresses(self):
with self.mock_post("lke/clusters") as m:
self.client.lke.cluster_create(
region="us-mia",
label="foobar",
kube_version="1.32",
node_pools=[self.client.lke.node_pool("g6-standard-1", 3)],
control_plane={
"acl": {
"enabled": False,
"addresses": None,
}
},
)

# Addresses should not be included in the API request if it's null
# See: TPT-3489
assert m.call_data["control_plane"] == {
"acl": {
"enabled": False,
}
}

def test_cluster_update_acl_null_addresses(self):
cluster = LKECluster(self.client, 18881)

with self.mock_put("lke/clusters/18881/control_plane_acl") as m:
cluster.control_plane_acl_update(
{
"enabled": True,
"addresses": None,
}
)

# Addresses should not be included in the API request if it's null
# See: TPT-3489
assert m.call_data == {"acl": {"enabled": True}}