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 279
/
controlplane.go
61 lines (54 loc) · 2.07 KB
/
controlplane.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
package bugreport
import (
"context"
"fmt"
"path"
"strings"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/openservicemesh/osm/pkg/constants"
)
func (c *Config) collectControlPlaneLogs() {
pods, err := c.KubeClient.CoreV1().Pods(c.ControlPlaneNamepace).
List(context.Background(), v1.ListOptions{
LabelSelector: fmt.Sprintf(
"%s=%s",
constants.OSMAppNameLabelKey,
constants.OSMAppNameLabelValue,
),
})
if err != nil {
c.completionFailure("Error getting control plane pods: %s", err)
goto afterPodLogCollection
}
for _, pod := range pods.Items {
cmd := []string{"kubectl", "logs", "-n", pod.Namespace, pod.Name}
outPath := path.Join(c.rootNamespaceDirPath(), pod.Namespace, rootPodDirName, pod.Name, commandsDirName, strings.Join(cmd, "_"))
if err := runCmdAndWriteToFile(cmd, outPath); err != nil {
c.completionFailure("Error writing control pod logs: %s", err)
continue
}
c.completionSuccess("Collected report for Pod %s/%s", pod.Namespace, pod.Name)
if pod.Status.ContainerStatuses[0].RestartCount > 0 {
cmd = append(cmd, "--previous")
outPath = path.Join(c.rootNamespaceDirPath(), pod.Namespace, rootPodDirName, pod.Name, commandsDirName, strings.Join(cmd, "_"))
if err := runCmdAndWriteToFile(cmd, outPath); err != nil {
c.completionFailure("Error writing previous control pod logs: %s", err)
continue
}
c.completionSuccess("Collected previous report for Pod %s/%s", pod.Namespace, pod.Name)
}
}
afterPodLogCollection:
// Collect MeshConfig, secrets in control plane namespace
namespaceCmds := [][]string{
{"kubectl", "get", "meshconfig", "-n", c.ControlPlaneNamepace, "-o", "yaml"},
{"kubectl", "get", "secrets", "-n", c.ControlPlaneNamepace}, // Only collect names to avoid collecting sensitive info
}
for _, cmd := range namespaceCmds {
outPath := path.Join(c.rootNamespaceDirPath(), c.ControlPlaneNamepace, commandsDirName, strings.Join(cmd, "_"))
if err := runCmdAndWriteToFile(cmd, outPath); err != nil {
c.completionFailure("Error writing control namespace scoped report: %s", err)
continue
}
}
}