-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9223 from BlaineEXE/use-yq-v4
build: use yq for RBAC yaml parsing
- Loading branch information
Showing
12 changed files
with
321 additions
and
354 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.