#!/bin/bash -x

BASE_COLLECTION_PATH="${BASE_COLLECTION_PATH:-/must-gather}"
PROS=${PROS:-5}

# Resource list
resources=$(/usr/bin/oc get apiservices | grep kubevirt.io | awk '{ print $1 }')

export apiservice_collection_path=${BASE_COLLECTION_PATH}/apiservices/
mkdir -p ${apiservice_collection_path}

echo ${resources[@]} | tr ' ' '\n' | xargs -t -I{} -P ${PROS} --max-args=1 sh -c '/usr/bin/oc get apiservice $1 -o yaml > ${apiservice_collection_path}/$1.yaml' -- {}

exit 0
