Repository navigation
ROX-37160: add AtMostOneOf exclusion validation #23381
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c1a3937
feat(crd): add AtMostOneOf exclusion validation
clickboo 512ee5f
use omitzero instead of omitempty tag for Deployment field of Exclusi…
clickboo 7a46988
scrub the validation error before crdify processes it, to prevent crd…
clickboo d0125fd
chore(ci): more generic CRD validation filtering (#23432)
porridge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| #!/usr/bin/env bash | ||
| # Run crdify on copies of CRDs after stripping out known false positives. | ||
| # Usage: | ||
| # crdify.sh <old-crd> <new-crd> [crdify flags] | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| ROOT_DIR="$(dirname "${BASH_SOURCE[0]}")/../../.." | ||
| readonly ROOT_DIR | ||
|
|
||
| if [[ $# -lt 2 ]]; then | ||
| echo "usage: $0 <old-crd> <new-crd> [crdify flags]" >&2 | ||
| exit 2 | ||
| fi | ||
|
|
||
| old_crd="${1:?missing required argument 'old-crd'}" | ||
| new_crd="${2:?missing required argument 'new-crd'}" | ||
| shift | ||
| shift | ||
|
|
||
| if [[ ! -f "$old_crd" ]]; then | ||
| echo "::error::CRD file not found: $old_crd" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ ! -f "$new_crd" ]]; then | ||
| echo "::error::CRD file not found: $new_crd" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
|
|
||
| # The addition of this particular validation rule, even though considered a breaking change by definition | ||
| # (https://github.com/kubernetes/community/blob/main/contributors/devel/sig-architecture/api_changes.md#backward-compatibility-gotchas) | ||
| # is fine in practice, since the `excludeByKind` branch is being added in the same release cycle as the rule itself, | ||
| # meaning no production CRS could have existed that violated the validation. | ||
| filter_spec_exclusions_one_of() { | ||
| local input="$1" | ||
| local output="$2" | ||
|
|
||
| local message='at most one of the fields in [deployment excludeByKind] may be set' | ||
| local rule='(has(self.deployment)?1:0)+(has(self.excludeByKind)?1:0) <= 1' | ||
|
|
||
| # Remove matching rule, and the validations list if empty afterwards. | ||
| message="${message}" rule="${rule}" \ | ||
| go run -C "${ROOT_DIR}/operator/tools/yq" github.com/mikefarah/yq/v4 eval ' | ||
| del( | ||
| .spec.versions[].schema.openAPIV3Schema.properties.spec.properties.exclusions.items."x-kubernetes-validations"[] | ||
| | select(.message == strenv(message) and .rule == strenv(rule)) | ||
| ) | ||
| | del( | ||
| .spec.versions[].schema.openAPIV3Schema.properties.spec.properties.exclusions.items."x-kubernetes-validations" | ||
| | select(length == 0) | ||
| ) | ||
| ' "$input" > "$output" | ||
| } | ||
|
|
||
|
|
||
| crd_basename="$(basename "${old_crd}")" | ||
| case "$crd_basename" in | ||
| config.stackrox.io_securitypolicies.yaml) | ||
| filtered_dir="$(mktemp -d)" | ||
| echo >&2 "Filtering known false positives from ${old_crd} and ${new_crd}" | ||
| filter_spec_exclusions_one_of "${old_crd}" "${filtered_dir}/old-${crd_basename}" | ||
| filter_spec_exclusions_one_of "${new_crd}" "${filtered_dir}/new-${crd_basename}" | ||
| old_crd="${filtered_dir}/old-${crd_basename}" | ||
| new_crd="${filtered_dir}/new-${crd_basename}" | ||
| ;; | ||
| *) | ||
| echo >&2 "No filtering rules for ${old_crd}, running crdify on original CRDs." | ||
| ;; | ||
| esac | ||
|
|
||
| set -x | ||
| go run -C "${ROOT_DIR}/operator/tools/crdify" sigs.k8s.io/crdify --config=config.yaml "$@" \ | ||
| "file://${old_crd}" "file://${new_crd}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
operator/bundle/manifests/config.stackrox.io_securitypolicies.yaml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.