Skip to content

Commit 5cb94c4

Browse files
committed
Support svc name filtering in k8s (already works in docker)
1 parent b171e7d commit 5cb94c4

1 file changed

Lines changed: 24 additions & 23 deletions

File tree

src/stack/deploy/k8s/deploy_k8s.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -477,31 +477,32 @@ def logs(self, services, tail, follow, stream):
477477
if len(pods) == 0:
478478
log_data = "******* Pods not running ********\n"
479479

480-
service_containers = []
481-
if services:
482-
for service_name in services:
483-
service_containers.append(f"{self.cluster_info.app_name}-deploy-{service_name}")
484-
485480
all_logs = []
486481
for k8s_pod_name in pods:
487-
containers = containers_in_pod(self.core_api, k8s_pod_name)
488-
if service_containers:
489-
containers = [c for c in containers if c in service_containers]
490-
# If the pod is not yet started, the logs request below will throw an exception
491-
try:
492-
log_data = ""
493-
for container in containers:
494-
container_log = self.core_api.read_namespaced_pod_log(
495-
k8s_pod_name, namespace=self.k8s_namespace, container=container
496-
)
497-
container_log_lines = container_log.splitlines()
498-
for line in container_log_lines:
499-
log_data += f"{container}: {line}\n"
500-
except client.exceptions.ApiException as e:
501-
if opts.o.debug:
502-
print(f"Error from read_namespaced_pod_log: {e}")
503-
log_data = "******* No logs available ********\n"
504-
all_logs.append(log_data)
482+
matched = True
483+
if services:
484+
matched = False
485+
for svc in services:
486+
if f"{self.cluster_info.app_name}-deploy-{svc}" not in k8s_pod_name:
487+
matched = True
488+
break
489+
if matched:
490+
containers = containers_in_pod(self.core_api, k8s_pod_name)
491+
# If the pod is not yet started, the logs request below will throw an exception
492+
try:
493+
log_data = ""
494+
for container in containers:
495+
container_log = self.core_api.read_namespaced_pod_log(
496+
k8s_pod_name, namespace=self.k8s_namespace, container=container
497+
)
498+
container_log_lines = container_log.splitlines()
499+
for line in container_log_lines:
500+
log_data += f"{container}: {line}\n"
501+
except client.exceptions.ApiException as e:
502+
if opts.o.debug:
503+
print(f"Error from read_namespaced_pod_log: {e}")
504+
log_data = "******* No logs available ********\n"
505+
all_logs.append(log_data)
505506
return log_stream_from_string("\n".join(all_logs))
506507

507508
def update(self):

0 commit comments

Comments
 (0)