@@ -367,6 +367,13 @@ func (c *CollectClusterResources) Collect(progressChan chan<- interface{}) (Coll
367367 }
368368 output .SaveResult (c .BundlePath , path .Join (constants .CLUSTER_RESOURCES_DIR , fmt .Sprintf ("%s-errors.json" , constants .CLUSTER_RESOURCES_ENDPOINTS )), marshalErrors (endpointsErrors ))
369369
370+ // endpointslices
371+ endpointslices , endpointslicesErrors := endpointslices (ctx , client , namespaceNames )
372+ for k , v := range endpointslices {
373+ _ = output .SaveResult (c .BundlePath , path .Join (constants .CLUSTER_RESOURCES_DIR , constants .CLUSTER_RESOURCES_ENDPOINTSICES , k ), bytes .NewBuffer (v ))
374+ }
375+ _ = output .SaveResult (c .BundlePath , path .Join (constants .CLUSTER_RESOURCES_DIR , fmt .Sprintf ("%s-errors.json" , constants .CLUSTER_RESOURCES_ENDPOINTSICES )), marshalErrors (endpointslicesErrors ))
376+
370377 // Service Accounts
371378 servicesAccounts , servicesAccountsErrors := serviceAccounts (ctx , client , namespaceNames )
372379 for k , v := range servicesAccounts {
@@ -1983,6 +1990,42 @@ func endpoints(ctx context.Context, client *kubernetes.Clientset, namespaces []s
19831990 return endpointsByNamespace , errorsByNamespace
19841991}
19851992
1993+ func endpointslices (ctx context.Context , client * kubernetes.Clientset , namespaces []string ) (map [string ][]byte , map [string ]string ) {
1994+ objsByNamespace := make (map [string ][]byte )
1995+ errorsByNamespace := make (map [string ]string )
1996+
1997+ for _ , namespace := range namespaces {
1998+ objs , err := client .DiscoveryV1 ().EndpointSlices (namespace ).List (ctx , metav1.ListOptions {})
1999+ if err != nil {
2000+ errorsByNamespace [namespace ] = err .Error ()
2001+ continue
2002+ }
2003+
2004+ // TODO: Can we DRY this? We repeat this pattern a lot
2005+ gvk , err := apiutil .GVKForObject (objs , scheme .Scheme )
2006+ if err == nil {
2007+ objs .GetObjectKind ().SetGroupVersionKind (gvk )
2008+ }
2009+
2010+ for i , o := range objs .Items {
2011+ gvk , err := apiutil .GVKForObject (& o , scheme .Scheme )
2012+ if err == nil {
2013+ objs .Items [i ].GetObjectKind ().SetGroupVersionKind (gvk )
2014+ }
2015+ }
2016+
2017+ b , err := json .MarshalIndent (objs , "" , " " )
2018+ if err != nil {
2019+ errorsByNamespace [namespace ] = err .Error ()
2020+ continue
2021+ }
2022+
2023+ objsByNamespace [namespace + ".json" ] = b
2024+ }
2025+
2026+ return objsByNamespace , errorsByNamespace
2027+ }
2028+
19862029func serviceAccounts (ctx context.Context , client kubernetes.Interface , namespaces []string ) (map [string ][]byte , map [string ]string ) {
19872030 serviceAccountsByNamespace := make (map [string ][]byte )
19882031 errorsByNamespace := make (map [string ]string )
0 commit comments