diff --git a/CHANGELOG.md b/CHANGELOG.md index 5697e40..cb1a1b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ This file is used to list changes made in each version of the Dinghy-ping ## unreleased +## v1.1.0 (2022-03-29) +- [Zane] + - Adding support for multiple containers in pods + ## v1.0.0 (2022-03-29) - [Zane] - rebuild application using Flask, dropping Responder framework diff --git a/charts/dinghy-ping/Chart.yaml b/charts/dinghy-ping/Chart.yaml index 66c1c17..a3736aa 100644 --- a/charts/dinghy-ping/Chart.yaml +++ b/charts/dinghy-ping/Chart.yaml @@ -1,8 +1,8 @@ apiVersion: v1 -appVersion: "v1.0.0" +appVersion: "v1.1.0" description: A Helm chart for dinghy-ping name: dinghy-ping -version: 0.4.9 +version: 0.4.10 icon: https://user-images.githubusercontent.com/538171/64288240-732bef00-cf16-11e9-830a-7b08759bffad.jpg maintainers: - name: sepulworld diff --git a/charts/dinghy-ping/templates/deployment.yaml b/charts/dinghy-ping/templates/deployment.yaml index 7345522..8e3de70 100644 --- a/charts/dinghy-ping/templates/deployment.yaml +++ b/charts/dinghy-ping/templates/deployment.yaml @@ -30,7 +30,7 @@ spec: - name: DINGHY_PING_HOST value: {{ .Release.Name }}.{{- .Values.subdomain }} - name: DD_DOGSTATSD_DISABLE - value: {{ .Values.disable_dogstatsd }} + value: "{{ .Values.disable_dogstatsd }}" - name: MY_CLUSTER_DOMAIN value: {{ .Values.subdomain }} ports: diff --git a/dinghy_ping/services/api.py b/dinghy_ping/services/api.py index 8db7d97..f825edf 100644 --- a/dinghy_ping/services/api.py +++ b/dinghy_ping/services/api.py @@ -442,8 +442,10 @@ def list_pods(): ) def dinghy_get_pods(): """Form input page for pod logs and describe, input namespace""" - - resp = render_template("pods_tabbed.html", namespaces=_get_all_namespaces()) + tail_lines = int(request.args.get("tail_lines", default=TAIL_LINES_DEFAULT)) + resp = render_template( + "pods_tabbed.html", tail_lines=tail_lines, namespaces=_get_all_namespaces() + ) return resp @@ -453,7 +455,7 @@ def dinghy_get_pods(): metric="dinghy_ping_events_render_namespace_event_page.timer", tags=dd_tags ) def dinghy_get_namespace_events(): - """Render landing page to select namespace for event stream""" + """render landing page to select namespace for event stream""" all_namespaces = _get_all_namespaces() @@ -492,11 +494,13 @@ def form_input_pod_logs(): pod = request.args.get("pod") namespace = request.args.get("namespace", "default") tail_lines = request.args.get("tail_lines", TAIL_LINES_DEFAULT) + container = request.args.get("container", "") - logging.debug(f"Retrieving pod logs... {pod} in namespace {namespace}") + logging.debug(f"Retrieving pods... {pod} in namespace {namespace}") + logging.debug(f"Retrieving container logs... {container} in pod {pod}") try: - ret = _get_pod_logs(pod, namespace, tail_lines) + ret = _get_pod_logs(pod, namespace, container, tail_lines) resp = render_template("pod_logs_output.html", logs=ret) return resp @@ -512,11 +516,13 @@ def form_input_pod_logs_stream(*, tail_lines=TAIL_LINES_DEFAULT): """List pods in namespace and click on one to display logs""" pod = request.args["pod"] namespace = request.args["namespace"] + container = request.args.get("container", "") resp = render_template( "pod_logs_output_streaming.html", namespace=namespace, name=pod, + container=container, dinghy_ping_web_socket_host=dinghy_ping_web_socket_host, ) @@ -552,10 +558,12 @@ def log_stream_websocket(ws): name = request.args["name"] namespace = request.args["namespace"] + container = request.args["container"] resp = k8s_client.read_namespaced_pod_log( name, namespace, + container=container, tail_lines=TAIL_LINES_DEFAULT, follow=True, _preload_content=False, @@ -691,16 +699,28 @@ def _get_deployment_logs(namespace, name, tail_lines=TAIL_LINES_DEFAULT): return logs -def _get_pod_logs(pod, namespace, tail_lines=TAIL_LINES_DEFAULT): +def _get_pod_logs(pod, namespace, container, tail_lines=TAIL_LINES_DEFAULT): """Read pod logs""" k8s_client = client.CoreV1Api() ret = [] - try: - ret = k8s_client.read_namespaced_pod_log( - pod, namespace, tail_lines=TAIL_LINES_DEFAULT - ) - except ApiException as e: - logging.error(f"Exception when calling CoreV1Api->read_namespaced_pod_log: {e}") + if container: + try: + ret = k8s_client.read_namespaced_pod_log( + pod, namespace, container=container, tail_lines=tail_lines + ) + except ApiException as e: + logging.error( + f"Exception HERE when calling CoreV1Api->read_namespaced_pod_log: {e}" + ) + else: + try: + ret = k8s_client.read_namespaced_pod_log( + pod, namespace, tail_lines=tail_lines + ) + except ApiException as e: + logging.error( + f"Exception when calling CoreV1Api->read_namespaced_pod_log: {e}" + ) return ret @@ -755,7 +775,7 @@ def _get_all_namespaces(): def _get_all_pods(namespace=None): - """Get all pods""" + """Get all pods and return dict of pods with their containers and their namespaces""" pods = {} k8s_client = client.CoreV1Api() @@ -767,7 +787,10 @@ def _get_all_pods(namespace=None): for i in ret.items: pod = i.metadata.name namespace = i.metadata.namespace - pods.update({pod: i.metadata.namespace}) + containers = [] + for container in i.spec.containers: + containers.append(container.name) + pods[pod] = dict(namespace=namespace, containers=containers) return pods diff --git a/dinghy_ping/views/templates/deployment_describe_output.html b/dinghy_ping/views/templates/deployment_describe_output.html index 8fea22b..9c46f72 100644 --- a/dinghy_ping/views/templates/deployment_describe_output.html +++ b/dinghy_ping/views/templates/deployment_describe_output.html @@ -27,11 +27,21 @@

Available Replicas: {{ deployment.status.available_replicas }}
Ready Replicas: {{ deployment.status.ready_replicas }}
Deployment PODS -
+ {% for pod, pod_obj in all_pods.items() %} - {{pod}} logstail describe -
+ + {{pod}} + {% for container in pod_obj.spec.containers %} + + {% endfor %} {% endfor %} + +
+ +
Created: {{ deployment.metadata.creation_timestamp }}
diff --git a/dinghy_ping/views/templates/pod_logs_input.html b/dinghy_ping/views/templates/pod_logs_input.html index 271e41a..4357ddd 100644 --- a/dinghy_ping/views/templates/pod_logs_input.html +++ b/dinghy_ping/views/templates/pod_logs_input.html @@ -5,10 +5,23 @@

Dinghy Ping - Pods


- {% for pod, namespace in all_pods.items() %} - {{namespace}} - {{pod}} logs tail describe + {% for pod, data in all_pods.items() %} + + {{data.namespace}} - {{pod}} + + {% for container in data.containers %} + + + {% endfor %}
{% endfor %} + +
+ +
{% endblock %} diff --git a/dinghy_ping/views/templates/pod_logs_output_streaming.html b/dinghy_ping/views/templates/pod_logs_output_streaming.html index cfc5d8f..abfb5b0 100644 --- a/dinghy_ping/views/templates/pod_logs_output_streaming.html +++ b/dinghy_ping/views/templates/pod_logs_output_streaming.html @@ -15,7 +15,7 @@ } function connect() { - var ws = new WebSocket('{{dinghy_ping_web_socket_host}}/ws/logstream?namespace={{namespace}}&name={{name}}'); + var ws = new WebSocket('{{dinghy_ping_web_socket_host}}/ws/logstream?namespace={{namespace}}&name={{name}}&container={{container}}'); ws.onmessage = function(event) { let message = event.data;