@@ -365,6 +365,32 @@ func (c *CollectClusterResources) Collect(progressChan chan<- interface{}) (Coll
365365 }
366366 output .SaveResult (c .BundlePath , path .Join (constants .CLUSTER_RESOURCES_DIR , fmt .Sprintf ("%s-errors.json" , constants .CLUSTER_RESOURCES_ENDPOINTS )), marshalErrors (endpointsErrors ))
367367
368+ // Service Accounts
369+ servicesAccounts , servicesAccountsErrors := serviceAccounts (ctx , client , namespaceNames )
370+ for k , v := range servicesAccounts {
371+ output .SaveResult (c .BundlePath , path .Join (constants .CLUSTER_RESOURCES_DIR , constants .CLUSTER_RESOURCES_SERVICE_ACCOUNTS , k ), bytes .NewBuffer (v ))
372+ }
373+ output .SaveResult (c .BundlePath , path .Join (constants .CLUSTER_RESOURCES_DIR , fmt .Sprintf ("%s-errors.json" , constants .CLUSTER_RESOURCES_SERVICE_ACCOUNTS )), marshalErrors (servicesAccountsErrors ))
374+
375+ // Leases
376+ leases , leasesErrors := leases (ctx , client , namespaceNames )
377+ for k , v := range leases {
378+ output .SaveResult (c .BundlePath , path .Join (constants .CLUSTER_RESOURCES_DIR , constants .CLUSTER_RESOURCES_LEASES , k ), bytes .NewBuffer (v ))
379+ }
380+ output .SaveResult (c .BundlePath , path .Join (constants .CLUSTER_RESOURCES_DIR , fmt .Sprintf ("%s-errors.json" , constants .CLUSTER_RESOURCES_LEASES )), marshalErrors (leasesErrors ))
381+
382+ // Volume Attachments
383+ volumeAttachments , volumeAttachmentsErrors := volumeAttachments (ctx , client )
384+ output .SaveResult (c .BundlePath , path .Join (constants .CLUSTER_RESOURCES_DIR , fmt .Sprintf ("%s.json" , constants .CLUSTER_RESOURCES_VOLUME_ATTACHMENTS )), bytes .NewBuffer (volumeAttachments ))
385+ output .SaveResult (c .BundlePath , path .Join (constants .CLUSTER_RESOURCES_DIR , fmt .Sprintf ("%s-errors.json" , constants .CLUSTER_RESOURCES_VOLUME_ATTACHMENTS )), marshalErrors (volumeAttachmentsErrors ))
386+
387+ // ConfigMaps
388+ configMaps , configMapsErrors := configMaps (ctx , client , namespaceNames )
389+ for k , v := range configMaps {
390+ output .SaveResult (c .BundlePath , path .Join (constants .CLUSTER_RESOURCES_DIR , constants .CLUSTER_RESOURCES_CONFIGMAPS , k ), bytes .NewBuffer (v ))
391+ }
392+
393+ output .SaveResult (c .BundlePath , path .Join (constants .CLUSTER_RESOURCES_DIR , fmt .Sprintf ("%s-errors.json" , constants .CLUSTER_RESOURCES_CONFIGMAPS )), marshalErrors (configMapsErrors ))
368394 return output , nil
369395}
370396
@@ -1949,3 +1975,134 @@ func endpoints(ctx context.Context, client *kubernetes.Clientset, namespaces []s
19491975
19501976 return endpointsByNamespace , errorsByNamespace
19511977}
1978+
1979+ func serviceAccounts (ctx context.Context , client kubernetes.Interface , namespaces []string ) (map [string ][]byte , map [string ]string ) {
1980+ serviceAccountsByNamespace := make (map [string ][]byte )
1981+ errorsByNamespace := make (map [string ]string )
1982+
1983+ for _ , namespace := range namespaces {
1984+ serviceAccounts , err := client .CoreV1 ().ServiceAccounts (namespace ).List (ctx , metav1.ListOptions {})
1985+ if err != nil {
1986+ errorsByNamespace [namespace ] = err .Error ()
1987+ continue
1988+ }
1989+
1990+ gvk , err := apiutil .GVKForObject (serviceAccounts , scheme .Scheme )
1991+ if err == nil {
1992+ serviceAccounts .GetObjectKind ().SetGroupVersionKind (gvk )
1993+ }
1994+
1995+ for i , o := range serviceAccounts .Items {
1996+ gvk , err := apiutil .GVKForObject (& o , scheme .Scheme )
1997+ if err == nil {
1998+ serviceAccounts .Items [i ].GetObjectKind ().SetGroupVersionKind (gvk )
1999+ }
2000+ }
2001+
2002+ b , err := json .MarshalIndent (serviceAccounts , "" , " " )
2003+ if err != nil {
2004+ errorsByNamespace [namespace ] = err .Error ()
2005+ continue
2006+ }
2007+
2008+ serviceAccountsByNamespace [namespace + ".json" ] = b
2009+ }
2010+
2011+ return serviceAccountsByNamespace , errorsByNamespace
2012+ }
2013+
2014+ func leases (ctx context.Context , client kubernetes.Interface , namespaces []string ) (map [string ][]byte , map [string ]string ) {
2015+ leasesByNamespace := make (map [string ][]byte )
2016+ errorsByNamespace := make (map [string ]string )
2017+
2018+ for _ , namespace := range namespaces {
2019+ leases , err := client .CoordinationV1 ().Leases (namespace ).List (ctx , metav1.ListOptions {})
2020+ if err != nil {
2021+ errorsByNamespace [namespace ] = err .Error ()
2022+ continue
2023+ }
2024+
2025+ gvk , err := apiutil .GVKForObject (leases , scheme .Scheme )
2026+ if err == nil {
2027+ leases .GetObjectKind ().SetGroupVersionKind (gvk )
2028+ }
2029+
2030+ for i , o := range leases .Items {
2031+ gvk , err := apiutil .GVKForObject (& o , scheme .Scheme )
2032+ if err == nil {
2033+ leases .Items [i ].GetObjectKind ().SetGroupVersionKind (gvk )
2034+ }
2035+ }
2036+
2037+ b , err := json .MarshalIndent (leases , "" , " " )
2038+ if err != nil {
2039+ errorsByNamespace [namespace ] = err .Error ()
2040+ continue
2041+ }
2042+
2043+ leasesByNamespace [namespace + ".json" ] = b
2044+ }
2045+
2046+ return leasesByNamespace , errorsByNamespace
2047+ }
2048+
2049+ func volumeAttachments (ctx context.Context , client kubernetes.Interface ) ([]byte , []string ) {
2050+ volumeAttachments , err := client .StorageV1 ().VolumeAttachments ().List (ctx , metav1.ListOptions {})
2051+ if err != nil {
2052+ return nil , []string {err .Error ()}
2053+ }
2054+
2055+ gvk , err := apiutil .GVKForObject (volumeAttachments , scheme .Scheme )
2056+ if err == nil {
2057+ volumeAttachments .GetObjectKind ().SetGroupVersionKind (gvk )
2058+ }
2059+
2060+ for i , o := range volumeAttachments .Items {
2061+ gvk , err := apiutil .GVKForObject (& o , scheme .Scheme )
2062+ if err == nil {
2063+ volumeAttachments .Items [i ].GetObjectKind ().SetGroupVersionKind (gvk )
2064+ }
2065+ }
2066+
2067+ b , err := json .MarshalIndent (volumeAttachments , "" , " " )
2068+ if err != nil {
2069+ return nil , []string {err .Error ()}
2070+ }
2071+
2072+ return b , nil
2073+ }
2074+
2075+ func configMaps (ctx context.Context , client kubernetes.Interface , namespaces []string ) (map [string ][]byte , map [string ]string ) {
2076+ configmapByNamespace := make (map [string ][]byte )
2077+ errorsByNamespace := make (map [string ]string )
2078+
2079+ for _ , namespace := range namespaces {
2080+ configmaps , err := client .CoreV1 ().ConfigMaps (namespace ).List (ctx , metav1.ListOptions {})
2081+ if err != nil {
2082+ errorsByNamespace [namespace ] = err .Error ()
2083+ continue
2084+ }
2085+
2086+ gvk , err := apiutil .GVKForObject (configmaps , scheme .Scheme )
2087+ if err == nil {
2088+ configmaps .GetObjectKind ().SetGroupVersionKind (gvk )
2089+ }
2090+
2091+ for i , o := range configmaps .Items {
2092+ gvk , err := apiutil .GVKForObject (& o , scheme .Scheme )
2093+ if err == nil {
2094+ configmaps .Items [i ].GetObjectKind ().SetGroupVersionKind (gvk )
2095+ }
2096+ }
2097+
2098+ b , err := json .MarshalIndent (configmaps , "" , " " )
2099+ if err != nil {
2100+ errorsByNamespace [namespace ] = err .Error ()
2101+ continue
2102+ }
2103+
2104+ configmapByNamespace [namespace + ".json" ] = b
2105+ }
2106+
2107+ return configmapByNamespace , errorsByNamespace
2108+ }
0 commit comments