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

feat(constraints): add compound constraints and olm.constraint value parser #203

Conversation

estroz
Copy link
Member

@estroz estroz commented Dec 10, 2021

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 10, 2021
// CompoundConstraint holds a list of potentially nested constraints
// over which a boolean operation is applied.
type CompoundConstraint struct {
Constraints []Constraint `json:"constraints"`
Copy link
Member

Choose a reason for hiding this comment

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

While I understand CompoundConstraint is a list of constraints but then Constraint itself can be a All, Any, None constraint which is a CompoundConstraint itself. So we potentially have a CompoundConstraint as a list of CompoundConstraint. While it is not a problem programmatically but logically it is convoluted and frankly difficult to test.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not quite, since CompoundConstraint does not alias Constraint; they're two distinct types. I don't see how you would get nice recursion that leverages std serialization libs otherwise. The encoded form is readable and comprehensible imo. Plus this is what the EP proposed.

Copy link
Member

@awgreene awgreene left a comment

Choose a reason for hiding this comment

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

Looks good to me. Primarily non-blocking nits and generic comments.

Comment on lines -19 to -29
// Constraint is a struct representing the new generic constraint type
type Constraint struct {
// Constraint message that surfaces in resolution
// This field is optional
Message string `json:"message" yaml:"message"`

// The cel struct that contraints CEL expression
// This field is required
Cel *Cel `json:"cel" yaml:"cel"`
}

Copy link
Member

Choose a reason for hiding this comment

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

Note: This was just moved to constraints.go and is still available within the package.

pkg/constraints/constraint.go Outdated Show resolved Hide resolved
pkg/constraints/constraint.go Show resolved Hide resolved
pkg/constraints/constraint.go Outdated Show resolved Hide resolved
pkg/constraints/constraint.go Outdated Show resolved Hide resolved
pkg/constraints/constraint_test.go Show resolved Hide resolved
pkg/constraints/constraint.go Outdated Show resolved Hide resolved
…parser

Signed-off-by: Eric Stroczynski <ericstroczynski@gmail.com>
Signed-off-by: Eric Stroczynski <ericstroczynski@gmail.com>
@estroz estroz added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Dec 10, 2021
@awgreene
Copy link
Member

awgreene commented Dec 10, 2021

/approve

I'm happy with the changes introduced in this PR, but I will wait for @dinhxuanvu to lgtm as he has been involved.

@openshift-ci
Copy link

openshift-ci bot commented Dec 10, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: awgreene, estroz

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

Comment on lines +124 to +129
input: func(t *testing.T) json.RawMessage {
p := make([]byte, maxConstraintSize+1)
_, err := rand.Read(p)
require.NoError(t, err)
return json.RawMessage(p)
}(t),
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

@timflannagan
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Dec 10, 2021
Copy link
Member

@dinhxuanvu dinhxuanvu left a comment

Choose a reason for hiding this comment

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

There is a bit about version vs versionRange for package dependency that I need to look into but lgtm overall.
/lgtm

@openshift-merge-robot openshift-merge-robot merged commit 40cb9fd into operator-framework:master Dec 10, 2021
@estroz estroz deleted the feat/compound-constraints branch December 10, 2021 20:55
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. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants