Created
November 12, 2022 00:05
-
-
Save dlbewley/6bfdf6d295d697d2797d93cad0133f88 to your computer and use it in GitHub Desktop.
decompose policy.open-cluster-management.io/v1 policies into manifests for use with PolicyGenerator Kustomize plugin
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
# split a file having multiple policies into multiple files | |
# each file is named policy-<policy_name> and contains 1 policy | |
yq e '.|split_doc' -s '.kind + "-" + .metadata.name | downcase' multi-policy.yaml | |
# create manifests dir for each policy | |
# place object definitions from each policy into corresponding manifest dir | |
for p in policy-*; do | |
policy_name=$(yq '.metadata.name' $p); | |
mkdir -p "manifests-$policy_name" | |
yq '.spec.policy-templates[].objectDefinition[].object-templates[].objectDefinition | split_doc' \ | |
-s '"manifests-'$policy_name'/" + .kind + "-" + .metadata.name | downcase' $p; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment