Skip to content

Commit

Permalink
Merge pull request Kuadrant#542 from jsmolar/observability
Browse files Browse the repository at this point in the history
Update DNSPolicy model according to load balance change
  • Loading branch information
jsmolar authored Sep 24, 2024
2 parents 364b75e + bebb50b commit ce9579c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
15 changes: 4 additions & 11 deletions testsuite/kuadrant/policy/dns.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions testsuite/tests/multicluster/load_balanced/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)
Expand All @@ -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}
)
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

0 comments on commit ce9579c

Please sign in to comment.