Skip to content

feat(cel): Add CEL custom library for semver comparison #202

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

Merged
merged 2 commits into from
Dec 10, 2021

Conversation

dinhxuanvu
Copy link
Member

Add CEL custom library for semver comparison to api repo. This
library is used in olm and registry.

Signed-off-by: Vu Dinh [email protected]

@openshift-ci
Copy link

openshift-ci bot commented Dec 8, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dinhxuanvu

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot requested review from awgreene and kevinrizza December 8, 2021 18:20
@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 8, 2021
Add CEL custom library for semver comparison to api repo. This
library is used in olm and registry.

Signed-off-by: Vu Dinh <[email protected]>
Copy link
Member

@joelanford joelanford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick review!

pkg/cel/cel.go Outdated
Comment on lines 34 to 40
type Evaluator interface {
Evaluate(env map[string]interface{}) (bool, error)
}

type EvaluatorProvider interface {
Evaluator(rule string) (Evaluator, error)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to get some GoDoc on these types to make it more obvious what their purpose is.

Are these specific to cel? If not, should they be in another package? Or should we name this package something else (e.g. constraint)?

Copy link
Member Author

@dinhxuanvu dinhxuanvu Dec 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the OLM PR, I call this package constraints but in api repo, I'm not sure if I should be more explicit about the constraint type. So I call it cel here but if constraints sounds more appropriate then I'm totally fine with that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, if this package is renamed to constraint or constraints, it would make sense to me to have something like:

$ tree constraint
constraint
├── cel.go (cel-specific stuff here)
├── compound.go (All, Any, None constraints here)
└── constraint.go (common types and interfaces, e.g. Constraint and Evaluator*)

WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, looking more closely at the evaluator interface, it looks cel-specific (at least for now)?

I'm curious if there's a more generic constraint interface that all of the constraint types could implement? When @estroz goes to add the compound constraint struct, will there be an interface he can implement such that he doesn't have to change anything on the OLM side?

Copy link
Member Author

@dinhxuanvu dinhxuanvu Dec 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code was meant to use with Evaluator() function below as a "selector" on which provider to use via id parameter (if you remember the original EP with evaluator struct with id field). Now that we don't have id part anymore, this provider becomes CEL-specific which is fine. If we introduce a new "provider" later, we can simply create a new NewSomethingEvaluatorProvider and add it to the SatResolver. Now evaluatorProvider on SatResolver is a field with a single provider but it can be a collection of providers. That shouldn't be a problem code-wise later on.

@estroz
Copy link
Member

estroz commented Dec 8, 2021

Since olm.constraint is just a property, which are sent over gRPC automatically, and known only to OLM's resolver, I don't see a need to encode its behavior here for operator-registry's sake. If anything in operator-registry is required to know about constraint implementations (like opm alpha diff libraries), then en/decoding for specific implementations should be implemented internally there; indeed, having an internal CEL evaluator here is totally fine and a good idea (but not a priority imo). If we ever decide to change this split of concerns in the future, then we break no APIs because there is no shared code.

Remind the original cel package to constraints pkg to reflect that
there will be more type of constraints.

Remove the evaluator/provider interfaces that are not needed yet.
The generic interface can be designed later when a new type of
constraint is introduced.

Signed-off-by: Vu Dinh <[email protected]>
@dinhxuanvu
Copy link
Member Author

After a discussion with Eric, it seems the generic interface design is not needed yet given only CEL is supported at the moment. There seems to be quite a bit of discussions about this interface that may need more time to figure out. For now, we can simply use struct and functions for CEL evaluation.

@estroz
Copy link
Member

estroz commented Dec 9, 2021

I'm fine with how this PR stands now. We can always deprecate the types defined here once we have a more robust interface system designed to handle other constraint types as @joelanford has suggested here.

@dinhxuanvu
Copy link
Member Author

I'm putting a hold here so people can approve and lgtm.
/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 9, 2021
@estroz
Copy link
Member

estroz commented Dec 9, 2021

/lgtm

@dinhxuanvu
Copy link
Member Author

Ready for merge
/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants