Skip to content

Commit 0240a63

Browse files
authored
chore: Collect endpointslices resources (#1636)
Signed-off-by: Evans Mungai <[email protected]>
1 parent f58f025 commit 0240a63

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

pkg/collect/cluster_resources.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
19862029
func 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)

pkg/constants/constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const (
5656
CLUSTER_RESOURCES_CLUSTER_ROLE_BINDINGS = "clusterrolebindings"
5757
CLUSTER_RESOURCES_PRIORITY_CLASS = "priorityclasses"
5858
CLUSTER_RESOURCES_ENDPOINTS = "endpoints"
59+
CLUSTER_RESOURCES_ENDPOINTSICES = "endpointslices"
5960
CLUSTER_RESOURCES_SERVICE_ACCOUNTS = "serviceaccounts"
6061
CLUSTER_RESOURCES_LEASES = "leases"
6162
CLUSTER_RESOURCES_VOLUME_ATTACHMENTS = "volumeattachments"

0 commit comments

Comments
 (0)