#!/bin/bash

source ./common

# Expect base collection path as an argument
BASE_COLLECTION_PATH=$1

# Use PWD as base path if no argument is passed
if [ "${BASE_COLLECTION_PATH}" = "" ]; then
    BASE_COLLECTION_PATH=$(pwd)
fi

NAMESPACE="openshift-logging"

CLO_COLLECTION_PATH="$BASE_COLLECTION_PATH/cluster-logging"
install_folder="$CLO_COLLECTION_PATH/install"

echo "Gathering data for install info"
mkdir -p "$install_folder"

echo "-- Subscription"
oc get -n ${NAMESPACE} subscriptions.operators.coreos.com -o yaml > "$install_folder/subscription-clo"
oc get -n openshift-operators-redhat subscriptions.operators.coreos.com -o yaml > "$install_folder/subscription-eo"

echo "-- Install Plan"
oc get -n ${NAMESPACE} installplans.operators.coreos.com -o yaml > "$install_folder/install_plan-clo"
oc get -n openshift-operators-redhat installplans.operators.coreos.com -o yaml > "$install_folder/install_plan-eo"

echo "-- Catalog Operator logs"
oc logs -n openshift-operator-lifecycle-manager -l app=catalog-operator > "$install_folder/co_logs"

echo "-- OLM Operator logs"
oc logs -n openshift-operator-lifecycle-manager -l app=olm-operator > "$install_folder/olmo_logs"
