@@ -351,9 +351,9 @@ Collecting PGO CLI logs...
351
351
return err
352
352
}
353
353
354
- get , err := postgresClient .Namespace (namespace ).Get (ctx ,
354
+ getCluster , err := postgresClient .Namespace (namespace ).Get (ctx ,
355
355
clusterName , metav1.GetOptions {})
356
- if err != nil || get == nil {
356
+ if err != nil || getCluster == nil {
357
357
if apierrors .IsForbidden (err ) || apierrors .IsNotFound (err ) {
358
358
return err
359
359
}
@@ -425,7 +425,7 @@ Collecting PGO CLI logs...
425
425
}
426
426
427
427
// Gather PostgresCluster manifest
428
- err = gatherClusterSpec (get , clusterName , tw , cmd )
428
+ err = gatherClusterSpec (getCluster , clusterName , tw , cmd )
429
429
if err != nil {
430
430
writeInfo (cmd , fmt .Sprintf ("Error gathering PostgresCluster manifest: %s" , err ))
431
431
}
@@ -462,7 +462,7 @@ Collecting PGO CLI logs...
462
462
// All Postgres Logs on the Postgres Instances (primary and replicas)
463
463
if numLogs > 0 {
464
464
err = gatherPostgresLogsAndConfigs (ctx , clientset , restConfig ,
465
- namespace , clusterName , outputDir , outputFile , numLogs , tw , cmd , get )
465
+ namespace , clusterName , outputDir , outputFile , numLogs , tw , cmd , getCluster )
466
466
if err != nil {
467
467
writeInfo (cmd , fmt .Sprintf ("Error gathering Postgres Logs and Config: %s" , err ))
468
468
}
@@ -561,6 +561,22 @@ Collecting PGO CLI logs...
561
561
writeInfo (cmd , fmt .Sprintf ("Error gathering kubectl plugins: %s" , err ))
562
562
}
563
563
564
+ // Get PGUpgrade spec (if available)
565
+ writeInfo (cmd , "Collecting PGUpgrade spec (if available)..." )
566
+
567
+ key := util .AllowUpgradeAnnotation ()
568
+ value , exists := getCluster .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
+
564
580
// Print cli output
565
581
writeInfo (cmd , "Collecting PGO CLI logs..." )
566
582
path := clusterName + "/cli.log"
@@ -579,7 +595,10 @@ Collecting PGO CLI logs...
579
595
}
580
596
581
597
func gatherPluginList (clusterName string , tw * tar.Writer , cmd * cobra.Command ) error {
582
- ex := exec .Command ("kubectl" , "plugin" , "list" )
598
+ ctx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
599
+ defer cancel () // Ensure the context is canceled to avoid leaks
600
+
601
+ ex := exec .CommandContext (ctx , "kubectl" , "plugin" , "list" )
583
602
msg , err := ex .Output ()
584
603
585
604
if err != nil {
@@ -594,6 +613,29 @@ func gatherPluginList(clusterName string, tw *tar.Writer, cmd *cobra.Command) er
594
613
return nil
595
614
}
596
615
616
+ func gatherPGUpgradeSpec (clusterName , namespace , pgUpgrade string , tw * tar.Writer , cmd * cobra.Command ) error {
617
+ ctx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
618
+ defer cancel () // Ensure the context is canceled to avoid leaks
619
+
620
+ ex := exec .CommandContext (ctx , "kubectl" , "get" , "pgupgrade" , pgUpgrade , "-n" , namespace , "-o" , "yaml" )
621
+ msg , err := ex .Output ()
622
+
623
+ if err != nil {
624
+ msg = append (msg , err .Error ()... )
625
+ msg = append (msg , []byte (`
626
+ There was an error running 'kubectl get pgupgrade'. Verify permissions and that the resource exists.` )... )
627
+
628
+ writeInfo (cmd , fmt .Sprintf ("Error: '%s'" , msg ))
629
+ }
630
+
631
+ path := clusterName + "/pgupgrade.yaml"
632
+ if err := writeTar (tw , msg , path , cmd ); err != nil {
633
+ return err
634
+ }
635
+
636
+ return nil
637
+ }
638
+
597
639
// exportSizeReport defines the message displayed when a support export archive
598
640
// is created. If the size of the archive file is greater than 25MiB, an alternate
599
641
// message is displayed.
0 commit comments