Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Commit

Permalink
Ignore Rego error removing non-existent paths. (#17)
Browse files Browse the repository at this point in the history
It is possible to get multiple deletion events for objects, in which
case the runner will remove the Rego store path a second time. We don't
care about the "doesn't exist" error in this case because we are pretty
sure we want the path to not exist.

Signed-off-by: James Peach <[email protected]>
  • Loading branch information
jpeach authored Sep 10, 2020
1 parent 6887821 commit 85b01ec
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/test/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,5 +628,17 @@ func removeResource(k *driver.KubeClient, c driver.RegoDriver, u *unstructured.U
return err
}

return c.RemovePath(pathForResource(gvr.Resource, u))
// We don't care if the path we wanted to remove wasn't found,
// as long as it's not there when we are done. We can end up
// receiving multiple delete events for the same object, which
// can attempt to remove the same path again.
return ignoreStorageNotFoundErr(c.RemovePath(pathForResource(gvr.Resource, u)))
}

func ignoreStorageNotFoundErr(err error) error {
if storage.IsNotFound(err) {
return nil
}

return err
}

0 comments on commit 85b01ec

Please sign in to comment.