|
25 | 25 | from test_framework.test_node import TestNode
|
26 | 26 | from test_framework.util import PortSeed, get_rpc_proxy
|
27 | 27 |
|
28 |
| -# Figure out what namespace we are in |
29 |
| -with open("/var/run/secrets/kubernetes.io/serviceaccount/namespace") as f: |
30 |
| - NAMESPACE = f.read().strip() |
31 |
| - |
32 |
| -# Get the in-cluster k8s client to determine what we have access to |
33 |
| -config.load_incluster_config() |
34 |
| -sclient = client.CoreV1Api() |
| 28 | +NAMESPACE = None |
| 29 | +pods = client.V1PodList(items=[]) |
| 30 | +cmaps = client.V1ConfigMapList(items=[]) |
35 | 31 |
|
36 | 32 | try:
|
37 |
| - # An admin with cluster access can list everything. |
38 |
| - # A wargames player with namespaced access will get a FORBIDDEN error here |
39 |
| - pods = sclient.list_pod_for_all_namespaces() |
40 |
| - cmaps = sclient.list_config_map_for_all_namespaces() |
| 33 | + # Get the in-cluster k8s client to determine what we have access to |
| 34 | + config.load_incluster_config() |
| 35 | + sclient = client.CoreV1Api() |
| 36 | + |
| 37 | + # Figure out what namespace we are in |
| 38 | + with open("/var/run/secrets/kubernetes.io/serviceaccount/namespace") as f: |
| 39 | + NAMESPACE = f.read().strip() |
| 40 | + |
| 41 | + try: |
| 42 | + # An admin with cluster access can list everything. |
| 43 | + # A wargames player with namespaced access will get a FORBIDDEN error here |
| 44 | + pods = sclient.list_pod_for_all_namespaces() |
| 45 | + cmaps = sclient.list_config_map_for_all_namespaces() |
| 46 | + except Exception: |
| 47 | + # Just get whatever we have access to in this namespace only |
| 48 | + pods = sclient.list_namespaced_pod(namespace=NAMESPACE) |
| 49 | + cmaps = sclient.list_namespaced_config_map(namespace=NAMESPACE) |
41 | 50 | except Exception:
|
42 |
| - # Just get whatever we have access to in this namespace only |
43 |
| - pods = sclient.list_namespaced_pod(namespace=NAMESPACE) |
44 |
| - cmaps = sclient.list_namespaced_config_map(namespace=NAMESPACE) |
| 51 | + # If there is no cluster config, the user might just be |
| 52 | + # running the scenario file locally with --help |
| 53 | + pass |
45 | 54 |
|
46 | 55 | WARNET = {"tanks": [], "lightning": [], "channels": []}
|
47 | 56 | for pod in pods.items:
|
|
0 commit comments