-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathgather
executable file
·74 lines (63 loc) · 2.46 KB
/
gather
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#! /bin/bash
# Copyright (c) 2023 Red Hat, Inc.
# Copyright Contributors to the Open Cluster Management project
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
source ${SCRIPT_DIR}/gather_utils
mkdir -p ${BASE_COLLECTION_PATH}
MCE_CLUSTER=false
HUB_CLUSTER=false
SPOKE_CLUSTER=false
MCE_NAME=""
export OPERATOR_NAMESPACE=""
export DEPLOYMENT_NAMESPACE=""
export GATHER_MCE_RAN=false
export GATHER_HUB_RAN=false
export HC_NAME=""
export HC_NAMESPACE="clusters" # default hosted cluster namespace
parse_args "$@"
check_if_engine() {
MCE_NAME=$(oc get multiclusterengines.multicluster.openshift.io --all-namespaces --no-headers=true | awk '{ print $1 }')
if [[ -n "${MCE_NAME}" ]]; then
log "Detected MCE resource: \"${MCE_NAME}\" on current cluster. This cluster has been verified as an engine cluster."
MCE_CLUSTER=true
OPERATOR_NAMESPACE=$(oc get pod -l control-plane=backplane-operator --all-namespaces --no-headers=true | head -n 1 | awk '{ print $1 }')
DEPLOYMENT_NAMESPACE=$(oc get mce "${MCE_NAME}" -o jsonpath='{.spec.targetNamespace}')
else
log "No MCE resource detected on the current cluster. This is not an engine cluster (Previous errors can be safely ignored)."
fi
}
check_if_hub() {
log "Detecting Hub cluster by fetching MCH resource..."
if oc get multiclusterhubs.operator.open-cluster-management.io --all-namespaces; then
log "Detected MCH resource. This cluster has been verified as a hub cluster."
HUB_CLUSTER=true
else
log "No MCH resource detected on the current cluster. This is not a hub cluster (Previous errors can be safely ignored)."
fi
}
check_if_spoke() {
log "Detecting Managed cluster by fetching Klusterlet CRD..."
if oc get crd klusterlets.operator.open-cluster-management.io; then
log "The current cluster has klusterlets.operator.open-cluster-management.io crd, it is a spoke cluster."
SPOKE_CLUSTER=true
else
log "The current cluster does not have klusterlets.operator.open-cluster-management.io crd, it is not a spoke cluster."
fi
}
check_if_engine
check_if_spoke
if ${MCE_CLUSTER}; then
check_if_hub
if ${HUB_CLUSTER}; then
# NOTE: The `gather_all_logs` script includes `gather_mce_logs`
log "Running ACM MultiClusterHub Must-Gather"
${SCRIPT_DIR}/gather_all_logs
else
log "Running MulticlusterEngine Must-Gather"
${SCRIPT_DIR}/gather_mce_logs
fi
fi
if ${SPOKE_CLUSTER}; then
${SCRIPT_DIR}/gather_spoke_logs
fi
log "ACM must-gather complete."