Skip to content

Commit 5145521

Browse files
committed
feat: add job to collect roles and rolebindings
1 parent 67a47df commit 5145521

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

pkg/jobs/job_list.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,40 @@ func JobList() []Job {
203203
ch <- jobResult
204204
},
205205
},
206+
{
207+
Name: "roles-list",
208+
Timeout: time.Second * 10,
209+
Execute: func(dc *data_collector.DataCollector, ctx context.Context, ch chan JobResult) {
210+
jobResult := JobResult{Files: make(map[string][]byte), Error: nil}
211+
for _, namespace := range dc.Namespaces {
212+
result, err := dc.K8sCoreClientSet.RbacV1().Roles(namespace).List(ctx, metav1.ListOptions{})
213+
if err != nil {
214+
dc.Logger.Printf("\tCould not retrieve roles list for namespace %s: %v\n", namespace, err)
215+
} else {
216+
jsonResult, _ := json.MarshalIndent(result, "", " ")
217+
jobResult.Files[path.Join(dc.BaseDir, "k8s", "rbac", namespace, "roles.json")] = jsonResult
218+
}
219+
}
220+
ch <- jobResult
221+
},
222+
},
223+
{
224+
Name: "rolebindings-list",
225+
Timeout: time.Second * 10,
226+
Execute: func(dc *data_collector.DataCollector, ctx context.Context, ch chan JobResult) {
227+
jobResult := JobResult{Files: make(map[string][]byte), Error: nil}
228+
for _, namespace := range dc.Namespaces {
229+
result, err := dc.K8sCoreClientSet.RbacV1().RoleBindings(namespace).List(ctx, metav1.ListOptions{})
230+
if err != nil {
231+
dc.Logger.Printf("\tCould not retrieve role bindings list for namespace %s: %v\n", namespace, err)
232+
} else {
233+
jsonResult, _ := json.MarshalIndent(result, "", " ")
234+
jobResult.Files[path.Join(dc.BaseDir, "k8s", "rbac", namespace, "rolebindings.json")] = jsonResult
235+
}
236+
}
237+
ch <- jobResult
238+
},
239+
},
206240
{
207241
Name: "k8s-version",
208242
Timeout: time.Second * 10,

0 commit comments

Comments
 (0)