forked from rook/rook
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use yq instead of Python for parsing RBAC from the Helm chart. We need to use yq v4.14.1 or higher to fix yq's handling of the yaml header markers ('---'). Update the Makefile's yq version to v4, which also requires updating the script to update the CRDs. This was quite easy. It is very difficult, however, to change the version of yq used by the CSV generating/parsing scripts, which already used their own yq download. Continue using yq v3 for this. In order to make sure the scripts are using the right version of yq, add basic validation to them to verify they are running v3 or v4 as required for their operation. Signed-off-by: Blaine Gardner <blaine.gardner@redhat.com>
- Loading branch information
Showing
11 changed files
with
310 additions
and
348 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 was deleted.
Oops, something went wrong.
This file contains 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,47 @@ | ||
#!/usr/bin/env bash | ||
set -eEuo pipefail | ||
|
||
# READS FROM STDIN | ||
# WRITES TO STDOUT | ||
# DEBUGS TO STDERR | ||
|
||
: ${YQ:=yq} | ||
|
||
if [[ "$($YQ --version)" != "yq (https://github.com/mikefarah/yq/) version 4."* ]]; then | ||
echo "yq must be version 4.x" | ||
exit 1 | ||
fi | ||
|
||
temp_dir="$(mktemp -d)" | ||
pushd "${temp_dir}" &>/dev/stderr | ||
|
||
# Output the RBAC into separate temporary files named with Kind and Name so that the filesystem can | ||
# sort the files, and we can keep the same resource ordering as before for easy diffing. Then we | ||
# just read in the files, sorted by the fs for final output. | ||
|
||
$YQ eval ' | ||
select(.kind == "PodSecurityPolicy"), | ||
select(.kind == "ServiceAccount"), | ||
select(.kind == "ClusterRole"), | ||
select(.kind == "ClusterRoleBinding"), | ||
select(.kind == "Role"), | ||
select(.kind == "RoleBinding") | ||
' - | # select all RBAC resource Kinds | ||
$YQ eval 'del(.metadata.labels.chart)' - | # remove the 'chart' label that only applies to Helm-managed resources | ||
sed '/^$/d' | # remove empty lines caused by yq's display of header/footer comments | ||
sed '/^# Source: /d' | # helm adds '# Source: <file>' comments atop of each yaml doc. Strip these | ||
$YQ eval --split-exp '.kind + " " + .metadata.name + " "' - # split into files by <kind> <name> .yaml | ||
# outputting the filenames with spaces after kind and name keeps the same sorting from before | ||
|
||
# For debugging, output the resource kinds and names we processed and the number we are keeping | ||
for file in *.yml; do | ||
echo "${file%.yml}" >/dev/stderr | ||
done | ||
# shellcheck disable=SC2012 # we know filenames are alphanumeric from being k8s resources | ||
echo "Number of RBAC resources: $(ls "${temp_dir}" | wc -l)" >/dev/stderr | ||
|
||
$YQ eval-all '.' ./*.yml | # output all files, now sorted by Kind and Name by the fs | ||
sed '/^$/d' # remove empty lines caused by yq's display of header/footer comments | ||
|
||
rm -rf "${temp_dir}" | ||
popd &>/dev/stderr |
Oops, something went wrong.