Skip to content

Commit c886918

Browse files
committed
Relied on kubectl proxy for testing.
1 parent b19fcbe commit c886918

File tree

5 files changed

+53
-45
lines changed

5 files changed

+53
-45
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ jobs:
4545
with:
4646
python-version: '3.12'
4747

48+
- name: Set release name
49+
run: echo "RELEASE_NAME=eoapi-$(echo "${{ github.sha }}" | cut -c1-8)" >> "$GITHUB_ENV"
50+
4851
- name: Start K3s cluster
4952
uses: jupyterhub/action-k3s-helm@v4
5053
with:
@@ -53,21 +56,21 @@ jobs:
5356
metrics-enabled: true
5457
docker-enabled: true
5558

56-
- name: Set release name
57-
run: echo "RELEASE_NAME=eoapi-$(echo "${{ github.sha }}" | cut -c1-8)" >> "$GITHUB_ENV"
58-
59-
- name: Verify K3s readiness
59+
- name: Wait until cluster is ready
6060
run: ./eoapi-cli cluster wait-ready
6161

6262
- name: Deploy eoAPI
6363
run: ./eoapi-cli deployment run
6464

65-
- name: Validate deployment
66-
run: ./eoapi-cli deployment debug
67-
6865
- name: Run integration tests
6966
run: ./eoapi-cli test integration
7067

68+
- name: Run notification tests
69+
run: ./eoapi-cli test notification
70+
71+
- name: Run autoscaling tests
72+
run: ./eoapi-cli test autoscaling
73+
7174
- name: Debug failed deployment
7275
if: failure()
7376
run: ./eoapi-cli deployment debug

charts/eoapi/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ multidim:
342342
GDAL_HTTP_MERGE_CONSECUTIVE_RANGES: "YES"
343343
GDAL_HTTP_MULTIPLEX: "YES"
344344
GDAL_HTTP_VERSION: "2"
345+
GDAL_SKIP: "VRT" # skip VRT driver to avoid https://github.com/OSGeo/gdal/issues/12645
345346
PYTHONWARNINGS: "ignore"
346347
VSI_CACHE: "TRUE"
347348
VSI_CACHE_SIZE: "5000000" # 5 MB (per file-handle)

tests/conftest.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,9 @@ def db_connection() -> Generator[psycopg2.extensions.connection, None, None]:
4242
"password": os.getenv("PGPASSWORD"),
4343
}
4444

45-
# All required vars are guaranteed to exist due to check above
4645
conn = None
4746
last_error = None
4847

49-
# Try different SSL modes for flexibility
5048
for sslmode in ["prefer", "require", "disable"]:
5149
try:
5250
conn = psycopg2.connect(
@@ -126,6 +124,21 @@ def kubectl_port_forward(
126124
return process
127125

128126

127+
def kubectl_proxy(
128+
port: int = 8001, namespace: str = None
129+
) -> subprocess.Popen[str]:
130+
"""Start kubectl proxy for accessing services via Kubernetes API."""
131+
cmd = ["kubectl", "proxy", f"--port={port}"]
132+
133+
process = subprocess.Popen(
134+
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
135+
)
136+
137+
# Wait a bit less than port-forward since proxy is usually faster
138+
time.sleep(2)
139+
return process
140+
141+
129142
def wait_for_url(url: str, timeout: int = 30, interval: int = 2) -> bool:
130143
start_time = time.time()
131144
while time.time() - start_time < timeout:
@@ -148,7 +161,6 @@ def make_request(url: str, timeout: int = 10) -> bool:
148161

149162

150163
def get_base_url() -> str:
151-
"""Get the base URL for API access."""
152164
namespace = get_namespace()
153165

154166
# Check if we have an ingress
@@ -179,7 +191,6 @@ def get_base_url() -> str:
179191

180192

181193
def get_pod_metrics(namespace: str, service_name: str) -> List[Dict[str, str]]:
182-
"""Get CPU and memory metrics for pods of a specific service."""
183194
release_name_val = get_release_name()
184195
result = subprocess.run(
185196
[
@@ -213,7 +224,6 @@ def get_pod_metrics(namespace: str, service_name: str) -> List[Dict[str, str]]:
213224

214225

215226
def get_hpa_status(namespace: str, hpa_name: str) -> Optional[Dict[str, Any]]:
216-
"""Get HPA status for a specific HPA."""
217227
result = kubectl_get("hpa", namespace=namespace, output="json")
218228
if result.returncode != 0:
219229
return None
@@ -227,7 +237,6 @@ def get_hpa_status(namespace: str, hpa_name: str) -> Optional[Dict[str, Any]]:
227237

228238

229239
def get_pod_count(namespace: str, service_name: str) -> int:
230-
"""Get the count of running pods for a specific service."""
231240
release_name_val = get_release_name()
232241
result = kubectl_get(
233242
"pods",

tests/integration/test_observability.py

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
get_namespace,
1010
get_release_name,
1111
kubectl_get,
12-
kubectl_port_forward,
12+
kubectl_proxy,
1313
wait_for_url,
1414
)
1515

@@ -184,26 +184,24 @@ def test_prometheus_targets_reachable(self) -> None:
184184
service = json.loads(result.stdout)["items"][0]
185185
service_name = service["metadata"]["name"]
186186

187-
# Try to port-forward to Prometheus
188-
local_port = 19090
189-
prometheus_port = 80
187+
# Try kubectl proxy instead of port-forward
188+
proxy_port = 8001
190189

191190
process = None
192191
try:
193-
process = kubectl_port_forward(
194-
service_name, local_port, prometheus_port, namespace
195-
)
192+
process = kubectl_proxy(proxy_port)
193+
194+
# Build proxy URL for Prometheus service
195+
proxy_url = f"http://localhost:{proxy_port}/api/v1/namespaces/{namespace}/services/{service_name}:80/proxy"
196196

197-
# Wait for port forward to establish
198-
if not wait_for_url(
199-
f"http://localhost:{local_port}/api/v1/targets"
200-
):
201-
pytest.skip("Could not establish connection to Prometheus")
197+
# Wait for proxy to establish
198+
if not wait_for_url(f"{proxy_url}/api/v1/targets"):
199+
pytest.skip(
200+
"Could not establish connection to Prometheus via proxy"
201+
)
202202

203203
# Check Prometheus targets
204-
response = requests.get(
205-
f"http://localhost:{local_port}/api/v1/targets"
206-
)
204+
response = requests.get(f"{proxy_url}/api/v1/targets")
207205
assert response.status_code == 200, (
208206
"Failed to get Prometheus targets"
209207
)
@@ -269,10 +267,10 @@ def test_hpa_resources_exist(self) -> None:
269267

270268
# Expected HPA names based on the Helm chart
271269
expected_hpas = [
272-
f"{release}-pgstac",
273-
f"{release}-raster",
274-
f"{release}-stac",
275-
f"{release}-vector",
270+
f"{release}-multidim-hpa",
271+
f"{release}-raster-hpa",
272+
f"{release}-stac-hpa",
273+
f"{release}-vector-hpa",
276274
]
277275

278276
found_hpas = {hpa["metadata"]["name"] for hpa in hpas}
@@ -401,20 +399,20 @@ def test_grafana_service_accessibility(self) -> None:
401399
service = services[0]
402400
service_name = service["metadata"]["name"]
403401

404-
# Port forward to Grafana
405-
local_port = 13000
406-
grafana_port = 80
402+
# Use kubectl proxy to access Grafana
403+
proxy_port = 8002
407404

408405
process = None
409406
try:
410-
process = kubectl_port_forward(
411-
service_name, local_port, grafana_port, namespace
412-
)
407+
process = kubectl_proxy(proxy_port)
408+
409+
# Build proxy URL for Grafana service
410+
proxy_url = f"http://localhost:{proxy_port}/api/v1/namespaces/{namespace}/services/{service_name}:80/proxy"
413411

414-
if not wait_for_url(f"http://localhost:{local_port}/api/health"):
415-
pytest.skip("Could not connect to Grafana")
412+
if not wait_for_url(f"{proxy_url}/api/health"):
413+
pytest.skip("Could not connect to Grafana via proxy")
416414

417-
response = requests.get(f"http://localhost:{local_port}/api/health")
415+
response = requests.get(f"{proxy_url}/api/health")
418416
assert response.status_code == 200, "Grafana health check failed"
419417

420418
health_data = response.json()

tests/requirements.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
# Test dependencies for eoAPI integration and autoscaling tests
1+
# Test dependencies for eoAPI tests
22

3-
# HTTP client libraries
43
httpx==0.27.0
54
requests==2.31.0
65

7-
# Testing framework
86
pytest==8.3.2
97
pytest-timeout==2.3.1
108

11-
# Database connectivity
129
psycopg2-binary==2.9.9

0 commit comments

Comments
 (0)