Repository navigation
Expand file tree
/
Copy pathconftest.py
More file actions
48 lines (45 loc) · 1.39 KB
/
Copy pathconftest.py
File metadata and controls
48 lines (45 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
import subprocess
import json
import pytest
@pytest.fixture(scope="session")
def kubecontext():
"""
Returns the target Kubernetes context:
1. KUBECONTEXT environment variable if set.
2. Current active context from `kubectl config current-context`.
3. Fallback to 'kind-zelkor'.
"""
if os.environ.get("KUBECONTEXT"):
return os.environ["KUBECONTEXT"]
try:
res = subprocess.run(
["kubectl", "config", "current-context"],
capture_output=True,
text=True,
check=True
)
ctx = res.stdout.strip()
if ctx:
return ctx
except Exception:
pass
return "kind-zelkor"
@pytest.fixture(scope="session")
def gateway_base_url():
"""Returns the Gateway base URL (default: http://127.0.0.1:8088)."""
return os.environ.get("GATEWAY_BASE_URL", "http://127.0.0.1:8088")
@pytest.fixture(scope="session")
def cluster_pods(kubecontext):
"""Retrieves all pods from the cluster across all namespaces."""
try:
res = subprocess.run(
["kubectl", "--context", kubecontext, "get", "pods", "-A", "-o", "json"],
capture_output=True,
text=True,
check=True
)
data = json.loads(res.stdout)
return data.get("items", [])
except Exception as e:
pytest.skip(f"Kubernetes cluster not accessible: {e}")