@@ -624,10 +624,9 @@ Collecting PGO CLI logs...
624624 writeInfo (cmd , fmt .Sprintf ("Error running kubectl describe lease: %s" , err ))
625625 }
626626
627- writeInfo (cmd , "Running kubectl describe pgadmin..." )
628- err = runKubectlCommand (tw , cmd , "pgadmin/describe/pgadmin" , "describe" , "pgadmin" , "-n" , namespace )
627+ err = gatherPgadminResources (config , clientset , ctx , namespace , tw , cmd )
629628 if err != nil {
630- writeInfo (cmd , fmt .Sprintf ("Error running kubectl describe pgadmin : %s" , err ))
629+ writeInfo (cmd , fmt .Sprintf ("Error gathering PGAdmin Resources : %s" , err ))
631630 }
632631
633632 // Print cli output
@@ -647,6 +646,74 @@ Collecting PGO CLI logs...
647646 return cmd
648647}
649648
649+ func gatherPgadminResources (config * internal.Config ,
650+ clientset * kubernetes.Clientset ,
651+ ctx context.Context ,
652+ namespace string ,
653+ tw * tar.Writer , cmd * cobra.Command ) error {
654+
655+ _ , pgadminClient , err := v1beta1 .NewPgadminClient (config )
656+
657+ if err != nil {
658+ return err
659+ }
660+
661+ pgadmins , err := pgadminClient .Namespace (namespace ).List (ctx , metav1.ListOptions {})
662+ if err != nil {
663+ if apierrors .IsForbidden (err ) {
664+ writeInfo (cmd , err .Error ())
665+ return nil
666+ }
667+ return err
668+ }
669+
670+ if len (pgadmins .Items ) == 0 {
671+ // If we didn't find any resources, skip
672+ writeInfo (cmd , "Resource PGAdmin not found, skipping" )
673+ return nil
674+ }
675+
676+ // Create a buffer to generate string with the table formatted list
677+ var buf bytes.Buffer
678+ if err := printers .NewTablePrinter (printers.PrintOptions {}).
679+ PrintObj (pgadmins , & buf ); err != nil {
680+ return err
681+ }
682+
683+ // Define the file name/path where the list file will be created and
684+ // write to the tar
685+ path := "pgadmin" + "/list"
686+ if err := writeTar (tw , buf .Bytes (), path , cmd ); err != nil {
687+ return err
688+ }
689+
690+ for _ , obj := range pgadmins .Items {
691+ b , err := yaml .Marshal (obj )
692+ if err != nil {
693+ return err
694+ }
695+
696+ path := "pgadmin" + "/" + obj .GetName () + ".yaml"
697+ if err := writeTar (tw , b , path , cmd ); err != nil {
698+ return err
699+ }
700+
701+ writeInfo (cmd , "Collecting PGAdmin pod logs..." )
702+ err = gatherPodLogs (ctx , clientset , namespace , fmt .Sprintf ("%s=%s" , util .LabelPgadmin , obj .GetName ()), "pgadmin" , tw , cmd )
703+ if err != nil {
704+ writeInfo (cmd , fmt .Sprintf ("Error gathering PGAdmin pod logs: %s" , err ))
705+ }
706+
707+ writeInfo (cmd , "Running kubectl describe pgadmin" )
708+ err = runKubectlCommand (tw , cmd , "pgadmin/describe/" + obj .GetName (), "describe" , "pgadmin" , obj .GetName (), "-n" , namespace )
709+ if err != nil {
710+ writeInfo (cmd , fmt .Sprintf ("Error running kubectl describe pgadmin: %s" , err ))
711+ }
712+ }
713+
714+ return nil
715+ }
716+
650717func gatherPluginList (clusterName string , tw * tar.Writer , cmd * cobra.Command ) error {
651718 ctx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
652719 defer cancel () // Ensure the context is canceled to avoid leaks
0 commit comments