Skip to content

Commit

Permalink
fix: make audit more fault tolerant, log error instead of skipping up…
Browse files Browse the repository at this point in the history
…date (#2162)

fix: make audit more fault tolerant, log error instead of skipping status update

Signed-off-by: Rita Zhang <rita.z.zhang@gmail.com>
  • Loading branch information
ritazh authored Jul 14, 2022
1 parent f5eacc7 commit 59e190f
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions pkg/audit/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,26 +488,25 @@ func (am *Manager) reviewObjects(ctx context.Context, kind string, folderCount i

files, err := am.getFilesFromDir(pDir, int(*auditChunkSize))
if err != nil {
errs = append(errs, err)
am.log.Error(err, "Unable to get files from directory")
continue
}
for _, fileName := range files {
contents, err := os.ReadFile(path.Join(pDir, fileName)) // #nosec G304
if err != nil {
errs = append(errs, err)
am.log.Error(err, "Unable to get content from file", "fileName", fileName)
continue
}
objFile, err := am.readUnstructured(contents)
if err != nil {
errs = append(errs, err)
am.log.Error(err, "Unable to get unstructured data from content in file", "fileName", fileName)
continue
}
objNs := objFile.GetNamespace()
ns := corev1.Namespace{}
if objNs != "" {
ns, err = nsCache.Get(ctx, am.client, objNs)
if err != nil {
errs = append(errs, err)
am.log.Error(err, "Unable to look up object namespace", "objNs", objNs)
continue
}
Expand All @@ -518,7 +517,7 @@ func (am *Manager) reviewObjects(ctx context.Context, kind string, folderCount i
}
resp, err := am.opa.Review(ctx, augmentedObj)
if err != nil {
errs = append(errs, err)
am.log.Error(err, "Unable to review object from file", "fileName", fileName, "objNs", objNs)
continue
}

Expand Down

0 comments on commit 59e190f

Please sign in to comment.