ci: do not fail step if log file is missing
from dataclasses import dataclass
import urllib3
from kubernetes import client, config
+from kubernetes.client.rest import ApiException
import os
from typing import Dict
import zipfile
-
@dataclass
class K8sResponse:
data: urllib3.response.HTTPResponse
@@ -113,6 +113,7 @@ def get_and_zip_logs(
if tail_lines:
args['tail_lines'] = tail_lines
+ try:
data, status_code, headers = k8s.read_namespaced_pod_log_with_http_info(**args)
# returns tuple (response_data, http status, headers)
log_response = K8sResponse(
@@ -124,6 +125,14 @@ def get_and_zip_logs(
if log_response.status_code != 200:
print(f'Getting logs failed with {log_response.status_code=}')
continue
+ except ApiException as ex:
+ if ex.status == 404:
+ print(f'Log for pod {pod_name} is already gone {str(ex)}')
+ else:
+ print(f'Getting logs for pod {pod_name} failed {str(ex)}')
+
+ with open(zip_comp, 'w') as f:
+ f.write('Log file for {pod_name} could not be retrieved: {str(ex)}')
with log_zip.open(zip_comp, mode='w') as zipcomp:
for chunk in log_response.data.stream(amt=4096):
