Skip to content

Instantly share code, notes, and snippets.

@ohmrefresh
Created October 5, 2019 03:39
Show Gist options
  • Select an option

  • Save ohmrefresh/2548baca745e8ae5baaeb70800242a3d to your computer and use it in GitHub Desktop.

Select an option

Save ohmrefresh/2548baca745e8ae5baaeb70800242a3d to your computer and use it in GitHub Desktop.
[OCP] Get All network policy
#!/bin/bash
namespace_arr=(animal fruit)
environment_arr=(dev qa)
basePath="NetworkPolicy/"
rm -rf ${basePath} || true
for name in "${namespace_arr[@]}"; do
for environment in "${environment_arr[@]}"; do
namespace="${name}-${environment}"
policy_arr=($(oc get NetworkPolicy --namespace=${namespace} | awk 'FNR > 1 {print $1}'))
for policy in "${policy_arr[@]}"; do
mkdir -p ${basePath}/${namespace}/
echo "${policy}"
oc get networkpolicy ${policy} --namespace=${namespace} -o yaml > ${basePath}/${namespace}/${policy}.yml
done
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment