Skip to content

Commit

Permalink
feat: enhance must-gather script to dynamically capture operator details
Browse files Browse the repository at this point in the history
Signed-off-by: Vibhu Prashar <vibhu.sharma2929@gmail.com>
  • Loading branch information
vprashar2929 committed Feb 6, 2024
1 parent 24a1a2b commit a3dbeba
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 243 deletions.
22 changes: 21 additions & 1 deletion must-gather/common
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,29 @@

set -eu -o pipefail

export KEPLER_NS=$(oc get keplerinternals kepler -o jsonpath='{.spec.exporter.deployment.namespace}')
export LOGFILE_NAME="gather-debug.log"

init() {
OPERATOR="$(
oc get subscription -A -o jsonpath='{.items[?(@.metadata.name=="power-monitoring-operator")].metadata.name}'
oc get subscription -A -o jsonpath='{.items[?(@.metadata.name=="kepler-operator")].metadata.name}'
)"
[[ -z "$OPERATOR" ]] && {
return 1
}
OPERATOR_NS="$(oc get subscription -A -o jsonpath="{.items[?(@.metadata.name==\"$OPERATOR\")].metadata.namespace}")"
[[ -z "$OPERATOR_NS" ]] && {
return 1
}
KEPLER_NS="$(oc get keplerinternals kepler -o jsonpath='{.spec.exporter.deployment.namespace}')"

log "found $OPERATOR deployed inside $OPERATOR_NS namespace"

export KEPLER_NS OPERATOR OPERATOR_NS

return 0
}

get_timestamp() {
date -u +"%Y-%m-%d %H:%M:%SZ"
}
Expand Down
46 changes: 17 additions & 29 deletions must-gather/gather
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,8 @@ gather_olm_info() {
}

gather_operator_info() {
oc get -n openshift-operators csv | grep kepler-operator && {
gather_kepler_operator_info
}

oc get -n openshift-operators csv | grep power-monitoring-operator && {
gather_power_monitoring_operator_info
}
return 0
}

gather_kepler_operator_info() {
log "getting kepler-operator info"
"$SCRIPT_DIR"/gather-kepler-operator-info "$BASE_COLLECTION_PATH"
}

gather_power_monitoring_operator_info() {
log "getting power-monitoring-operator info"
"$SCRIPT_DIR"/gather-power-monitoring-operator-info "$BASE_COLLECTION_PATH"
log "getting $OPERATOR info"
"$SCRIPT_DIR"/gather-operator-info "$BASE_COLLECTION_PATH"
}

gather_monitoring_info() {
Expand Down Expand Up @@ -131,17 +115,21 @@ main() {
export KUBECACHEDIR=/tmp/cache-dir

echo "powermon must-gather started..."
gather_olm_info
gather_operator_info
get_kepler_instance
get_kepler_internal_instances
get_kepler_events
get_kepler_daemon_set
get_kepler_config_map
get_kepler_sa
get_kepler_scc
gather_kepler_exporter_info
gather_monitoring_info
init || {
log "fail to gather operator details"
return 1
}
gather_olm_info || true
gather_operator_info || true
get_kepler_instance || true
get_kepler_internal_instances || true
get_kepler_events || true
get_kepler_daemon_set || true
get_kepler_config_map || true
get_kepler_sa || true
get_kepler_scc || true
gather_kepler_exporter_info || true
gather_monitoring_info || true

echo "powermon must-gather completed"
}
Expand Down
98 changes: 0 additions & 98 deletions must-gather/gather-kepler-operator-info

This file was deleted.

21 changes: 4 additions & 17 deletions must-gather/gather-olm-info
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,15 @@ source "${SCRIPT_DIR}/common"

BASE_COLLECTION_PATH=$1

KEPLER_OPERATOR_LABELS="operators.coreos.com/kepler-operator.openshift-operators"
POWER_MONITORING_OPERATOR_LABELS="operators.coreos.com/power-monitoring-operator.openshift-operators"

get_olm() {
oc get -n openshift-operators csv | grep kepler-operator && {
log "collecting olm info for kepler-operator"
run oc -n openshift-operators get olm -l "${KEPLER_OPERATOR_LABELS}"= \
-oyaml "$OLM_INFO_DIR/kepler-operator-olm-resources.yaml"
}

oc get -n openshift-operators csv | grep power-monitoring-operator && {
log "collecting olm info for power-monitoring-operator"
run oc -n openshift-operators get olm -l "${POWER_MONITORING_OPERATOR_LABELS}"= \
-oyaml "$OLM_INFO_DIR/power-mon-olm-resources.yaml"
}

return 0
log "collecting olm info for $OPERATOR"
run oc -n "$OPERATOR_NS" get olm -l "operators.coreos.com/$OPERATOR.$OPERATOR_NS"= \
-oyaml "$OLM_INFO_DIR/$OPERATOR-olm-resources.yaml"
}

get_summary() {
log "collecting olm summary"
run oc -n openshift-operators get olm -owide "$OLM_INFO_DIR/summary.txt"
run oc -n "$OPERATOR_NS" get olm -owide "$OLM_INFO_DIR/summary.txt"
}

main() {
Expand Down
95 changes: 95 additions & 0 deletions must-gather/gather-operator-info
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env bash

# copyright 2023.
#
# licensed under the apache license, version 2.0 (the "license");
# you may not use this file except in compliance with the license.
# you may obtain a copy of the license at
#
# http://www.apache.org/licenses/license-2.0
#
# unless required by applicable law or agreed to in writing, software
# distributed under the license is distributed on an "as is" basis,
# without warranties or conditions of any kind, either express or implied.
# see the license for the specific language governing permissions and
# limitations under the license.
#

set -eu -o pipefail

SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
source "${SCRIPT_DIR}/common"

BASE_COLLECTION_PATH=$1
OPERATOR_DEPLOY_NAME="kepler-operator-controller"

get_catalogsource() {
log "getting catalogsource info for $OPERATOR"
run oc -n "$OPERATOR_NS" get catalogsource "$OPERATOR-catalog" -oyaml "$KEPLER_OPERATOR_INFO_DIR/$OPERATOR-catalogsource.yaml"
}

get_subscription() {
log "getting subscription info for $OPERATOR"
run oc -n "$OPERATOR_NS" get subscription -l operators.coreos.com/"$OPERATOR"."$OPERATOR_NS"= -oyaml "$KEPLER_OPERATOR_INFO_DIR/$OPERATOR-subscription.yaml"
}

get_install_plan() {
log "getting installplan info for $OPERATOR"
run oc -n "$OPERATOR_NS" get installplan -l operators.coreos.com/"$OPERATOR"."$OPERATOR_NS"= -oyaml "$KEPLER_OPERATOR_INFO_DIR/$OPERATOR-installplan.yaml"
}

get_csv() {
log "getting CSV for $OPERATOR"
run oc -n "$OPERATOR_NS" get csv -l operators.coreos.com/"$OPERATOR"."$OPERATOR_NS"= -oyaml "$KEPLER_OPERATOR_INFO_DIR/$OPERATOR-csv.yaml"
}

get_kepler_operator_deployment_info() {
log "getting deployment info for $OPERATOR"
run oc -n "$OPERATOR_NS" get deployment "$OPERATOR_DEPLOY_NAME" -oyaml "$KEPLER_OPERATOR_INFO_DIR/$OPERATOR-deployment.yaml"
}

get_kepler_operator_pod_info() {
log "getting pod info for $OPERATOR"
run oc -n "$OPERATOR_NS" get pod \
-l app.kubernetes.io/component=manager \
-l app.kubernetes.io/part-of="kepler-operator" \
-oyaml "$KEPLER_OPERATOR_INFO_DIR/$OPERATOR.yaml"
}

get_summary() {
run oc -n "$OPERATOR_NS" get catalogsource "$OPERATOR-catalog" -owide "$KEPLER_OPERATOR_INFO_DIR/summary.txt"
echo -e "\n" >>"$KEPLER_OPERATOR_INFO_DIR/summary.txt"

run oc -n "$OPERATOR_NS" get subscription -owide "$KEPLER_OPERATOR_INFO_DIR/summary.txt"
echo -e "\n" >>"$KEPLER_OPERATOR_INFO_DIR/summary.txt"

run oc -n "$OPERATOR_NS" get installplan -owide "$KEPLER_OPERATOR_INFO_DIR/summary.txt"
echo -e "\n" >>"$KEPLER_OPERATOR_INFO_DIR/summary.txt"

run oc -n "$OPERATOR_NS" get csv -owide "$KEPLER_OPERATOR_INFO_DIR/summary.txt"
echo -e "\n" >>"$KEPLER_OPERATOR_INFO_DIR/summary.txt"

run oc -n "$OPERATOR_NS" get deployment "$OPERATOR_DEPLOY_NAME" -owide "$KEPLER_OPERATOR_INFO_DIR/summary.txt"
echo -e "\n" >>"$KEPLER_OPERATOR_INFO_DIR/summary.txt"

run oc -n "$OPERATOR_NS" get pod \
-l app.kubernetes.io/component=manager \
-l app.kubernetes.io/part-of="kepler-operator" \
-owide "$KEPLER_OPERATOR_INFO_DIR/summary.txt"
}

main() {

KEPLER_OPERATOR_INFO_DIR="$BASE_COLLECTION_PATH/$OPERATOR-info"
mkdir -p "$KEPLER_OPERATOR_INFO_DIR"

get_subscription
get_catalogsource
get_install_plan
get_csv
get_kepler_operator_deployment_info
get_kepler_operator_pod_info
get_summary
}

main "$@"
Loading

0 comments on commit a3dbeba

Please sign in to comment.