Skip to content
This repository was archived by the owner on Dec 12, 2025. It is now read-only.

Commit 9afd5f5

Browse files
author
Nikolas De Giorgis
authored
CLOUDP-66908: add configmap to evg logs (#100)
1 parent c5e4c16 commit 9afd5f5

File tree

3 files changed

+71
-26
lines changed

3 files changed

+71
-26
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,4 @@ zz_generated*.go
8282
__pycache__
8383
Dockerfile
8484
Dockerfile_python_formatting
85+
logs/*

scripts/dev/dump_diagnostic.py

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import os
22
import shutil
33
import yaml
4-
from typing import Dict, TextIO
4+
from typing import Dict, TextIO, List
5+
import json
56
import k8s_request_data
67

78

@@ -26,41 +27,60 @@ def header(msg: str) -> str:
2627

2728
def dump_crd(crd_log: TextIO) -> None:
2829
crd = k8s_request_data.get_crds()
29-
crd_log.write(header("CRD"))
30-
crd_log.write(yaml.dump(clean_nones(crd)))
30+
if crd is not None:
31+
crd_log.write(header("CRD"))
32+
crd_log.write(yaml.dump(clean_nones(crd)))
3133

3234

3335
def dump_persistent_volume(diagnostic_file: TextIO) -> None:
34-
diagnostic_file.write(header("Persistent Volumes"))
3536
pv = k8s_request_data.get_persistent_volumes()
36-
diagnostic_file.write(yaml.dump(clean_nones(pv)))
37+
if pv is not None:
38+
diagnostic_file.write(header("Persistent Volumes"))
39+
diagnostic_file.write(yaml.dump(clean_nones(pv)))
3740

3841

3942
def dump_stateful_sets_namespaced(diagnostic_file: TextIO, namespace: str) -> None:
40-
diagnostic_file.write(header("Stateful Sets"))
4143
sst = k8s_request_data.get_stateful_sets_namespaced(namespace)
42-
diagnostic_file.write(yaml.dump(clean_nones(sst)))
44+
if sst is not None:
45+
diagnostic_file.write(header("Stateful Sets"))
46+
diagnostic_file.write(yaml.dump(clean_nones(sst)))
4347

4448

4549
def dump_pod_log_namespaced(namespace: str, name: str, containers: list) -> None:
4650
for container in containers:
4751
with open(
48-
"logs/e2e/{}-{}.log".format(name, container.name),
49-
mode="w",
50-
encoding="utf-8",
52+
f"logs/e2e/{name}-{container.name}.log", mode="w", encoding="utf-8",
5153
) as log_file:
52-
log_file.write(
53-
k8s_request_data.get_pod_log_namespaced(namespace, name, container.name)
54+
log = k8s_request_data.get_pod_log_namespaced(
55+
namespace, name, container.name
5456
)
57+
if log is not None:
58+
log_file.write(log)
5559

5660

5761
def dump_pods_and_logs_namespaced(diagnostic_file: TextIO, namespace: str) -> None:
5862
pods = k8s_request_data.get_pods_namespaced(namespace)
59-
for pod in pods:
60-
name = pod.metadata.name
61-
diagnostic_file.write(header(f"Pod {name}"))
62-
diagnostic_file.write(yaml.dump(clean_nones(pod.to_dict())))
63-
dump_pod_log_namespaced(namespace, name, pod.spec.containers)
63+
if pods is not None:
64+
for pod in pods:
65+
name = pod.metadata.name
66+
diagnostic_file.write(header(f"Pod {name}"))
67+
diagnostic_file.write(yaml.dump(clean_nones(pod.to_dict())))
68+
dump_pod_log_namespaced(namespace, name, pod.spec.containers)
69+
70+
71+
def dump_configmap_keys_namespaced(
72+
namespace: str, keys: List[str], configmap_name: str
73+
) -> None:
74+
configmap = k8s_request_data.get_configmap_namespaced(namespace, configmap_name)
75+
if configmap is not None:
76+
for key in keys:
77+
with open(
78+
f"logs/e2e/{configmap_name}-{key}.json", mode="w", encoding="utf-8",
79+
) as log_file:
80+
if key in configmap["data"]:
81+
log_file.write(
82+
json.dumps(json.loads(configmap["data"][key]), indent=4)
83+
)
6484

6585

6686
def dump_all(namespace: str) -> None:
@@ -82,3 +102,5 @@ def dump_all(namespace: str) -> None:
82102

83103
with open("logs/e2e/crd.log", mode="w", encoding="utf-8") as crd_log:
84104
dump_crd(crd_log)
105+
106+
dump_configmap_keys_namespaced(namespace, ["automation-config"], "mdb0-config")

scripts/dev/k8s_request_data.py

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,60 @@
11
from kubernetes.client.rest import ApiException
22
from kubernetes import client
33

4+
from typing import Optional
45

5-
def get_crds() -> dict:
6+
7+
def get_crds() -> Optional[dict]:
68
crdv1 = client.ApiextensionsV1beta1Api()
79
try:
810
crd = crdv1.list_custom_resource_definition(pretty="true")
911
except ApiException as e:
1012
print("Exception when calling list_custom_resource_definition: %s\n" % e)
13+
return None
1114
return crd.to_dict()
1215

1316

14-
def get_persistent_volumes() -> dict:
17+
def get_persistent_volumes() -> Optional[dict]:
1518
corev1 = client.CoreV1Api()
1619
try:
1720
pv = corev1.list_persistent_volume(pretty="true")
1821
except ApiException as e:
1922
print("Exception when calling list_persistent_volume %s\n" % e)
23+
return None
2024
return pv.to_dict()
2125

2226

23-
def get_stateful_sets_namespaced(namespace: str) -> dict:
27+
def get_stateful_sets_namespaced(namespace: str) -> Optional[dict]:
2428
av1beta1 = client.AppsV1Api()
2529
try:
2630
sst = av1beta1.list_namespaced_stateful_set(namespace, pretty="true")
2731
except ApiException as e:
2832
print("Exception when calling list_namespaced_stateful_set: %s\n" % e)
33+
return None
2934
return sst.to_dict()
3035

3136

32-
def get_pods_namespaced(namespace: str) -> list:
37+
def get_configmap_namespaced(namespace: str, name: str) -> Optional[dict]:
38+
corev1 = client.CoreV1Api()
39+
try:
40+
config_map = corev1.read_namespaced_config_map(name, namespace, pretty="true")
41+
except ApiException as e:
42+
print("Exception when calling read_namespaced_config_map: %s\n" % e)
43+
return None
44+
return config_map.to_dict()
45+
46+
47+
def get_pods_namespaced(namespace: str) -> Optional[list]:
3348
corev1 = client.CoreV1Api()
3449
try:
3550
pods = corev1.list_namespaced_pod(namespace)
3651
except ApiException as e:
3752
print("Exception when calling list_namespaced_pod: %s\n" % e)
53+
return None
3854
return pods.items
3955

4056

41-
def get_pod_namespaced(namespace: str, pod_name: str) -> client.V1Pod:
57+
def get_pod_namespaced(namespace: str, pod_name: str) -> Optional[client.V1Pod]:
4258
corev1 = client.CoreV1Api()
4359
try:
4460
pod = corev1.read_namespaced_pod(name=pod_name, namespace=namespace)
@@ -47,9 +63,15 @@ def get_pod_namespaced(namespace: str, pod_name: str) -> client.V1Pod:
4763
return pod
4864

4965

50-
def get_pod_log_namespaced(namespace: str, pod_name: str, container_name: str) -> str:
66+
def get_pod_log_namespaced(
67+
namespace: str, pod_name: str, container_name: str
68+
) -> Optional[str]:
5169
corev1 = client.CoreV1Api()
52-
log = corev1.read_namespaced_pod_log(
53-
name=pod_name, namespace=namespace, pretty="true", container=container_name
54-
)
70+
try:
71+
log = corev1.read_namespaced_pod_log(
72+
name=pod_name, namespace=namespace, pretty="true", container=container_name
73+
)
74+
except ApiException as e:
75+
print("Exception when calling read_namespaced_pod_log: %s\n" % e)
76+
return None
5577
return log

0 commit comments

Comments
 (0)