Skip to content

Commit b240325

Browse files
committed
Add limitranges to cluster-resource collector
1 parent 1ce5e7b commit b240325

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

pkg/collect/cluster_resources.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ type ClusterResourcesOutput struct {
3737
Groups []byte `json:"cluster-resources/groups.json,omitempty"`
3838
Resources []byte `json:"cluster-resources/resources.json,omitempty"`
3939
GroupsResourcesErrors []byte `json:"cluster-resources/groups-resources-errors.json,omitempty"`
40+
LimitRanges map[string][]byte `json:"cluster-resources/limitranges,omitempty"`
41+
LimitRangesErrors []byte `json:"cluster-ressources/limitranges-errors.json,omitempty"`
4042

4143
// TODO these should be considered for relocation to an rbac or auth package. cluster resources might not be the right place
4244
AuthCanI map[string][]byte `json:"cluster-resources/auth-cani-list,omitempty"`
@@ -148,6 +150,14 @@ func ClusterResources(ctx *Context) ([]byte, error) {
148150
return nil, err
149151
}
150152

153+
// limit ranges
154+
limitRanges, limitRangesErrors := limitRanges(client, namespaceNames)
155+
clusterResourcesOutput.LimitRanges = limitRanges
156+
clusterResourcesOutput.LimitRangesErrors, err = marshalNonNil(limitRangesErrors)
157+
if err != nil {
158+
return nil, err
159+
}
160+
151161
// auth cani
152162
authCanI, authCanIErrors := authCanI(client, namespaceNames)
153163
clusterResourcesOutput.AuthCanI = authCanI
@@ -371,6 +381,29 @@ func imagePullSecrets(client *kubernetes.Clientset, namespaces []string) (map[st
371381
return imagePullSecrets, errors
372382
}
373383

384+
func limitRanges(client *kubernetes.Clientset, namespaces []string) (map[string][]byte, map[string]string) {
385+
limitRangesByNamespace := make(map[string][]byte)
386+
errorsByNamespace := make(map[string]string)
387+
388+
for _, namespace := range namespaces {
389+
limitRanges, err := client.CoreV1().LimitRanges(namespace).List(metav1.ListOptions{})
390+
if err != nil {
391+
errorsByNamespace[namespace] = err.Error()
392+
continue
393+
}
394+
395+
b, err := json.MarshalIndent(limitRanges.Items, "", " ")
396+
if err != nil {
397+
errorsByNamespace[namespace] = err.Error()
398+
continue
399+
}
400+
401+
limitRangesByNamespace[namespace+".json"] = b
402+
}
403+
404+
return limitRangesByNamespace, errorsByNamespace
405+
}
406+
374407
func nodes(client *kubernetes.Clientset) ([]byte, []string) {
375408
nodes, err := client.CoreV1().Nodes().List(metav1.ListOptions{})
376409
if err != nil {
@@ -529,5 +562,7 @@ func (c *ClusterResourcesOutput) Redact() (*ClusterResourcesOutput, error) {
529562
Groups: groups,
530563
Resources: resources,
531564
GroupsResourcesErrors: c.GroupsResourcesErrors,
565+
LimitRanges: c.LimitRanges,
566+
LimitRangesErrors: c.LimitRangesErrors,
532567
}, nil
533568
}

0 commit comments

Comments
 (0)