-
Notifications
You must be signed in to change notification settings - Fork 89
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
Escape CEL Reserved Keywords when Generating Validation Rules #255
Escape CEL Reserved Keywords when Generating Validation Rules #255
Conversation
Signed-off-by: dalton hill <[email protected]>
Signed-off-by: dalton hill <[email protected]>
1393635
to
1825930
Compare
PR is ready for review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comment, otherwise LGTM. Thanks @dalton-hill-0 for the contribution!
Signed-off-by: dalton hill <[email protected]>
@@ -444,3 +455,12 @@ func fieldPathWithWildcard(parts []string) string { | |||
} | |||
return seg.String() | |||
} | |||
|
|||
func sanitizePath(p string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
func sanitizePath(p string) string { | |
func escapeName(p string) string { |
|
||
var ( | ||
// ref: https://github.com/google/cel-spec/blob/v0.6.0/doc/langdef.md#syntax | ||
celReservedKeywords = []string{"true", "false", "null", "in", "as", "break", "const", "continue", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: We may use a map[string]struct{}
(or the higher-level "k8s.io/apimachinery/pkg/util/sets.Set
) for O(1) lookups. Also the list we search has a relatively static small size.
Description of your changes
Fixes #254
Wraps CEL reserved keywords found in Validation Rules (i.e.,
__{keyword}__
).For instance, if the object has a field "namespace", this would be the before and after in
zz_<obj>_types.go
The same diff, for the generated CRD
I have:
make reviewable
to ensure this PR is ready for review.backport release-x.y
labels to auto-backport this PR if necessary.How has this code been tested