Skip to content

Commit

Permalink
Collect statefulsets (#123)
Browse files Browse the repository at this point in the history
* Collect statefulsets

* go version
  • Loading branch information
emosbaugh authored Jan 23, 2020
1 parent 58b6424 commit 8eddab6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/analyze/statefulset_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func analyzeStatefulsetStatus(analyzer *troubleshootv1beta1.StatefulsetStatus, getCollectedFileContents func(string) ([]byte, error)) (*AnalyzeResult, error) {
collected, err := getCollectedFileContents(path.Join("cluster-resources", "statefulsets", fmt.Sprintf("%s.json", analyzer.Namespace)))
if err != nil {
return nil, errors.Wrap(err, "failed to read collected deployments from namespace")
return nil, errors.Wrap(err, "failed to read collected statefulsets from namespace")
}

var statefulsets []appsv1.StatefulSet
Expand Down
39 changes: 39 additions & 0 deletions pkg/collect/cluster_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type ClusterResourcesOutput struct {
ServicesErrors []byte `json:"cluster-resources/services-errors.json,omitempty"`
Deployments map[string][]byte `json:"cluster-resources/deployments,omitempty"`
DeploymentsErrors []byte `json:"cluster-resources/deployments-errors.json,omitempty"`
StatefulSets map[string][]byte `json:"cluster-resources/statefulsets,omitempty"`
StatefulSetsErrors []byte `json:"cluster-resources/statefulsets-errors.json,omitempty"`
Ingress map[string][]byte `json:"cluster-resources/ingress,omitempty"`
IngressErrors []byte `json:"cluster-resources/ingress-errors.json,omitempty"`
StorageClasses []byte `json:"cluster-resources/storage-classes.json,omitempty"`
Expand Down Expand Up @@ -98,6 +100,14 @@ func ClusterResources(ctx *Context) ([]byte, error) {
return nil, err
}

// statefulsets
statefulsets, statefulsetsErrors := statefulsets(client, namespaceNames)
clusterResourcesOutput.StatefulSets = statefulsets
clusterResourcesOutput.StatefulSetsErrors, err = marshalNonNil(statefulsetsErrors)
if err != nil {
return nil, err
}

// ingress
ingress, ingressErrors := ingress(client, namespaceNames)
clusterResourcesOutput.Ingress = ingress
Expand Down Expand Up @@ -278,6 +288,29 @@ func deployments(client *kubernetes.Clientset, namespaces []string) (map[string]
return deploymentsByNamespace, errorsByNamespace
}

func statefulsets(client *kubernetes.Clientset, namespaces []string) (map[string][]byte, map[string]string) {
statefulsetsByNamespace := make(map[string][]byte)
errorsByNamespace := make(map[string]string)

for _, namespace := range namespaces {
statefulsets, err := client.AppsV1().StatefulSets(namespace).List(metav1.ListOptions{})
if err != nil {
errorsByNamespace[namespace] = err.Error()
continue
}

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

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

return statefulsetsByNamespace, errorsByNamespace
}

func ingress(client *kubernetes.Clientset, namespaces []string) (map[string][]byte, map[string]string) {
ingressByNamespace := make(map[string][]byte)
errorsByNamespace := make(map[string]string)
Expand Down Expand Up @@ -513,6 +546,10 @@ func (c *ClusterResourcesOutput) Redact() (*ClusterResourcesOutput, error) {
if err != nil {
return nil, err
}
statefulsets, err := redactMap(c.StatefulSets)
if err != nil {
return nil, err
}
ingress, err := redactMap(c.Ingress)
if err != nil {
return nil, err
Expand Down Expand Up @@ -545,6 +582,8 @@ func (c *ClusterResourcesOutput) Redact() (*ClusterResourcesOutput, error) {
ServicesErrors: c.ServicesErrors,
Deployments: deployments,
DeploymentsErrors: c.DeploymentsErrors,
StatefulSets: statefulsets,
StatefulSetsErrors: c.StatefulSetsErrors,
Ingress: ingress,
IngressErrors: c.IngressErrors,
StorageClasses: storageClasses,
Expand Down

0 comments on commit 8eddab6

Please sign in to comment.