This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 277
/
pod.go
78 lines (68 loc) · 2.32 KB
/
pod.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package bugreport
import (
"context"
"path"
"strings"
mapset "github.com/deckarep/golang-set"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/types"
)
const (
rootPodDirName = "pods"
)
func (c *Config) collectPerPodReport() {
for _, pod := range c.AppPods {
for _, podCmd := range getPerPodCommands(pod) {
outPath := path.Join(c.rootNamespaceDirPath(), pod.Namespace, rootPodDirName, pod.Name, commandsDirName, strings.Join(podCmd, "_"))
if err := runCmdAndWriteToFile(podCmd, outPath); err != nil {
c.completionFailure("Error running cmd: %v", podCmd)
}
}
c.completionSuccess("Collected report for Pod %q", pod)
}
}
func (c *Config) getUniquePods() []types.NamespacedName {
var pods []types.NamespacedName
podSet := mapset.NewSet()
for _, pod := range c.AppPods {
podSet.Add(pod)
}
for _, deployment := range c.AppDeployments {
d, err := c.KubeClient.AppsV1().Deployments(deployment.Namespace).Get(context.Background(), deployment.Name, metav1.GetOptions{})
if err != nil {
c.completionFailure("Deployment %s not found, skipping it", deployment)
continue
}
podLabels := d.Spec.Template.ObjectMeta.Labels
options := metav1.ListOptions{
LabelSelector: fields.SelectorFromSet(podLabels).String(),
}
podList, err := c.KubeClient.CoreV1().Pods(deployment.Namespace).List(context.Background(), options)
if err != nil {
c.completionFailure("Error listing Pods for Deployment %s, err: %s", deployment, err)
}
if podList == nil {
continue
}
for _, pod := range podList.Items {
p := types.NamespacedName{Name: pod.Name, Namespace: pod.Namespace}
podSet.Add(p)
}
}
for p := range podSet.Iter() {
pods = append(pods, p.(types.NamespacedName))
}
return pods
}
func getPerPodCommands(pod types.NamespacedName) [][]string {
return [][]string{
{"kubectl", "logs", pod.Name, "-n", pod.Namespace, "-c", "envoy"},
{"osm", "proxy", "get", "config_dump", pod.Name, "-n", pod.Namespace},
{"osm", "proxy", "get", "ready", pod.Name, "-n", pod.Namespace},
{"osm", "proxy", "get", "stats", pod.Name, "-n", pod.Namespace},
{"osm", "proxy", "get", "clusters", pod.Name, "-n", pod.Namespace},
{"osm", "proxy", "get", "listeners", pod.Name, "-n", pod.Namespace},
{"osm", "proxy", "get", "certs", pod.Name, "-n", pod.Namespace},
}
}