@@ -11,6 +11,7 @@ import (
1111 "strings"
1212
1313 troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
14+ "github.com/replicatedhq/troubleshoot/pkg/k8sutil"
1415 "gopkg.in/yaml.v2"
1516 authorizationv1 "k8s.io/api/authorization/v1"
1617 corev1 "k8s.io/api/core/v1"
@@ -67,16 +68,19 @@ func ClusterResources(c *Collector, clusterResourcesCollector *troubleshootv1bet
6768 }
6869
6970 // pods
70- pods , podErrors , failedPods := pods (ctx , client , namespaceNames )
71+ pods , podErrors , unhealthyPods := pods (ctx , client , namespaceNames )
7172 for k , v := range pods {
7273 output .SaveResult (c .BundlePath , path .Join ("cluster-resources/pods" , k ), bytes .NewBuffer (v ))
7374 }
7475 output .SaveResult (c .BundlePath , "cluster-resources/pods-errors.json" , marshalErrors (podErrors ))
7576
76- for _ , pod := range failedPods {
77+ for _ , pod := range unhealthyPods {
7778 allContainers := append (pod .Spec .InitContainers , pod .Spec .Containers ... )
7879 for _ , container := range allContainers {
79- logsRoot := path .Join (c .BundlePath , "cluster-resources" , "pods" , pod .Namespace , "logs" )
80+ logsRoot := ""
81+ if c .BundlePath != "" {
82+ logsRoot = path .Join (c .BundlePath , "cluster-resources" , "pods" , "logs" , pod .Namespace )
83+ }
8084 limits := & troubleshootv1beta2.LogLimits {
8185 MaxLines : 500 ,
8286 }
@@ -86,7 +90,7 @@ func ClusterResources(c *Collector, clusterResourcesCollector *troubleshootv1bet
8690 output .SaveResult (c .BundlePath , errPath , bytes .NewBuffer ([]byte (err .Error ())))
8791 }
8892 for k , v := range podLogs {
89- output [filepath .Join ("cluster-resources" , "pods" , pod . Namespace , "logs" , k )] = v
93+ output [filepath .Join ("cluster-resources" , "pods" , "logs" , pod . Namespace , k )] = v
9094 }
9195 }
9296 }
@@ -263,7 +267,7 @@ func getNamespace(ctx context.Context, client *kubernetes.Clientset, namespace s
263267func pods (ctx context.Context , client * kubernetes.Clientset , namespaces []string ) (map [string ][]byte , map [string ]string , []corev1.Pod ) {
264268 podsByNamespace := make (map [string ][]byte )
265269 errorsByNamespace := make (map [string ]string )
266- failedPods := []corev1.Pod {}
270+ unhealthyPods := []corev1.Pod {}
267271
268272 for _ , namespace := range namespaces {
269273 pods , err := client .CoreV1 ().Pods (namespace ).List (ctx , metav1.ListOptions {})
@@ -279,15 +283,15 @@ func pods(ctx context.Context, client *kubernetes.Clientset, namespaces []string
279283 }
280284
281285 for _ , pod := range pods .Items {
282- if pod . Status . Phase == corev1 . PodFailed {
283- failedPods = append (failedPods , pod )
286+ if k8sutil . IsPodUnhealthy ( & pod ) {
287+ unhealthyPods = append (unhealthyPods , pod )
284288 }
285289 }
286290
287291 podsByNamespace [namespace + ".json" ] = b
288292 }
289293
290- return podsByNamespace , errorsByNamespace , failedPods
294+ return podsByNamespace , errorsByNamespace , unhealthyPods
291295}
292296
293297func services (ctx context.Context , client * kubernetes.Clientset , namespaces []string ) (map [string ][]byte , map [string ]string ) {
0 commit comments