Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Driver interface AddConstraint improvement #324

Open
acpana opened this issue Apr 21, 2023 · 0 comments
Open

Driver interface AddConstraint improvement #324

acpana opened this issue Apr 21, 2023 · 0 comments

Comments

@acpana
Copy link
Contributor

acpana commented Apr 21, 2023

overview

At the moment, AddConstraint's definition (docs) states:

        // AddConstraint adds a Constraint to Driver for a particular Template. Future
	// calls to Query may reference the added Constraint. Replaces the existing
	// Constraint if it already exists.
        AddConstraint(ctx context.Context, constraint *unstructured.Unstructured) error

However, if no Template has already been added, via AddTemplate, the behavior is undefined. At present, the rego driver "fails silently":

key := drivers.ConstraintKeyFrom(constraint)
path := key.StoragePath()
d.mtx.Lock()
defer d.mtx.Unlock()
targets := d.targets[key.Kind]
for _, target := range targets {
err := d.storage.addData(ctx, target, path, params)
if err != nil {
return err
}
}
return nil

solutions

  1. Define the behavior and enforce it. Update the docs and if the targets is not found err out with some helpful error like TemplateNotFound
targets, found := ...
if not found, error
  1. Modify the signature of AddConstraint to also include the Template that we want to associate the Constraint with. This approach would probably require some rethinking or regrokking of the flow for both AddTemplate and AddConstraint so it may actually be more work than value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant