Skip to content

Commit 60d5b68

Browse files
authored
Add Daemonset collection to cluster_resources (#1213)
* added daemonset collection to cluster_resources * squash commit to remove commit that was submitted by root
1 parent f9dbccd commit 60d5b68

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

pkg/collect/cluster_resources.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,13 @@ func (c *CollectClusterResources) Collect(progressChan chan<- interface{}) (Coll
214214
}
215215
output.SaveResult(c.BundlePath, path.Join(constants.CLUSTER_RESOURCES_DIR, fmt.Sprintf("%s-errors.json", constants.CLUSTER_RESOURCES_STATEFULSETS)), marshalErrors(statefulsetsErrors))
216216

217+
// daemonsets
218+
daemonsets, daemonsetsErrors := daemonsets(ctx, client, namespaceNames)
219+
for k, v := range daemonsets {
220+
output.SaveResult(c.BundlePath, path.Join(constants.CLUSTER_RESOURCES_DIR, constants.CLUSTER_RESOURCES_DAEMONSETS, k), bytes.NewBuffer(v))
221+
}
222+
output.SaveResult(c.BundlePath, path.Join(constants.CLUSTER_RESOURCES_DIR, fmt.Sprintf("%s-errors.json", constants.CLUSTER_RESOURCES_DAEMONSETS)), marshalErrors(daemonsetsErrors))
223+
217224
// replicasets
218225
replicasets, replicasetsErrors := replicasets(ctx, client, namespaceNames)
219226
for k, v := range replicasets {
@@ -646,6 +653,42 @@ func statefulsets(ctx context.Context, client *kubernetes.Clientset, namespaces
646653
return statefulsetsByNamespace, errorsByNamespace
647654
}
648655

656+
func daemonsets(ctx context.Context, client *kubernetes.Clientset, namespaces []string) (map[string][]byte, map[string]string) {
657+
daemonsetsByNamespace := make(map[string][]byte)
658+
errorsByNamespace := make(map[string]string)
659+
660+
for _, namespace := range namespaces {
661+
daemonsets, err := client.AppsV1().DaemonSets(namespace).List(ctx, metav1.ListOptions{})
662+
663+
if err != nil {
664+
errorsByNamespace[namespace] = err.Error()
665+
continue
666+
}
667+
668+
gvk, err := apiutil.GVKForObject(daemonsets, scheme.Scheme)
669+
if err == nil {
670+
daemonsets.GetObjectKind().SetGroupVersionKind(gvk)
671+
}
672+
673+
for i, o := range daemonsets.Items {
674+
gvk, err := apiutil.GVKForObject(&o, scheme.Scheme)
675+
if err == nil {
676+
daemonsets.Items[i].GetObjectKind().SetGroupVersionKind(gvk)
677+
}
678+
}
679+
680+
b, err := json.MarshalIndent(daemonsets, "", " ")
681+
if err != nil {
682+
errorsByNamespace[namespace] = err.Error()
683+
continue
684+
}
685+
686+
daemonsetsByNamespace[namespace+".json"] = b
687+
}
688+
689+
return daemonsetsByNamespace, errorsByNamespace
690+
}
691+
649692
func replicasets(ctx context.Context, client *kubernetes.Clientset, namespaces []string) (map[string][]byte, map[string]string) {
650693
replicasetsByNamespace := make(map[string][]byte)
651694
errorsByNamespace := make(map[string]string)

pkg/constants/constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const (
3030
CLUSTER_RESOURCES_DEPLOYMENTS = "deployments"
3131
CLUSTER_RESOURCES_REPLICASETS = "replicasets"
3232
CLUSTER_RESOURCES_STATEFULSETS = "statefulsets"
33+
CLUSTER_RESOURCES_DAEMONSETS = "daemonsets"
3334
CLUSTER_RESOURCES_JOBS = "jobs"
3435
CLUSTER_RESOURCES_CRONJOBS = "cronjobs"
3536
CLUSTER_RESOURCES_INGRESS = "ingress"

0 commit comments

Comments
 (0)