From bebb50bd7fd3ab7d3fa442026bd275c632557cee Mon Sep 17 00:00:00 2001 From: Jakub Smolar Date: Thu, 19 Sep 2024 14:55:56 +0200 Subject: [PATCH] Update DNSPolicy model according to load balance change Signed-off-by: Jakub Smolar --- testsuite/kuadrant/policy/dns.py | 15 ++++----------- .../tests/multicluster/load_balanced/conftest.py | 4 ++-- .../load_balanced/test_unsupported_geocode.py | 2 +- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/testsuite/kuadrant/policy/dns.py b/testsuite/kuadrant/policy/dns.py index 69c79625..57a237d3 100644 --- a/testsuite/kuadrant/policy/dns.py +++ b/testsuite/kuadrant/policy/dns.py @@ -1,6 +1,7 @@ """Module for DNSPolicy related classes""" from dataclasses import dataclass +from typing import Optional from testsuite.gateway import Referencable from testsuite.kubernetes.client import KubernetesClient @@ -25,15 +26,9 @@ def _check(obj): class LoadBalancing: """Dataclass for DNSPolicy load-balancing spec""" - default_geo: str - default_weight: int - - def asdict(self): - """Custom asdict due to nested structure.""" - return { - "geo": {"defaultGeo": self.default_geo}, - "weighted": {"defaultWeight": self.default_weight}, - } + defaultGeo: bool # pylint: disable=invalid-name + geo: str + weight: Optional[int] class DNSPolicy(Policy): @@ -58,12 +53,10 @@ def create_instance( "spec": { "targetRef": parent.reference, "providerRefs": [{"name": provider_secret_name}], - "routingStrategy": "simple", }, } if load_balancing: - model["spec"]["routingStrategy"] = "loadbalanced" model["spec"]["loadBalancing"] = asdict(load_balancing) return cls(model, context=cluster.context) diff --git a/testsuite/tests/multicluster/load_balanced/conftest.py b/testsuite/tests/multicluster/load_balanced/conftest.py index c70b9ce3..22dfa7ed 100644 --- a/testsuite/tests/multicluster/load_balanced/conftest.py +++ b/testsuite/tests/multicluster/load_balanced/conftest.py @@ -31,7 +31,7 @@ def dns_server2(dns_config): @pytest.fixture(scope="module") def dns_policy(blame, cluster, gateway, dns_server, module_label, dns_provider_secret): """DNSPolicy with load-balancing for the first cluster""" - load_balancing = LoadBalancing(default_geo=dns_server["geo_code"], default_weight=10) + load_balancing = LoadBalancing(defaultGeo=True, geo=dns_server["geo_code"], weight=10) return DNSPolicy.create_instance( cluster, blame("dns"), gateway, dns_provider_secret, load_balancing, labels={"app": module_label} ) @@ -40,7 +40,7 @@ def dns_policy(blame, cluster, gateway, dns_server, module_label, dns_provider_s @pytest.fixture(scope="module") def dns_policy2(blame, cluster2, gateway2, dns_server, module_label, dns_provider_secret): """DNSPolicy with load-balancing for the second cluster""" - load_balancing = LoadBalancing(default_geo=dns_server["geo_code"], default_weight=10) + load_balancing = LoadBalancing(defaultGeo=True, geo=dns_server["geo_code"], weight=10) return DNSPolicy.create_instance( cluster2, blame("dns"), gateway2, dns_provider_secret, load_balancing, labels={"app": module_label} ) diff --git a/testsuite/tests/multicluster/load_balanced/test_unsupported_geocode.py b/testsuite/tests/multicluster/load_balanced/test_unsupported_geocode.py index c06e16b6..0dcbda98 100644 --- a/testsuite/tests/multicluster/load_balanced/test_unsupported_geocode.py +++ b/testsuite/tests/multicluster/load_balanced/test_unsupported_geocode.py @@ -9,7 +9,7 @@ def test_unsupported_geocode(dns_policy): """Change default geocode to not existent one and verify that policy became not enforced""" - dns_policy.model.spec.loadBalancing.geo.defaultGeo = "XX" + dns_policy.model.spec.loadBalancing.geo = "XX" dns_policy.apply() assert dns_policy.wait_until(has_condition("Enforced", "False"))