Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

K8s events #248

Merged
merged 3 commits into from
Aug 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 additions & 0 deletions pkg/collect/cluster_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ func ClusterResources(c *Collector) (map[string][]byte, error) {
return nil, err
}

//Events
events, eventsErrors := events(ctx, client, namespaceNames)
for k, v := range events {
clusterResourcesOutput[path.Join("cluster-resources/events", k)] = v
}
clusterResourcesOutput["cluster-resources/events-errors.json"], err = marshalNonNil(eventsErrors)
if err != nil {
return nil, err
}

return clusterResourcesOutput, nil
}

Expand Down Expand Up @@ -478,6 +488,29 @@ func authCanI(ctx context.Context, client *kubernetes.Clientset, namespaces []st
return authListByNamespace, errorsByNamespace
}

func events(ctx context.Context, client *kubernetes.Clientset, namespaces []string) (map[string][]byte, map[string]string) {
eventsByNamespace := make(map[string][]byte)
errorsByNamespace := make(map[string]string)

for _, namespace := range namespaces {
events, err := client.CoreV1().Events(namespace).List(ctx, metav1.ListOptions{})
if err != nil {
errorsByNamespace[namespace] = err.Error()
continue
}

b, err := json.MarshalIndent(events.Items, "", " ")
if err != nil {
errorsByNamespace[namespace] = err.Error()
continue
}

eventsByNamespace[namespace+".json"] = b
}

return eventsByNamespace, errorsByNamespace
}

// not exprted from: https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/cmd/auth/cani.go#L339
func convertToPolicyRule(status authorizationv1.SubjectRulesReviewStatus) []rbacv1.PolicyRule {
ret := []rbacv1.PolicyRule{}
Expand Down