|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +##### Initialize Variables |
| 4 | +OSB="OCI Service Broker" |
| 5 | +KGP="kubectl get pods" |
| 6 | + |
| 7 | + |
| 8 | +#Function for Priting the Start of Diagnostic Tool |
| 9 | +function start_tool() |
| 10 | +{ |
| 11 | + echo -e "\n===============================Starting OCI Service Broker Diagnostic Tool=======================================\n\n\n"; |
| 12 | +} |
| 13 | + |
| 14 | +#Function for Printing the Stop of Diagnostic Tool |
| 15 | +function stop_tool() |
| 16 | +{ |
| 17 | + echo -e "\n\n\n===============================OCI Service Broker Diagnostic Tool Completed======================================"; |
| 18 | +} |
| 19 | + |
| 20 | +#Function for Border Print |
| 21 | +function border_print() |
| 22 | +{ |
| 23 | + echo -e "\n******************************************************************************************************************" |
| 24 | +} |
| 25 | + |
| 26 | +#Function for Collecting logs |
| 27 | +#Parameter Details: |
| 28 | +#$1 - Name of the OCI Service Broker |
| 29 | +#$2 - OCI Service Broker name in the Helm Release |
| 30 | +#$3 - OCI Service Broker namespace |
| 31 | +#$4 - Service Catalog namespace |
| 32 | +#$5 - OCI Service Broker Pod Name |
| 33 | +function collect_logs () |
| 34 | +{ |
| 35 | + border_print |
| 36 | + echo -e "\n\nCollecting $1 Related Logs : " |
| 37 | + fol_name="OSB-Logs"-$(date "+%Y%m%d-%H%M%S") |
| 38 | + fol="/tmp/"$fol_name |
| 39 | + mkdir $fol |
| 40 | + # OCI Service Broker Logs |
| 41 | + kubectl -n $3 logs $5 -c oci-service-broker > $fol/osb_pod.log |
| 42 | + # Helm ls logs |
| 43 | + helm ls $2 --namespace $3 > $fol/helm_ls.log |
| 44 | + # Helm Values Changed Logs |
| 45 | + helm get values $2 > $fol/helm_values_changed.log |
| 46 | + # Kubectl get all for OCI Service Broker Namespace Logs |
| 47 | + kubectl get all -n $3 > $fol/kubectl_get_all_osb_ns.log |
| 48 | + # Kubectl get all for Catalog Namespace Logs |
| 49 | + kubectl get all -n $4 > $fol/kubectl_get_all_catalog_ns.log |
| 50 | + # svcat for brokers, instances, bindings Logs |
| 51 | + svcat get brokers -n $3 -o yaml > $fol/svcat_brokers.log |
| 52 | + svcat get instances -n $3 > $fol/svcat_instances.log |
| 53 | + svcat get bindings -n $3 > $fol/svcat_bindings.log |
| 54 | + # Kubectl describe OCI Service Broker Logs |
| 55 | + kubectl -n $3 describe pod $5 > $fol/osb_pod_describe.log |
| 56 | + zip -qq -r $fol.zip $fol/ |
| 57 | + rm -rf $fol/ |
| 58 | + echo -e "The Logs are available at " $fol.zip ". Please share this zip file with OCI Service Broker dev team." |
| 59 | +} |
| 60 | + |
| 61 | +function usage_info() |
| 62 | +{ |
| 63 | + echo -e "################################################################################################################\n" |
| 64 | + echo "OCI Service Diagnostics Tool needs 2 arguments i.e., OCI Service Broker Namespace and Service Catalog Namespace" |
| 65 | + echo -e "\nUsage:\n ./osb_diagnostics.sh <OCI-Service-Broker-Namespace> <Service-Catalog-Namespace>\n" |
| 66 | + echo -e "################################################################################################################\n" |
| 67 | +} |
| 68 | + |
| 69 | +############################################################################################################################# |
| 70 | +#### Starting of the OSB Diagnostic Tool |
| 71 | +start_tool |
| 72 | + |
| 73 | +if [ "$1" == "-h" ] || [ "$1" == "--help" ] |
| 74 | +then |
| 75 | + usage_info |
| 76 | + exit 0 |
| 77 | +elif [ $# -le 1 ] |
| 78 | +then |
| 79 | + usage_info |
| 80 | + exit 1 |
| 81 | +fi |
| 82 | + |
| 83 | +##### Checking the Kube Config Env Variable |
| 84 | +if [ -z "$KUBECONFIG" ] |
| 85 | +then |
| 86 | + echo -e "KUBECONFIG environment variable is not set. Hence this tool will use the default kube config." |
| 87 | +else |
| 88 | + echo -e "Output of KUBECONFIG env variable : " $KUBECONFIG |
| 89 | +fi |
| 90 | + |
| 91 | +svcat_ver=`svcat version` |
| 92 | +if [ -z "$svcat_ver" ] |
| 93 | +then |
| 94 | + echo -e "\nsvcat tool is not installed to verify whether Service Catalog is running and able to connect to $OSB\n" |
| 95 | + echo -e "Please follow the instructions in https://svc-cat.io/docs/install/#installing-the-service-catalog-cli to install svcat tool" |
| 96 | + stop_tool |
| 97 | + exit 1 |
| 98 | +fi |
| 99 | + |
| 100 | +### Service Catalog Related Diagnostics |
| 101 | +CATALOG_NS=$2 |
| 102 | +OSB_NS=$1 |
| 103 | +ctlg_pods=($($KGP -n $CATALOG_NS | grep catalog | xargs)) |
| 104 | +if [ -z "$ctlg_pods" ] |
| 105 | +then |
| 106 | + echo -e "\nService Catalog is not running in the given Namespace. Exiting the Tool." |
| 107 | + stop_tool |
| 108 | + exit 1; |
| 109 | +fi |
| 110 | +border_print |
| 111 | +echo -e "\nBelow are the Service Catalog pods:\n" |
| 112 | +$KGP -n $CATALOG_NS | grep catalog |
| 113 | + |
| 114 | +### OCI Service Broker Related Diagnostics |
| 115 | +osb_pod_out=$($KGP -n $OSB_NS | grep "oci-service-broker" | head -1) |
| 116 | +if [ -z "$osb_pod_out" ] |
| 117 | +then |
| 118 | + echo -e "\n$OSB is not running in the given Namespace. Exiting the Tool." |
| 119 | + stop_tool |
| 120 | + exit 1; |
| 121 | +fi |
| 122 | +border_print |
| 123 | +echo -e "\nBelow are the $OSB pods: \n" |
| 124 | +$KGP -n $OSB_NS | grep "oci-service-broker" |
| 125 | + |
| 126 | +osb_name=$(echo $osb_pod_out | awk '{split($0,a," "); print a[1]}' | awk '{split($0,b,"-oci-service-broker-"); print b[1]}') |
| 127 | +osb_pod_status=$(echo $osb_pod_out | awk '{split($0,a," "); print a[3]}') |
| 128 | +osb_pod_name=$(echo $osb_pod_out | cut -d" " -f1) |
| 129 | + |
| 130 | +catalog_name=$($KGP -n $CATALOG_NS | grep "catalog-apiserver" | awk '{split($0,a," "); print a[1]}' | awk '{split($0,b,"-catalog-apiserver-"); print b[1]}') |
| 131 | + |
| 132 | +##### Helm List |
| 133 | +border_print |
| 134 | +echo -e "Helm List of OCI Service Broker\n" |
| 135 | +helm ls $osb_name --namespace=$OSB_NS |
| 136 | +echo -e "\nHelm List of Service Catalog\n" |
| 137 | +helm ls $catalog_name --namespace=$CATALOG_NS |
| 138 | + |
| 139 | +if [ ! -z $osb_pod_status ] |
| 140 | +then |
| 141 | + if [ $osb_pod_status = "ContainerCreating" ] |
| 142 | + then |
| 143 | + oci_cred_miss=`kubectl -n $OSB_NS describe pod $osb_pod_name | grep 'secrets "ocicredentials" not found'` |
| 144 | + if [ ! -z oci_cred_miss ] |
| 145 | + then |
| 146 | + echo -e -n "\nOCI Credentails Kubernetes secret is Missing. Follow link --> (https://github.com/oracle/oci-service-broker/blob/master/charts/oci-service-broker/docs/installation.md#oci-credentials) " |
| 147 | + echo -e "to create the user credentials with valid information.\n" |
| 148 | + fi |
| 149 | + elif [ $osb_pod_status = "CrashLoopBackOff" ] |
| 150 | + then |
| 151 | + echo -e "\nThe OCI Service Broker Pod is in CrashLoopBackOff State." |
| 152 | + auth_err_msg=$(kubectl -n $OSB_NS logs $osb_pod_name -c oci-service-broker | grep "Authentication failed") |
| 153 | + if [ ! -z "$auth_err_msg" ] |
| 154 | + then |
| 155 | + echo -e "\nOCI Credentials Kubernetes secret: \n" |
| 156 | + kubectl get secret ocicredentials -n $OSB_NS |
| 157 | + echo -e -n "\nOCI Credentials Kubernetes secret is having Invalid credentails. Follow link --> (https://github.com/oracle/oci-service-broker/blob/master/charts/oci-service-broker/docs/installation.md#oci-credentials) " |
| 158 | + echo -e "to create the user credentials with valid information.\n" |
| 159 | + fi |
| 160 | + collect_logs "$OSB" "$osb_name" "$OSB_NS" "$CATALOG_NS" "$osb_pod_name" |
| 161 | + stop_tool |
| 162 | + exit 0; |
| 163 | + fi |
| 164 | +fi |
| 165 | + |
| 166 | +border_print |
| 167 | +echo -e "\nsvcat get brokers Output:\n" |
| 168 | +svcat get brokers |
| 169 | + |
| 170 | +svcat_brk_out=`svcat get brokers | awk 'NR>2 { print $1}'` |
| 171 | +brk_count=$(($(svcat get brokers | wc -l) -2)) |
| 172 | +if [ $brk_count -gt 1 ] |
| 173 | +then |
| 174 | + echo -e "\nTotal number of OCI Service Brokers registered is : " $brk_count |
| 175 | + echo -e "If multiple OCI Service Brokers is registered, only one broker can be in Ready State.\n" |
| 176 | +elif [ $brk_count -eq 0 ] |
| 177 | +then |
| 178 | + echo -e "\n$OSB is not yet registered with Service Catalog. Please use the yaml at charts/oci-service-broker/samples/oci-service-broker.yaml to register\n" |
| 179 | +fi |
| 180 | +q=1 |
| 181 | +while [ $q -le $brk_count ] |
| 182 | +do |
| 183 | + border_print |
| 184 | + brk_name=$(echo $svcat_brk_out | cut -d " " -f $q) |
| 185 | + echo "" |
| 186 | + echo -e "Broker : " $brk_name " \nStatus : \n" |
| 187 | + svcat_brk_status=($(svcat get broker $brk_name | grep "$brk_name" | awk '{split($0,a," "); print a[3] }' )) |
| 188 | + osb_url=`svcat get broker $brk_name | grep "$brk_name" | awk '{split($0,a," "); print a[2] }'` |
| 189 | + |
| 190 | + if [ $svcat_brk_status = "Ready" ] |
| 191 | + then |
| 192 | + echo -e "$OSB is successfully installed and able to communicate with Service Catalog" |
| 193 | + elif [ $svcat_brk_status = "ErrorFetchingCatalog" ] |
| 194 | + then |
| 195 | + echo -e "$OSB is unable to communicate with the Service Catalog." |
| 196 | + if [ $CATALOG_NS != $OSB_NS ] |
| 197 | + then |
| 198 | + echo -e "\nService Catalog and $OSB are in different Namespaces." |
| 199 | + fi |
| 200 | + echo -e "Please check the URL ($osb_url) used in oci-service-broker.yaml is valid and re-register based on documentation." |
| 201 | + fi |
| 202 | + q=$(($q + 1)) |
| 203 | +done |
| 204 | + |
| 205 | +collect_logs "$OSB" "$osb_name" "$OSB_NS" "$CATALOG_NS" "$osb_pod_name" |
| 206 | +stop_tool |
| 207 | + |
| 208 | + |
| 209 | + |
0 commit comments