diff --git a/docs/content/reference/pgo_support_export.md b/docs/content/reference/pgo_support_export.md index 19e021de..5130dd3e 100644 --- a/docs/content/reference/pgo_support_export.md +++ b/docs/content/reference/pgo_support_export.md @@ -71,6 +71,7 @@ kubectl pgo support export daisy --monitoring-namespace another-namespace --outp | Note: No data or k8s secrets are collected. └──────────────────────────────────────────────────────────────── Collecting PGO CLI version... +Collecting names and namespaces for PostgresClusters... Collecting current Kubernetes context... Collecting Kubernetes version... Collecting nodes... diff --git a/internal/cmd/export.go b/internal/cmd/export.go index db609e2c..4502c270 100644 --- a/internal/cmd/export.go +++ b/internal/cmd/export.go @@ -234,6 +234,7 @@ kubectl pgo support export daisy --monitoring-namespace another-namespace --outp | Note: No data or k8s secrets are collected. └──────────────────────────────────────────────────────────────── Collecting PGO CLI version... +Collecting names and namespaces for PostgresClusters... Collecting current Kubernetes context... Collecting Kubernetes version... Collecting nodes... @@ -315,6 +316,7 @@ Collecting PGO CLI logs... if err != nil { return err } + get, err := postgresClient.Namespace(namespace).Get(ctx, clusterName, metav1.GetOptions{}) if err != nil || get == nil { @@ -355,6 +357,10 @@ Collecting PGO CLI logs... // PGO CLI version err = gatherPGOCLIVersion(ctx, clusterName, tw, cmd) + if err == nil { + err = gatherPostgresClusterNames(clusterName, ctx, cmd, tw, postgresClient) + } + // Current Kubernetes context if err == nil { err = gatherKubeContext(ctx, config, clusterName, tw, cmd) @@ -484,6 +490,40 @@ func gatherPGOCLIVersion(_ context.Context, return nil } +func gatherPostgresClusterNames(clusterName string, ctx context.Context, cmd *cobra.Command, tw *tar.Writer, client dynamic.NamespaceableResourceInterface) error { + result, err := client.List(ctx, metav1.ListOptions{}) + + if err != nil { + return err + } + + data := []byte{} + for _, item := range result.Items { + ns, found, err := unstructured.NestedString(item.Object, "metadata", "namespace") + if !found { + return fmt.Errorf("key not found: metadata.namespace") + } + if err != nil { + return err + } + name, found, err := unstructured.NestedString(item.Object, "metadata", "name") + if !found { + return fmt.Errorf("key not found: metadata.name") + } + if err != nil { + return err + } + data = append(data, []byte("Namespace: "+ns+"\t"+"Cluster: "+name+"\n")...) + } + + path := clusterName + "/cluster-names" + if err := writeTar(tw, data, path, cmd); err != nil { + return err + } + + return nil +} + // gatherKubeContext collects the current Kubernetes context func gatherKubeContext(_ context.Context, config *internal.Config, diff --git a/testing/kuttl/e2e/support-export/01--support_export.yaml b/testing/kuttl/e2e/support-export/01--support_export.yaml index 9d94400f..a1a0af68 100644 --- a/testing/kuttl/e2e/support-export/01--support_export.yaml +++ b/testing/kuttl/e2e/support-export/01--support_export.yaml @@ -18,6 +18,14 @@ commands: exit 1 } + # check that the cluster-names file exist and is not empty + if [[ ! -s ./kuttl-support-cluster/cluster-names ]] + then + echo "Expected cluster-names file to not be empty" + eval "$CLEANUP" + exit 1 + fi + # check that the context file exist and is not empty if [[ ! -s ./kuttl-support-cluster/current-context ]] then @@ -26,7 +34,6 @@ commands: exit 1 fi - # check for expected gzip compression level FILE_INFO=$(file ./crunchy_k8s_support_export_*.tar.gz) [[ "${FILE_INFO}" == *'gzip compressed data, max compression'* ]] || {