Merge pull request #9570 from BlaineEXE/make-crd-rbac-ordering-deterministic-in-linux
build: make crd/rbac generation order deterministic
This commit is contained in:
2 files changed
+29
-9
No files matched your search
@@ -97,7 +97,19 @@ fi
|
||||
|
||||
generating_main_crd
|
||||
|
||||
# Linux doesn't guarantee file ordering, so we must sort the output to make sure it's deterministic.
|
||||
# In order to handle file paths with spaces in the yq command below, it's easiest to read the
|
||||
# file names into an array.
|
||||
# Set locale `LC_ALL=C` because different OSes have different sort behavior;
|
||||
# `C` sorting order is based on the byte values,
|
||||
# Reference: https://blog.zhimingwang.org/macos-lc_collate-hunt
|
||||
LC_ALL=C
|
||||
CRD_FILES=()
|
||||
while read -r line; do
|
||||
CRD_FILES+=("$line")
|
||||
done < <(find "$OLM_CATALOG_DIR" -type f -name '*.yaml' | sort)
|
||||
|
||||
echo "---" >> "$CEPH_CRDS_FILE_PATH" # yq doesn't output the first doc separator
|
||||
$YQ_BIN_PATH eval-all '.' "$OLM_CATALOG_DIR/"*.yaml >> "$CEPH_CRDS_FILE_PATH"
|
||||
$YQ_BIN_PATH eval-all '.' "${CRD_FILES[@]}" >> "$CEPH_CRDS_FILE_PATH"
|
||||
|
||||
build_helm_resources
|
||||
@@ -1,9 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eEuo pipefail
|
||||
# setting locate `LC_ALL=C` because different OS do files sorting differently,
|
||||
# so setting a common behaviour, `C` sorting order is based on the byte values,
|
||||
# Reference: https://blog.zhimingwang.org/macos-lc_collate-hunt
|
||||
LC_ALL=C
|
||||
|
||||
# READS FROM STDIN
|
||||
# WRITES TO STDOUT
|
||||
@@ -39,14 +35,26 @@ sed '/^# Source: /d' | # helm adds '# Source: <file>' comments atop of each yaml
|
||||
$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
|
||||
|
||||
# Linux doesn't guarantee file ordering, so sort the files to make sure order is deterministic.
|
||||
# And in order to handle file paths with spaces, it's easiest to read the file names into an array.
|
||||
# Set locale `LC_ALL=C` because different OSes have different sort behavior;
|
||||
# `C` sorting order is based on the byte values,
|
||||
# Reference: https://blog.zhimingwang.org/macos-lc_collate-hunt
|
||||
LC_ALL=C
|
||||
RBAC_FILES=()
|
||||
while read -r line; do
|
||||
RBAC_FILES+=("$line")
|
||||
done < <(find . -type f -name '*.yml' | sort)
|
||||
|
||||
# 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
|
||||
for file in "${RBAC_FILES[@]}"; do
|
||||
# basename to get rid of the leading './' which find adds; %.yml to remove the .yml suffix
|
||||
basename "${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
|
||||
echo "Number of RBAC resources: ${#RBAC_FILES[@]}" >/dev/stderr
|
||||
|
||||
$YQ eval-all '.' ./*.yml | # output all files, now sorted by Kind and Name by the fs
|
||||
$YQ eval-all '.' "${RBAC_FILES[@]}" | # 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}"
|
||||
|
||||
Reference in new issue
Block a user