Add EscapingExamples
Adds a set of example which demonstrate the effects of escaping when generating validation rules. Specifically:
- `` vs "" for rule quoting
- "" vs r'' in CEL expressions
These tests justify the following general recommendations to avoid complex escaping:
- Always prefer `` for validation rules
- Always prefer r'' for strings in CEL expressions
Pipeline controller notification
This repository is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.
For optional jobs, comment /test ? to see a list of all defined jobs. Review these jobs and use /test <job> to manually trigger optional jobs most likely to be impacted by the proposed changes.
Hello @mdbooth! Some important instructions when contributing to openshift/api: API design plays an important part in the user experience of OpenShift and as such API PRs are subject to a high level of scrutiny to ensure they follow our best practices. If you haven't already done so, please review the OpenShift API Conventions and ensure that your proposed changes are compliant. Following these conventions will help expedite the api review process for your PR.
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by: Once this PR has been reviewed and has the lgtm label, please assign deads2k for approval. For more information see the Code Review Process.
The full list of commands accepted by this bot can be found here.
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
@mdbooth: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:
| Test name | Commit | Details | Required | Rerun command |
|---|---|---|---|---|
| ci/prow/lint | 73fa3337f3b04e05b535781292839ab47c79b408 | link | true | /test lint |
Full PR test history. Your PR dashboard.
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.
@JoelSpeed The linter is rejecting because apparently Pattern is banned in this repo. That obviously make this example impossible to write.
However, I also don't think it's a good idea. Certainly CEL has a lot of validation functions which we should require folks to use in preference to custom patterns. And as discussed, format markers in preference to those with the security related carve-outs documents in https://github.com/openshift/api/pull/2574. But if you're validating something that doesn't follow a standard kubernetes pattern then using Pattern is clearer and more concise than doing the same thing in a CEL expression. Quite apart from anything else, as demonstrated in this PR there are fewer escaping-related footguns.
A quick grep for Pattern in this repo shows that most, but critically far from all, of them should not exist.
Not sure what to do with this. My recommendation would be to remove the prohibition on Pattern and replace it with a softer review requirement that it needs a good use case. If you really want to stick with a ban then I'd also have to update https://github.com/openshift/api/pull/2574 to document that, as well as removing it here.
PR needs rebase.
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.
Apart from needing a rebase, this an interesting and useful example, thanks!
We can override the linting that suggests we aren't allowed a pattern, but the pointer bits should be fixed