From d33393d3fd7a456f9d73c9be11fb91424f78179f Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Wed, 23 Jul 2025 16:32:21 -0400 Subject: [PATCH] feat: debug failed global helm chart installations by checking all pod logs --- plugins/scheduler-k3s/functions.go | 19 +++++++++++++++++++ plugins/scheduler-k3s/k8s.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/plugins/scheduler-k3s/functions.go b/plugins/scheduler-k3s/functions.go index 76f5991d7..accb49d17 100644 --- a/plugins/scheduler-k3s/functions.go +++ b/plugins/scheduler-k3s/functions.go @@ -1605,6 +1605,25 @@ func installHelmCharts(ctx context.Context, clientset KubernetesClient, shouldIn Wait: true, }) if err != nil { + chartPods, err := clientset.ListPods(ctx, ListPodsInput{ + Namespace: chart.Namespace, + }) + if err != nil { + return fmt.Errorf("Error listing chart pods: %w", err) + } + for _, pod := range chartPods { + logs, err := clientset.GetLogs(ctx, GetLogsInput{ + Name: pod.Name, + Namespace: pod.Namespace, + }) + if err != nil { + return fmt.Errorf("Error getting chart pod logs: %w", err) + } + common.LogExclaim(fmt.Sprintf("Logs for %s/%s", pod.Namespace, pod.Name)) + for _, log := range strings.Split(string(logs), "\n") { + common.LogInfo1(log) + } + } return fmt.Errorf("Error installing chart %s: %w", chart.ChartPath, err) } } diff --git a/plugins/scheduler-k3s/k8s.go b/plugins/scheduler-k3s/k8s.go index 494d5ab9a..491e9174a 100644 --- a/plugins/scheduler-k3s/k8s.go +++ b/plugins/scheduler-k3s/k8s.go @@ -416,6 +416,35 @@ func (k KubernetesClient) ExecCommand(ctx context.Context, input ExecCommandInpu }) } +// GetPodLogsInput contains all the information needed to get the logs for a Kubernetes pod +type GetLogsInput struct { + // Name is the Kubernetes pod name + Name string + + // Namespace is the Kubernetes namespace + Namespace string +} + +// GetLogs gets the logs for a Kubernetes pod +func (k KubernetesClient) GetLogs(ctx context.Context, input GetLogsInput) ([]byte, error) { + logOptions := corev1.PodLogOptions{} + + request := k.Client.CoreV1().Pods(input.Namespace).GetLogs(input.Name, &logOptions) + + readCloser, err := request.Stream(ctx) + if err != nil { + return nil, fmt.Errorf("failed to get logs: %w", err) + } + defer readCloser.Close() + + bytes, err := io.ReadAll(readCloser) + if err != nil { + return nil, fmt.Errorf("failed to read logs: %w", err) + } + + return bytes, nil +} + // GetNodeInput contains all the information needed to get a Kubernetes node type GetNodeInput struct { // Name is the Kubernetes node name