#!/bin/bash

# generate /must-gather/version file
. version
echo "openshift/must-gather" > /must-gather/version
version >> /must-gather/version

# Resource List
resources=()

# Cluster Version Information 
resources+=(clusterversion ns/openshift-cluster-version)

# Operator Resources
resources+=(clusteroperators)

# Certificate Resources
resources+=(certificatesigningrequests)

# Machine/Node Resources
resources+=(nodes machineconfigs machineconfigpools)

# Namespaces/Project Resources
resources+=(ns/default ns/openshift ns/kube-system ns/openshift-etcd)

# Storage Resources
resources+=(storageclasses persistentvolumes volumeattachments)

# Networking Resources
resources+=(networks.operator.openshift.io)

# Run the Collection of Resources using inspect
# running accross all-namespaces for the few "Autoscaler" resouces.
for resource in "${resources[@]}"; do
    oc adm inspect --dest-dir must-gather ${resource}
done

# Collect System Audit Logs
/usr/bin/gather_audit_logs

# Gather Service Logs (using a suplamental Script); Scoped to Masters.
/usr/bin/gather_service_logs master
