Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
52 changes: 47 additions & 5 deletions internal/cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,9 @@ Collecting PGO CLI logs...
return err
}

get, err := postgresClient.Namespace(namespace).Get(ctx,
getCluster, err := postgresClient.Namespace(namespace).Get(ctx,
clusterName, metav1.GetOptions{})
if err != nil || get == nil {
if err != nil || getCluster == nil {
if apierrors.IsForbidden(err) || apierrors.IsNotFound(err) {
return err
}
Expand Down Expand Up @@ -425,7 +425,7 @@ Collecting PGO CLI logs...
}

// Gather PostgresCluster manifest
err = gatherClusterSpec(get, clusterName, tw, cmd)
err = gatherClusterSpec(getCluster, clusterName, tw, cmd)
if err != nil {
writeInfo(cmd, fmt.Sprintf("Error gathering PostgresCluster manifest: %s", err))
}
Expand Down Expand Up @@ -462,7 +462,7 @@ Collecting PGO CLI logs...
// All Postgres Logs on the Postgres Instances (primary and replicas)
if numLogs > 0 {
err = gatherPostgresLogsAndConfigs(ctx, clientset, restConfig,
namespace, clusterName, outputDir, outputFile, numLogs, tw, cmd, get)
namespace, clusterName, outputDir, outputFile, numLogs, tw, cmd, getCluster)
if err != nil {
writeInfo(cmd, fmt.Sprintf("Error gathering Postgres Logs and Config: %s", err))
}
Expand Down 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 := getCluster.GetAnnotations()[key]

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")
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")
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"
}