From 0fbdb18a76462ad8563d7c767fd92f18ac5508cb Mon Sep 17 00:00:00 2001 From: David Boreham Date: Wed, 14 Feb 2024 15:59:03 -0700 Subject: [PATCH] Fix logging for multi-container pods --- stack_orchestrator/deploy/k8s/deploy_k8s.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/stack_orchestrator/deploy/k8s/deploy_k8s.py b/stack_orchestrator/deploy/k8s/deploy_k8s.py index e1f729c5..b4a6a853 100644 --- a/stack_orchestrator/deploy/k8s/deploy_k8s.py +++ b/stack_orchestrator/deploy/k8s/deploy_k8s.py @@ -20,7 +20,7 @@ from kubernetes import client, config from stack_orchestrator import constants from stack_orchestrator.deploy.deployer import Deployer, DeployerConfigGenerator from stack_orchestrator.deploy.k8s.helpers import create_cluster, destroy_cluster, load_images_into_kind -from stack_orchestrator.deploy.k8s.helpers import pods_in_deployment, log_stream_from_string, generate_kind_config +from stack_orchestrator.deploy.k8s.helpers import pods_in_deployment, containers_in_pod, log_stream_from_string, generate_kind_config from stack_orchestrator.deploy.k8s.cluster_info import ClusterInfo from stack_orchestrator.opts import opts from stack_orchestrator.deploy.deployment_context import DeploymentContext @@ -359,9 +359,15 @@ class K8sDeployer(Deployer): log_data = "******* Pods not running ********\n" else: k8s_pod_name = pods[0] + containers = containers_in_pod(self.core_api, k8s_pod_name) # If the pod is not yet started, the logs request below will throw an exception try: - log_data = self.core_api.read_namespaced_pod_log(k8s_pod_name, namespace="default", container="test") + log_data = "" + for container in containers: + container_log = self.core_api.read_namespaced_pod_log(k8s_pod_name, namespace="default", container=container) + container_log_lines = container_log.splitlines() + for line in container_log_lines: + log_data += f"{container}: {line}\n" except client.exceptions.ApiException as e: if opts.o.debug: print(f"Error from read_namespaced_pod_log: {e}")