Skip to content

Instantly share code, notes, and snippets.

@dlbewley
Created November 12, 2022 00:05
Show Gist options
  • Save dlbewley/6bfdf6d295d697d2797d93cad0133f88 to your computer and use it in GitHub Desktop.
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
# 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