Skip to content

Commit

Permalink
Add test for NO_PROXY + lightkube fix
Browse files Browse the repository at this point in the history
  • Loading branch information
phvalguima committed Oct 18, 2023
1 parent 6ea47e5 commit b9b1819
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/integration/high_availability/test_replication.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,28 @@

TIMEOUT = 15 * 60

# Quick hack: force NO_PROXY env to have the IP/hostname of the cluster
from lightkube.core.generic_client import GenericClient
from lightkube.config.client_adapter import httpx_parameters
from lightkube.config.kubeconfig import SingleConfig
import os
import httpx
from urllib.parse import urlparse


def NoProxyExtendClient(config: SingleConfig, timeout: httpx.Timeout) -> httpx.Client:
"""Reviews the NO_PROXY setting: it must contain the base_url's IP/hostname, otherwise add it."""
# urlparse returns an <ip>|<hostname>:<port>, we do not need the port
host = urlparse(config.cluster.server).split(":")[0]
print("TESTING" + os.environ["NO_PROXY"])
if host not in os.environ["NO_PROXY"].split(","): # compare with a list, as we want to avoid matching "192.168.0.1" "192.168.0.1/24,10.0.0.0/8" string
os.environ["NO_PROXY"] = ",".join([host, os.environ["NO_PROXY"] ])
print("TESTING" + os.environ["NO_PROXY"])
return httpx.Client(trust_env=False, **httpx_parameters(config, timeout))

# Override the AdapterClient
GenericClient.AdapterClient = staticmethod(NoProxyExtendClient)


@pytest.mark.group(1)
async def test_build_and_deploy(ops_test: OpsTest) -> None:
Expand Down

0 comments on commit b9b1819

Please sign in to comment.