Skip to content

Commit ce53dbc

Browse files
authored
Merge pull request #330 from replicatedhq/pv-pvc
add pv and pvcs to support bundle
2 parents 7589b4f + 3b10d9c commit ce53dbc

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

pkg/collect/cluster_resources.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,24 @@ func ClusterResources(c *Collector) (map[string][]byte, error) {
173173
return nil, err
174174
}
175175

176+
//Persistent Volumes
177+
pvs, pvsErrors := pvs(ctx, client)
178+
clusterResourcesOutput["cluster-resources/pvs.json"] = pvs
179+
clusterResourcesOutput["cluster-resources/pvs-errors.json"], err = marshalNonNil(pvsErrors)
180+
if err != nil {
181+
return nil, err
182+
}
183+
184+
//Persistent Volume Claims
185+
pvcs, pvcsErrors := pvcs(ctx, client, namespaceNames)
186+
for k, v := range pvcs {
187+
clusterResourcesOutput[path.Join("cluster-resources/pvcs", k)] = v
188+
}
189+
clusterResourcesOutput["cluster-resources/pvcs-errors.json"], err = marshalNonNil(pvcsErrors)
190+
if err != nil {
191+
return nil, err
192+
}
193+
176194
return clusterResourcesOutput, nil
177195
}
178196

@@ -532,3 +550,39 @@ func convertToPolicyRule(status authorizationv1.SubjectRulesReviewStatus) []rbac
532550

533551
return ret
534552
}
553+
554+
func pvs(ctx context.Context, client *kubernetes.Clientset) ([]byte, []string) {
555+
pv, err := client.CoreV1().PersistentVolumes().List(ctx, metav1.ListOptions{})
556+
if err != nil {
557+
return nil, []string{err.Error()}
558+
}
559+
560+
b, err := json.MarshalIndent(pv.Items, "", " ")
561+
if err != nil {
562+
return nil, []string{err.Error()}
563+
}
564+
return b, nil
565+
}
566+
567+
func pvcs(ctx context.Context, client *kubernetes.Clientset, namespaces []string) (map[string][]byte, map[string]string) {
568+
pvcsByNamespace := make(map[string][]byte)
569+
errorsByNamespace := make(map[string]string)
570+
571+
for _, namespace := range namespaces {
572+
pvcs, err := client.CoreV1().PersistentVolumeClaims(namespace).List(ctx, metav1.ListOptions{})
573+
if err != nil {
574+
errorsByNamespace[namespace] = err.Error()
575+
continue
576+
}
577+
578+
b, err := json.MarshalIndent(pvcs.Items, "", " ")
579+
if err != nil {
580+
errorsByNamespace[namespace] = err.Error()
581+
continue
582+
}
583+
584+
pvcsByNamespace[namespace+".json"] = b
585+
}
586+
587+
return pvcsByNamespace, errorsByNamespace
588+
}

0 commit comments

Comments
 (0)