Skip to content

Commit

Permalink
Adds kubectl plugin list to export
Browse files Browse the repository at this point in the history
Issue: PGO-598
  • Loading branch information
Anthony Landreth committed Nov 6, 2023
1 parent 94f6057 commit 5b75612
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion docs/content/reference/pgo_support_export.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ kubectl pgo support export daisy --monitoring-namespace another-namespace --outp
| PGO CLI Support Export Tool
| The support export tool will collect information that is
| commonly necessary for troubleshooting a PostgresCluster.
| Note: No data or k8s secrets are collected.
| Note: No data or k8s secrets are collected, however,
| kubectl is used to list plugins on the user's machine.
└────────────────────────────────────────────────────────────────
Collecting PGO CLI version...
Collecting names and namespaces for PostgresClusters...
Expand Down Expand Up @@ -99,6 +100,7 @@ Collecting Patroni info...
Collecting pgBackRest info...
Collecting processes...
Collecting system times from containers...
Collecting list of kubectl plugins...
Collecting PGO CLI logs...
┌────────────────────────────────────────────────────────────────
| Archive file size: 0.02 MiB
Expand Down
24 changes: 24 additions & 0 deletions internal/cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"io"
"os"
"os/exec"
"strings"
"text/tabwriter"
"time"
Expand Down Expand Up @@ -232,6 +233,7 @@ kubectl pgo support export daisy --monitoring-namespace another-namespace --outp
| The support export tool will collect information that is
| commonly necessary for troubleshooting a PostgresCluster.
| Note: No data or k8s secrets are collected.
| However, kubectl is used to list plugins on the user's machine.
└────────────────────────────────────────────────────────────────
Collecting PGO CLI version...
Collecting names and namespaces for PostgresClusters...
Expand Down Expand Up @@ -262,6 +264,7 @@ Collecting Patroni info...
Collecting pgBackRest info...
Collecting processes...
Collecting system times from containers...
Collecting list of kubectl plugins...
Collecting PGO CLI logs...
┌────────────────────────────────────────────────────────────────
| Archive file size: 0.02 MiB
Expand Down Expand Up @@ -449,6 +452,11 @@ Collecting PGO CLI logs...
err = gatherSystemTime(ctx, clientset, restConfig, namespace, clusterName, tw, cmd)
}

if err == nil {
writeInfo(cmd, "Collecting list of kubectl plugins...")
err = gatherPluginList(clusterName, tw, cmd)
}

// Print cli output
writeInfo(cmd, "Collecting PGO CLI logs...")
path := clusterName + "/logs/cli"
Expand All @@ -471,6 +479,22 @@ Collecting PGO CLI logs...
return cmd
}

func gatherPluginList(clusterName string, tw *tar.Writer, cmd *cobra.Command) error {
ex := exec.Command("kubectl", "plugin", "list")
msg, err := ex.Output()

if err != nil {
// Capture error message when kubectl is not found in $PATH.
msg = append(msg, err.Error()...)
}
path := clusterName + "/plugin-list"
if err := writeTar(tw, msg, path, cmd); err != nil {
return err
}

return nil
}

// exportSizeReport defines the message displayed when a support export archive
// is created. If the size of the archive file is greater than 25MiB, an alternate
// message is displayed.
Expand Down
4 changes: 4 additions & 0 deletions testing/kuttl/e2e/support-export/01--support_export.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ commands:
# check that the pgbackrest info file exists and is not empty
check_file "pgbackrest-info"
# check that the plugin list file exists and is not empty
# the file will at least include kubectl-pgo
check_file "plugin-list"
# check for expected gzip compression level
FILE_INFO=$(file ./crunchy_k8s_support_export_*.tar.gz)
[[ "${FILE_INFO}" == *'gzip compressed data, max compression'* ]] || {
Expand Down

0 comments on commit 5b75612

Please sign in to comment.