Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion magnum_cluster_api/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
AUTOSCALE_ANNOTATION_MAX = "cluster.x-k8s.io/cluster-api-autoscaler-node-group-max-size"

DEFAULT_POD_CIDR = "10.100.0.0/16"
DEFAULT_NODE_CIDR = "10.0.0.0/24"


class ClusterAutoscalerHelmRelease:
Expand Down Expand Up @@ -1202,7 +1203,7 @@ def get_object(self) -> dict:
"name": "nodeCidr",
"value": self.cluster.labels.get(
"fixed_subnet_cidr",
"10.0.0.0/24",
DEFAULT_NODE_CIDR,
),
},
{
Expand Down
46 changes: 46 additions & 0 deletions magnum_cluster_api/tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ def test_generate_cloud_controller_manager_config(self, mocker, requests_mock):
lb-provider=amphora
lb-method=ROUND_ROBIN
create-monitor=True

[Networking]
address-sort-order=10.0.0.0/24
"""
)

Expand All @@ -138,6 +141,9 @@ def test_generate_cloud_controller_manager_config_for_amphora(self, requests_moc
lb-provider=amphora
lb-method=ROUND_ROBIN
create-monitor=True

[Networking]
address-sort-order=10.0.0.0/24
"""
)

Expand Down Expand Up @@ -169,6 +175,9 @@ def test_generate_cloud_controller_manager_config_for_amphora_without_monitor(
lb-provider=ovn
lb-method=SOURCE_IP_PORT
create-monitor=False

[Networking]
address-sort-order=10.0.0.0/24
"""
)

Expand All @@ -195,6 +204,9 @@ def test_generate_cloud_controller_manager_config_for_ovn(self, requests_mock):
lb-provider=ovn
lb-method=SOURCE_IP_PORT
create-monitor=True

[Networking]
address-sort-order=10.0.0.0/24
"""
)

Expand Down Expand Up @@ -226,6 +238,9 @@ def test_generate_cloud_controller_manager_config_for_ovn_with_correct_algorithm
lb-provider=ovn
lb-method=SOURCE_IP_PORT
create-monitor=True

[Networking]
address-sort-order=10.0.0.0/24
"""
)

Expand All @@ -245,6 +260,37 @@ def test_generate_cloud_controller_manager_config_for_ovn_with_invalid_algorithm
self.context, self.pykube_api, self.cluster
)

def test_generate_cloud_controller_manager_with_custom_subnet_cidr(
self, requests_mock
):
self.cluster.labels = {"fixed_subnet_cidr": "10.0.50.0/24"}

with requests_mock as rsps:
rsps.add(self._response_for_cloud_config_secret())

config = utils.generate_cloud_controller_manager_config(
self.context, self.pykube_api, self.cluster
)

assert config == textwrap.dedent(
"""\
[Global]
auth-url=http://localhost/v3
region=RegionOne
application-credential-id=fake_application_credential_id
application-credential-secret=fake_application_credential_secret
tls-insecure=false

[LoadBalancer]
lb-provider=amphora
lb-method=ROUND_ROBIN
create-monitor=True

[Networking]
address-sort-order=10.0.50.0/24
"""
)


class TestUtils(base.BaseTestCase):
"""Test case for utils."""
Expand Down
5 changes: 5 additions & 0 deletions magnum_cluster_api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from magnum_cluster_api import exceptions as mcapi_exceptions
from magnum_cluster_api import image_utils, images, objects
from magnum_cluster_api.cache import ServerGroupCache
from magnum_cluster_api.resources import DEFAULT_NODE_CIDR

AVAILABLE_OPERATING_SYSTEMS = ["ubuntu", "flatcar", "rockylinux"]
DEFAULT_SERVER_GROUP_POLICIES = ["soft-anti-affinity"]
Expand Down Expand Up @@ -133,6 +134,8 @@ def generate_cloud_controller_manager_config(
octavia_lb_algorithm=octavia_lb_algorithm
)

node_cidr = cluster.labels.get("fixed_subnet_cidr", DEFAULT_NODE_CIDR)

return textwrap.dedent(
f"""\
[Global]
Expand All @@ -146,6 +149,8 @@ def generate_cloud_controller_manager_config(
lb-provider={octavia_provider}
lb-method={octavia_lb_algorithm}
create-monitor={octavia_lb_healthcheck}
[Networking]
address-sort-order={node_cidr}
"""
)

Expand Down
Loading