Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion internal/cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,22 @@ Collecting PGO CLI logs...
writeInfo(cmd, fmt.Sprintf("Error gathering kubectl plugins: %s", err))
}

// Get PGUpgrade spec (if available)
writeInfo(cmd, "Collecting PGUpgrade spec (if available)...")

key := util.AllowUpgradeAnnotation()
value, exists := get.GetAnnotations()[key]
Comment thread
philrhurst marked this conversation as resolved.
Outdated

if exists {
writeInfo(cmd, fmt.Sprintf("The PGUpgrade object is: %s", value))
err = gatherPGUpgradeSpec(clusterName, namespace, value, tw, cmd)
if err != nil {
writeInfo(cmd, fmt.Sprintf("Error gathering PGUpgrade spec: %s", err))
}
} else {
writeInfo(cmd, fmt.Sprintf("There is no PGUpgrade object associated with cluster '%s'", clusterName))
}

// Print cli output
writeInfo(cmd, "Collecting PGO CLI logs...")
path := clusterName + "/cli.log"
Expand All @@ -579,7 +595,10 @@ Collecting PGO CLI logs...
}

func gatherPluginList(clusterName string, tw *tar.Writer, cmd *cobra.Command) error {
ex := exec.Command("kubectl", "plugin", "list")
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel() // Ensure the context is canceled to avoid leaks

ex := exec.CommandContext(ctx, "kubectl", "plugin", "list")
Comment thread
philrhurst marked this conversation as resolved.
msg, err := ex.Output()

if err != nil {
Expand All @@ -594,6 +613,29 @@ func gatherPluginList(clusterName string, tw *tar.Writer, cmd *cobra.Command) er
return nil
}

func gatherPGUpgradeSpec(clusterName, namespace, pgUpgrade string, tw *tar.Writer, cmd *cobra.Command) error {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel() // Ensure the context is canceled to avoid leaks

ex := exec.CommandContext(ctx, "kubectl", "get", "pgupgrade", pgUpgrade, "-n", namespace, "-o", "yaml")
Comment thread
tjmoore4 marked this conversation as resolved.
msg, err := ex.Output()

if err != nil {
msg = append(msg, err.Error()...)
msg = append(msg, []byte(`
There was an error running 'kubectl get pgupgrade'. Verify permissions and that the resource exists.`)...)

writeInfo(cmd, fmt.Sprintf("Error: '%s'", msg))
}

path := clusterName + "/pgupgrade.yaml"
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
6 changes: 6 additions & 0 deletions internal/util/naming.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,9 @@ func PostgresUserSecretLabels(clusterName string) string {
return LabelCluster + "=" + clusterName + "," +
LabelRole + "=" + RolePostgresUser
}

// AllowUpgradeAnnotation is the annotation key to allow of PostgresCluster
// to upgrade. Its value is the name of the PGUpgrade object.
func AllowUpgradeAnnotation() string {
return labelPrefix + "allow-upgrade"
}