Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
Add bug-report ability to collect control plane logs (#4365)
Browse files Browse the repository at this point in the history
Adds bug-report ability to collect control plane logs

Signed-off-by: Thomas Stringer <[email protected]>
  • Loading branch information
trstringer authored Nov 17, 2021
1 parent e5b2754 commit 81b5265
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
37 changes: 37 additions & 0 deletions pkg/bugreport/controlplane.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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() error {
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 {
return fmt.Errorf("error getting control plane pods: %w", err)
}

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 {
return fmt.Errorf("error writing control pod logs: %w", err)
}
c.completionSuccess("Collected report for Pod %s/%s", pod.Namespace, pod.Name)
}

return nil
}
9 changes: 9 additions & 0 deletions pkg/bugreport/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ func (c *Config) Run() error {
c.completionSuccess("Finished generating report for individual app pods")
c.endSection()

// Generate report for control plane pods
fmt.Fprintf(c.Stdout, "[+] Collecting information from control plane pods\n")
if err := c.collectControlPlaneLogs(); err != nil {
c.completionFailure("Error getting control plane logs")
return errors.Wrap(err, "Error getting control plane pods")
}
c.completionSuccess("Finished generating report for control plane pods")
c.endSection()

// Generate output file if not provided
if c.OutFile == "" {
outFd, err := ioutil.TempFile("", "*_osm-bug-report.tar.gz")
Expand Down

0 comments on commit 81b5265

Please sign in to comment.