#!/bin/bash

NAMESPACES="istio-system istio-operator"

for NAMESPACE in ${NAMESPACES}
do
  echo "Collecting details from ${NAMESPACE} namespace"
  WORKDIR="${NAMESPACE}-details"
  mkdir ${WORKDIR}
  pushd ${WORKDIR}
  for POD in $(oc get pods -n ${NAMESPACE} -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}'); do oc describe pod/${POD} -n ${NAMESPACE} > ${NAMESPACE}-pod-${POD}-description.txt; done
  oc get nodes -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | oc describe node $1 | grep ${NAMESPACE} > ${NAMESPACE}-resource-utilization.txt
  oc get pods -n ${NAMESPACE} -o jsonpath='{range .items[*]}{"\n"}{"Pod: "}{.metadata.name}{"\n"}{"  Containers: \n"}{range .spec.containers[*]}{"   -> "}{.image}{" (name: "}{.name}{")\n"}{end}' > ${NAMESPACE}-pods-containers-and-images.txt
  popd
done

