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

Add limitranges to cluster-resource collector #116

Merged
merged 1 commit into from
Jan 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions pkg/collect/cluster_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -529,5 +562,7 @@ func (c *ClusterResourcesOutput) Redact() (*ClusterResourcesOutput, error) {
Groups: groups,
Resources: resources,
GroupsResourcesErrors: c.GroupsResourcesErrors,
LimitRanges: c.LimitRanges,
LimitRangesErrors: c.LimitRangesErrors,
}, nil
}