Skip to content

Commit 236a960

Browse files
committed
gather PGUpgrade resource
1 parent 8fb0eea commit 236a960

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

internal/cmd/export.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,22 @@ Collecting PGO CLI logs...
561561
writeInfo(cmd, fmt.Sprintf("Error gathering kubectl plugins: %s", err))
562562
}
563563

564+
// Get PGUpgrade spec (if available)
565+
writeInfo(cmd, "Collecting PGUpgrade spec (if available)...")
566+
567+
key := util.AllowUpgradeAnnotation()
568+
value, exists := get.GetAnnotations()[key]
569+
570+
if exists {
571+
writeInfo(cmd, fmt.Sprintf("The PGUpgrade object is: %s", value))
572+
err = gatherPGUpgradeSpec(clusterName, namespace, value, tw, cmd)
573+
if err != nil {
574+
writeInfo(cmd, fmt.Sprintf("Error gathering PGUpgrade spec: %s", err))
575+
}
576+
} else {
577+
writeInfo(cmd, fmt.Sprintf("There is no PGUpgrade object associated with cluster '%s'", clusterName))
578+
}
579+
564580
// Print cli output
565581
writeInfo(cmd, "Collecting PGO CLI logs...")
566582
path := clusterName + "/cli.log"
@@ -594,6 +610,26 @@ func gatherPluginList(clusterName string, tw *tar.Writer, cmd *cobra.Command) er
594610
return nil
595611
}
596612

613+
func gatherPGUpgradeSpec(clusterName, namespace, pgUpgrade string, tw *tar.Writer, cmd *cobra.Command) error {
614+
ex := exec.Command("kubectl", "get", "pgupgrade", pgUpgrade, "-n", namespace, "-o", "yaml")
615+
msg, err := ex.Output()
616+
617+
if err != nil {
618+
msg = append(msg, err.Error()...)
619+
msg = append(msg, []byte(`
620+
There was an error running 'kubectl get pgupgrade'. Verify permissions and that the resource exists.`)...)
621+
622+
writeInfo(cmd, fmt.Sprintf("Error: '%s'", msg))
623+
}
624+
625+
path := clusterName + "/pgupgrade.yaml"
626+
if err := writeTar(tw, msg, path, cmd); err != nil {
627+
return err
628+
}
629+
630+
return nil
631+
}
632+
597633
// exportSizeReport defines the message displayed when a support export archive
598634
// is created. If the size of the archive file is greater than 25MiB, an alternate
599635
// message is displayed.

internal/util/naming.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,9 @@ func PostgresUserSecretLabels(clusterName string) string {
8989
return LabelCluster + "=" + clusterName + "," +
9090
LabelRole + "=" + RolePostgresUser
9191
}
92+
93+
// AllowUpgradeAnnotation is the annotation key to allow of PostgresCluster
94+
// to upgrade. Its value is the name of the PGUpgrade object.
95+
func AllowUpgradeAnnotation() string {
96+
return labelPrefix + "allow-upgrade"
97+
}

0 commit comments

Comments
 (0)