summaryrefslogtreecommitdiffstats
path: root/kubernetes/oneclick
diff options
context:
space:
mode:
Diffstat (limited to 'kubernetes/oneclick')
-rwxr-xr-xkubernetes/oneclick/createAll.bash8
-rw-r--r--kubernetes/oneclick/tools/autoCleanConfig.bash54
-rw-r--r--kubernetes/oneclick/tools/autoCreateConfig.bash65
-rw-r--r--kubernetes/oneclick/tools/collectInfo.bash171
4 files changed, 297 insertions, 1 deletions
diff --git a/kubernetes/oneclick/createAll.bash b/kubernetes/oneclick/createAll.bash
index 72d852ded6..5a99b19623 100755
--- a/kubernetes/oneclick/createAll.bash
+++ b/kubernetes/oneclick/createAll.bash
@@ -84,7 +84,13 @@ create_onap_helm() {
fi
fi
- cmd=`echo helm install $LOCATION/$2/ --name $1-$2 --namespace $1 --set nsPrefix=$1,nodePortPrefix=$3 ${HELM_VALUES_ADDITION}`
+ # assign default auth token
+ if [[ -z $ONAP_DEFAULT_AUTH_TOKEN ]]; then
+ DEFAULT_SECRET=`kubectl get secrets -n $1-$2 | grep default-token | awk '{ print $1}'`
+ ONAP_DEFAULT_AUTH_TOKEN=`kubectl get secrets $DEFAULT_SECRET -n $1-$2 -o yaml | grep 'token:' | awk '{ print $2}' | base64 --decode`
+ fi
+
+ cmd=`echo helm install $LOCATION/$2/ --name $1-$2 --namespace $1 --set nsPrefix=$1,nodePortPrefix=$3,kubeMasterAuthToken=$ONAP_DEFAULT_AUTH_TOKEN ${HELM_VALUES_ADDITION}`
eval ${cmd}
check_return_code $cmd
}
diff --git a/kubernetes/oneclick/tools/autoCleanConfig.bash b/kubernetes/oneclick/tools/autoCleanConfig.bash
new file mode 100644
index 0000000000..e274e0d0c5
--- /dev/null
+++ b/kubernetes/oneclick/tools/autoCleanConfig.bash
@@ -0,0 +1,54 @@
+########################################################################################
+# This script wraps {$OOM}/kubernetes/oneclick/deleteAll.sh script along with #
+# the following steps to clean up ONAP configure for specified namespace: #
+# - remove namespace #
+# - remove release #
+# - remove shared directory #
+# #
+# To run it, just enter the following command: #
+# ./autoCleanConfig.bash <namespace, default is "onap"> #
+########################################################################################
+#!/bin/bash
+
+
+NS=$1
+if [[ -z $NS ]]
+then
+ echo "Namespace is not specified, use onap namespace."
+ NS="onap"
+fi
+
+echo "Clean up $NS configuration"
+cd ..
+./deleteAll.bash -n $NS -y
+cd -
+
+echo "----------------------------------------------
+Force remove namespace..."
+kubectl delete namespace $NS
+echo "...done : kubectl get namespace
+-----------------------------------------------
+>>>>>>>>>>>>>> k8s namespace"
+kubectl get namespace
+while [[ ! -z `kubectl get namespace|grep $NS` ]]
+do
+ echo "Wait for namespace $NS to be deleted
+-----------------------------------------------
+>>>>>>>>>>>>>> k8s namespace"
+ kubectl get namespace
+ sleep 2
+done
+
+echo "Force delete helm process ..."
+helm delete $NS-config --purge --debug
+echo "...done : helm ls --all
+ -----------------------------------------------
+>>>>>>>>>>>>>> helm"
+helm ls --all
+
+echo "Remove $NS dockerdata..."
+sudo rm -rf /dockerdata-nfs/onap
+echo "...done : ls -altr /dockerdata-nfs
+ -----------------------------------------------
+>>>>>>>>>>>>>> /dockerdata-nfs directory"
+ls -altr /dockerdata-nfs
diff --git a/kubernetes/oneclick/tools/autoCreateConfig.bash b/kubernetes/oneclick/tools/autoCreateConfig.bash
new file mode 100644
index 0000000000..99ea03e1bb
--- /dev/null
+++ b/kubernetes/oneclick/tools/autoCreateConfig.bash
@@ -0,0 +1,65 @@
+########################################################################################
+# This script wraps {$OOM}/kubernetes/config/createConfig.sh script #
+# and will only terminated when the configuration is Completed or failed #
+# #
+# To run it, just enter the following command: #
+# ./autoCreateConfig.bash <namespace, default is "onap"> #
+########################################################################################
+#!/bin/bash
+
+
+NS=$1
+if [[ -z $NS ]]
+then
+ echo "Namespace is not specified, use onap namespace."
+ NS="onap"
+fi
+
+echo "Create $NS config under config directory..."
+cd ../../config
+./createConfig.sh -n $NS
+cd -
+
+
+echo "...done : kubectl get namespace
+-----------------------------------------------
+>>>>>>>>>>>>>> k8s namespace"
+kubectl get namespace
+
+
+echo "
+-----------------------------------------------
+>>>>>>>>>>>>>> helm : helm ls --all"
+helm ls --all
+
+
+echo "
+-----------------------------------------------
+>>>>>>>>>>>>>> pod : kubectl get pods -n $NS -a"
+kubectl get pods -n $NS -a
+
+
+while true
+do
+ echo "wait for $NS config pod reach to Completed STATUS"
+ sleep 5
+ echo "-----------------------------------------------"
+ kubectl get pods -n $NS -a
+
+ status=`kubectl get pods -n $NS -a |grep config |xargs echo | cut -d' ' -f3`
+
+ if [ "$status" = "Completed" ]
+ then
+ echo "$NS config is Completed!!!"
+ break
+ fi
+
+ if [ "$status" = "Error" ]
+ then
+ echo "
+$NS config is failed with Error!!!
+Logs are:"
+ kubectl logs config -n $NS -f
+ break
+ fi
+done
diff --git a/kubernetes/oneclick/tools/collectInfo.bash b/kubernetes/oneclick/tools/collectInfo.bash
new file mode 100644
index 0000000000..734c5a6c62
--- /dev/null
+++ b/kubernetes/oneclick/tools/collectInfo.bash
@@ -0,0 +1,171 @@
+#!/bin/bash
+
+NS=
+OUT_NAME=onap_info_$(date +%y.%m.%d_%H.%M.%S.%N)
+OUT_FILE=
+OUT_DIR=$(dirname "$0")
+TMP_DIR=$(dirname $(mktemp -u))
+CONTAINER_LOGS_PATH=/var/log/onap
+CP_CONTAINER_LOGS=false
+
+if [ ! -z "$DEBUG" ]; then
+ set -x
+fi
+
+usage() {
+ cat <<EOF
+Utility script collecting various information about ONAP deployment on kubernetes.
+
+Usage: $0 [PARAMs]
+-u : Display usage
+-n [NAMESPACE] : Kubernetes namespace (required)
+-a [APP] : Specify a specific ONAP component (default: all)
+-d [OUT_DIR] : Specify output folder for the collected info pack file
+ (default: current dir)
+-f [OUT_FILE] : Specify output file for the collected info
+ (default: file name with timestamp)
+-c : Collect log files from containers, from path ${CONTAINER_LOGS_PATH}
+EOF
+}
+
+call_with_log() {
+ local _cmd=$1
+ local _log=$2
+ # Make sure otput dir exists
+ mkdir -p "$(dirname "$_log")"
+ printf "Command: ${_cmd}\n" >> ${_log}
+ printf "================================================================================\n" >> ${_log}
+ eval "${_cmd}" >> ${_log} 2>&1
+ printf "================================================================================\n" >> ${_log}
+}
+
+collect_pod_info() {
+ local _ns=$1
+ local _id=$2
+ local _log_dir=$3
+ local _cp_logs=$4
+ declare -i _i=0
+ kubectl -n $_ns get pods $_id -o=jsonpath='{range .spec.containers[*]}{.name}{"\n"}{end}' | while read c; do
+ call_with_log "kubectl -n $_ns logs $_id -c $c" "$_log_dir/$_id-$c.log"
+ if [ "$_i" -eq "0" ] && [ "$_cp_logs" == "true" ]; then
+ # copy logs from 1st container only as logs dir is shared between the containers
+ local _cmd="kubectl cp $_ns/$_id:${CONTAINER_LOGS_PATH} $_log_dir/$_id-$c -c $c"
+ if [ -z "$DEBUG" ]; then
+ _cmd+=" > /dev/null 2>&1"
+ fi
+ eval "${_cmd}"
+ fi
+ ((_i++))
+ done
+}
+
+collect_ns_info() {
+ local _ns=$1
+ local _log_dir=$2/$_ns
+ call_with_log "kubectl -n $NS-$i get services -o=wide" "$_log_dir/list_services.log"
+ kubectl -n "$_ns" get services | while read i; do
+ local _id=`echo -n $i | tr -s ' ' | cut -d' ' -n -f1`
+ if [ "$_id" == "NAME" ]; then
+ continue
+ fi
+ call_with_log "kubectl -n $_ns describe services $_id" "$_log_dir/describe_services/$_id.log"
+ done
+ call_with_log "kubectl -n $NS-$i get pods -o=wide" "$_log_dir/list_pods.log"
+ kubectl -n "$_ns" get pods | while read i; do
+ local _id=`echo -n $i | tr -s ' ' | cut -d' ' -n -f1`
+ if [ "$_id" == "NAME" ]; then
+ continue
+ fi
+ call_with_log "kubectl -n $_ns describe pods $_id" "$_log_dir/describe_pods/$_id.log"
+ collect_pod_info "$_ns" "$_id" "$_log_dir/logs" "${CP_CONTAINER_LOGS}"
+ done
+}
+
+while getopts ":un:a:d:f:c" PARAM; do
+ case $PARAM in
+ u)
+ usage
+ exit 1
+ ;;
+ n)
+ NS=${OPTARG}
+ ;;
+ a)
+ APP=${OPTARG}
+ if [[ -z $APP ]]; then
+ usage
+ exit 1
+ fi
+ ;;
+ d)
+ OUT_DIR=${OPTARG}
+ if [[ -z $OUT_DIR ]]; then
+ usage
+ exit 1
+ fi
+ ;;
+ f)
+ OUT_FILE=${OPTARG}
+ if [[ -z $OUT_FILE ]]; then
+ usage
+ exit 1
+ fi
+ ;;
+ c)
+ CP_CONTAINER_LOGS=true
+ ;;
+ ?)
+ usage
+ exit
+ ;;
+ esac
+done
+
+if [ -z "$NS" ]; then
+ usage
+ exit 1
+fi
+
+if [[ -z $OUT_FILE ]]; then
+ OUT_FILE=$OUT_NAME.tgz
+fi
+
+if [ ! -z "$APP" ]; then
+ _APPS=($APP)
+else
+ _APPS=(`kubectl get namespaces | grep "^$NS-" | tr -s ' ' | cut -d' ' -n -f1 | sed -e "s/^$NS-//"`)
+fi
+
+printf "Collecting information about ONAP deployment...\n"
+printf "Components: %s\n" "${_APPS[*]}"
+
+# Collect common info
+mkdir -p ${TMP_DIR}/${OUT_NAME}/
+echo "${_APPS[*]}" > ${TMP_DIR}/${OUT_NAME}/component-list.log
+printf "Collecting Helm info\n"
+call_with_log "helm version" "${TMP_DIR}/${OUT_NAME}/helm-version.log"
+call_with_log "helm list" "${TMP_DIR}/${OUT_NAME}/helm-list.log"
+
+printf "Collecting Kubernetes info\n"
+call_with_log "kubectl version" "${TMP_DIR}/${OUT_NAME}/k8s-version.log"
+call_with_log "kubectl get nodes -o=wide" "${TMP_DIR}/${OUT_NAME}/k8s-nodes.log"
+call_with_log "kubectl cluster-info" "${TMP_DIR}/${OUT_NAME}/k8s-cluster-info.log"
+call_with_log "kubectl cluster-info dump" "${TMP_DIR}/${OUT_NAME}/k8s-cluster-info-dump.log"
+call_with_log "kubectl top node" "${TMP_DIR}/${OUT_NAME}/k8s-top-node.log"
+
+# Collect per-component info
+for i in ${_APPS[@]}; do
+ printf "Writing Kubernetes info of component $i\n"
+ collect_ns_info "$NS-$i" "${TMP_DIR}/${OUT_NAME}"
+done
+
+# Pack and cleanup
+mkdir -p ${OUT_DIR}
+_OUT_DIR=`readlink -e ${OUT_DIR}`
+printf "Packing output to ${_OUT_DIR}/${OUT_FILE}...\n"
+cd ${TMP_DIR}
+tar cfz ${_OUT_DIR}/${OUT_FILE} ${OUT_NAME}
+cd -
+printf "Cleaning up...\n"
+rm -rf ${TMP_DIR}/${OUT_NAME}
+printf "Done\n"