My purpose is to get all PDB in AKS all namespaces. If a namespace don't have PDB, it should just skip and went to another namespace. In my local env, bash script can list PDB in all namespaces. But in Azure pipeline, if a namespace don't contain PDB, the whole bash script just ended and throw error: No resources found in default namespace. ##[error]Bash exited with code '1'.
My Bash script:
namespace=$(kubectl get namespace|egrep -iv 'name|kube-system'|awk '{ print $1 }')
echo "${namespace}"
for ns in ${namespace};
do
poddisruptionbudget=$(kubectl get pdb -n ${ns}|awk '{ print $1 }'|grep -iv 'name');
for pdb in ${poddisruptionbudget};
do
echo "PDB $pdb in namespace $ns"
kubectl get -o=yaml pdb $pdb -n $ns >/azp/pdb/$ns-${pdb}.yaml;
kubectl delete pdb $pdb -n $ns
done;
done
Azure Pipeline Code:
- task: Bash@3
displayName: Upgrade AKS cluster
inputs:
filePath: '$(System.DefaultWorkingDirectory)/aks-operation/aks_upgrade.sh'
Try to run a shell script in Azure DevOps pipeline, get all PDB in AKS. However, some namespace don't container PDB, azure pipeline exited with failure:
No resources found in default namespace.
##[error]Bash exited with code '1'.