akondur / collect_data_k8s

2 stars 0 forks source link

allow namespacing for k8 collection #2

Open zeropoint46 opened 2 years ago

zeropoint46 commented 2 years ago

allow specifying namespace for collecting k8 info from cluster. This is esspecially valuable for cases when the cluster is either large or parts of the cluster can't be shared for security reasons and for namespaced deployments of splunk-operator.

zeropoint46 commented 2 years ago

I modified the script to have something like this:

while getopts "d:t:l:n:" opt
do
   case "$opt" in
      d) diag="$OPTARG" ;;
      t) targetfolder="$OPTARG" ;;
      l) limitandavoiddescribe="$OPTARG" ;;
      n) namespace="$OPTARG" ;;
      ? ) helpFunction ;; # Print helpFunction in case parameter is non-existent
   esac
done

# setup k8 command
if [ -z "namespace" ]
then
    k8cmd=$(which kubectl)
else
    k8cmd="$(which kubectl) -n $namespace"
fi

then I changed all the kubectl commands to something like this:

${k8cmd} get all >> all.txt; ${k8cmd} get all -o yaml >> all.txt;
zeropoint46 commented 2 years ago

additional changes need to be done for the python script.