Skip to content

Commit a562887

Browse files
authored
Add code to collect cluster endpoint data with cluster-resources collector (#1219)
added code to collect cluster endpoint data to cluster-resources collector
1 parent 620fa75 commit a562887

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

pkg/collect/cluster_resources.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,13 @@ func (c *CollectClusterResources) Collect(progressChan chan<- interface{}) (Coll
352352
output.SaveResult(c.BundlePath, path.Join(constants.CLUSTER_RESOURCES_DIR, fmt.Sprintf("%s.json", constants.CLUSTER_RESOURCES_CLUSTER_ROLE_BINDINGS)), bytes.NewBuffer(clusterRoleBindings))
353353
output.SaveResult(c.BundlePath, path.Join(constants.CLUSTER_RESOURCES_DIR, fmt.Sprintf("%s-errors.json", constants.CLUSTER_RESOURCES_CLUSTER_ROLE_BINDINGS)), marshalErrors(clusterRoleBindingsErrors))
354354

355+
// endpoints
356+
endpoints, endpointsErrors := endpoints(ctx, client, namespaceNames)
357+
for k, v := range endpoints {
358+
output.SaveResult(c.BundlePath, path.Join(constants.CLUSTER_RESOURCES_DIR, constants.CLUSTER_RESOURCES_ENDPOINTS, k), bytes.NewBuffer(v))
359+
}
360+
output.SaveResult(c.BundlePath, path.Join(constants.CLUSTER_RESOURCES_DIR, fmt.Sprintf("%s-errors.json", constants.CLUSTER_RESOURCES_ENDPOINTS)), marshalErrors(endpointsErrors))
361+
355362
return output, nil
356363
}
357364

@@ -1888,3 +1895,38 @@ func clusterRoleBindings(ctx context.Context, client *kubernetes.Clientset) ([]b
18881895
}
18891896
return b, nil
18901897
}
1898+
1899+
func endpoints(ctx context.Context, client *kubernetes.Clientset, namespaces []string) (map[string][]byte, map[string]string) {
1900+
endpointsByNamespace := make(map[string][]byte)
1901+
errorsByNamespace := make(map[string]string)
1902+
1903+
for _, namespace := range namespaces {
1904+
endpoints, err := client.CoreV1().Endpoints(namespace).List(ctx, metav1.ListOptions{})
1905+
if err != nil {
1906+
errorsByNamespace[namespace] = err.Error()
1907+
continue
1908+
}
1909+
1910+
gvk, err := apiutil.GVKForObject(endpoints, scheme.Scheme)
1911+
if err == nil {
1912+
endpoints.GetObjectKind().SetGroupVersionKind(gvk)
1913+
}
1914+
1915+
for i, o := range endpoints.Items {
1916+
gvk, err := apiutil.GVKForObject(&o, scheme.Scheme)
1917+
if err == nil {
1918+
endpoints.Items[i].GetObjectKind().SetGroupVersionKind(gvk)
1919+
}
1920+
}
1921+
1922+
b, err := json.MarshalIndent(endpoints, "", " ")
1923+
if err != nil {
1924+
errorsByNamespace[namespace] = err.Error()
1925+
continue
1926+
}
1927+
1928+
endpointsByNamespace[namespace+".json"] = b
1929+
}
1930+
1931+
return endpointsByNamespace, errorsByNamespace
1932+
}

pkg/constants/constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const (
5252
CLUSTER_RESOURCES_CLUSTER_ROLES = "clusterroles"
5353
CLUSTER_RESOURCES_CLUSTER_ROLE_BINDINGS = "clusterrolebindings"
5454
CLUSTER_RESOURCES_PRIORITY_CLASS = "priorityclasses"
55+
CLUSTER_RESOURCES_ENDPOINTS = "endpoints"
5556

5657
// Custom exit codes
5758
EXIT_CODE_CATCH_ALL = 1

0 commit comments

Comments
 (0)