From b24032519e2bb6398311ff9c7bb4d14c0503f080 Mon Sep 17 00:00:00 2001 From: Marc Campbell Date: Fri, 10 Jan 2020 17:41:20 +0000 Subject: [PATCH] Add limitranges to cluster-resource collector --- pkg/collect/cluster_resources.go | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/pkg/collect/cluster_resources.go b/pkg/collect/cluster_resources.go index 1e5efd85..e9a4f7f8 100644 --- a/pkg/collect/cluster_resources.go +++ b/pkg/collect/cluster_resources.go @@ -37,6 +37,8 @@ type ClusterResourcesOutput struct { Groups []byte `json:"cluster-resources/groups.json,omitempty"` Resources []byte `json:"cluster-resources/resources.json,omitempty"` GroupsResourcesErrors []byte `json:"cluster-resources/groups-resources-errors.json,omitempty"` + LimitRanges map[string][]byte `json:"cluster-resources/limitranges,omitempty"` + LimitRangesErrors []byte `json:"cluster-ressources/limitranges-errors.json,omitempty"` // TODO these should be considered for relocation to an rbac or auth package. cluster resources might not be the right place AuthCanI map[string][]byte `json:"cluster-resources/auth-cani-list,omitempty"` @@ -148,6 +150,14 @@ func ClusterResources(ctx *Context) ([]byte, error) { return nil, err } + // limit ranges + limitRanges, limitRangesErrors := limitRanges(client, namespaceNames) + clusterResourcesOutput.LimitRanges = limitRanges + clusterResourcesOutput.LimitRangesErrors, err = marshalNonNil(limitRangesErrors) + if err != nil { + return nil, err + } + // auth cani authCanI, authCanIErrors := authCanI(client, namespaceNames) clusterResourcesOutput.AuthCanI = authCanI @@ -371,6 +381,29 @@ func imagePullSecrets(client *kubernetes.Clientset, namespaces []string) (map[st return imagePullSecrets, errors } +func limitRanges(client *kubernetes.Clientset, namespaces []string) (map[string][]byte, map[string]string) { + limitRangesByNamespace := make(map[string][]byte) + errorsByNamespace := make(map[string]string) + + for _, namespace := range namespaces { + limitRanges, err := client.CoreV1().LimitRanges(namespace).List(metav1.ListOptions{}) + if err != nil { + errorsByNamespace[namespace] = err.Error() + continue + } + + b, err := json.MarshalIndent(limitRanges.Items, "", " ") + if err != nil { + errorsByNamespace[namespace] = err.Error() + continue + } + + limitRangesByNamespace[namespace+".json"] = b + } + + return limitRangesByNamespace, errorsByNamespace +} + func nodes(client *kubernetes.Clientset) ([]byte, []string) { nodes, err := client.CoreV1().Nodes().List(metav1.ListOptions{}) if err != nil { @@ -529,5 +562,7 @@ func (c *ClusterResourcesOutput) Redact() (*ClusterResourcesOutput, error) { Groups: groups, Resources: resources, GroupsResourcesErrors: c.GroupsResourcesErrors, + LimitRanges: c.LimitRanges, + LimitRangesErrors: c.LimitRangesErrors, }, nil }