Skip to content

Commit b1f1530

Browse files
Anthony Landrethtony-landreth
authored andcommitted
Adds kubectl plugin list to export
Issue: PGO-598
1 parent e758a86 commit b1f1530

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

docs/content/reference/pgo_support_export.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ kubectl pgo support export daisy --monitoring-namespace another-namespace --outp
6969
| The support export tool will collect information that is
7070
| commonly necessary for troubleshooting a PostgresCluster.
7171
| Note: No data or k8s secrets are collected.
72+
| However, kubectl is used to list plugins on the user's machine.
7273
└────────────────────────────────────────────────────────────────
7374
Collecting PGO CLI version...
7475
Collecting names and namespaces for PostgresClusters...
@@ -99,6 +100,7 @@ Collecting Patroni info...
99100
Collecting pgBackRest info...
100101
Collecting processes...
101102
Collecting system times from containers...
103+
Collecting list of kubectl plugins...
102104
Collecting PGO CLI logs...
103105
┌────────────────────────────────────────────────────────────────
104106
| Archive file size: 0.02 MiB

internal/cmd/export.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"fmt"
2323
"io"
2424
"os"
25+
"os/exec"
2526
"strings"
2627
"text/tabwriter"
2728
"time"
@@ -232,6 +233,7 @@ kubectl pgo support export daisy --monitoring-namespace another-namespace --outp
232233
| The support export tool will collect information that is
233234
| commonly necessary for troubleshooting a PostgresCluster.
234235
| Note: No data or k8s secrets are collected.
236+
| However, kubectl is used to list plugins on the user's machine.
235237
└────────────────────────────────────────────────────────────────
236238
Collecting PGO CLI version...
237239
Collecting names and namespaces for PostgresClusters...
@@ -262,6 +264,7 @@ Collecting Patroni info...
262264
Collecting pgBackRest info...
263265
Collecting processes...
264266
Collecting system times from containers...
267+
Collecting list of kubectl plugins...
265268
Collecting PGO CLI logs...
266269
┌────────────────────────────────────────────────────────────────
267270
| Archive file size: 0.02 MiB
@@ -449,6 +452,11 @@ Collecting PGO CLI logs...
449452
err = gatherSystemTime(ctx, clientset, restConfig, namespace, clusterName, tw, cmd)
450453
}
451454

455+
if err == nil {
456+
writeInfo(cmd, "Collecting list of kubectl plugins...")
457+
err = gatherPluginList(clusterName, tw, cmd)
458+
}
459+
452460
// Print cli output
453461
writeInfo(cmd, "Collecting PGO CLI logs...")
454462
path := clusterName + "/logs/cli"
@@ -471,6 +479,22 @@ Collecting PGO CLI logs...
471479
return cmd
472480
}
473481

482+
func gatherPluginList(clusterName string, tw *tar.Writer, cmd *cobra.Command) error {
483+
ex := exec.Command("kubectl", "plugin", "list")
484+
msg, err := ex.Output()
485+
486+
if err != nil {
487+
// Capture error message when kubectl is not found in $PATH.
488+
msg = append(msg, err.Error()...)
489+
}
490+
path := clusterName + "/plugin-list"
491+
if err := writeTar(tw, msg, path, cmd); err != nil {
492+
return err
493+
}
494+
495+
return nil
496+
}
497+
474498
// exportSizeReport defines the message displayed when a support export archive
475499
// is created. If the size of the archive file is greater than 25MiB, an alternate
476500
// message is displayed.

testing/kuttl/e2e/support-export/01--support_export.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ commands:
4343
# check that the pgbackrest info file exists and is not empty
4444
check_file "pgbackrest-info"
4545
46+
# check that the plugin list file exists and is not empty
47+
# the file will at least include kubectl-pgo
48+
check_file "plugin-list"
49+
4650
# check for expected gzip compression level
4751
FILE_INFO=$(file ./crunchy_k8s_support_export_*.tar.gz)
4852
[[ "${FILE_INFO}" == *'gzip compressed data, max compression'* ]] || {

0 commit comments

Comments
 (0)