File s390-tools-sles15sp4-dbginfo.sh-add_kubernetes.patch of Package s390-tools.29120

---
 scripts/dbginfo.sh   |   55 ++++++++++++++++++++++++++++++++++++++++++++-------
 scripts/dbginfo.sh.1 |   10 +++++----
 2 files changed, 54 insertions(+), 11 deletions(-)

--- a/scripts/dbginfo.sh
+++ b/scripts/dbginfo.sh
@@ -2,7 +2,7 @@
 #
 # dbginfo.sh - Tool to collect runtime, configuration, and trace information
 #
-# Copyright IBM Corp. 2002, 2021
+# Copyright IBM Corp. 2002, 2022
 #
 # s390-tools is free software; you can redistribute it and/or modify
 # it under the terms of the MIT license. See LICENSE for details.
@@ -25,6 +25,8 @@ readonly KERNEL_VERSION=$(echo ${KERNEL_
 readonly KERNEL_MAJOR_REVISION=$(echo ${KERNEL_BASE} | cut -d'.' -f2 )
 readonly KERNEL_MINOR_REVISION=$(echo ${KERNEL_BASE} | cut -d'.' -f3 | sed 's/[^0-9].*//g')
 readonly KERNEL_INFO=${KERNEL_VERSION}.${KERNEL_MAJOR_REVISION}.${KERNEL_MINOR_REVISION}
+readonly KUBERNETES=$(if type kubectl >/dev/null 2>&1; then echo "YES"; else echo "NO"; fi)
+readonly KUBERNETES_LOG_LINES=50
 readonly KVM=$(if which virsh >/dev/null 2>&1; then echo "YES"; else echo "NO"; fi)
 # The file to indicate that another instance of the script is already running
 readonly LOCKFILE="/tmp/${SCRIPTNAME}.lock"
@@ -79,7 +81,7 @@ This script collects runtime, configurat
 a Linux on IBM Z installation for debugging purposes.
 
 It also traces information about z/VM if the Linux runs under z/VM.
-KVM or DOCKER data ist collected on a host serving this.
+Virtualization platform data is collected on a host serving this.
 
 Default location for data collection and final tar file is "/tmp/".
 The collected information is written to a TAR archive named
@@ -149,7 +151,7 @@ $(cat /proc/sysinfo | grep 'Name')
 Kernel version        = ${KERNEL_INFO}
 OS version / distro   = ${OS_NAME}
 KVM host              = ${KVM}
-DOCKER host           = ${DOCKER}
+container host        Kubernetes: ${KUBERNETES} - docker: ${DOCKER}
 
 Current user          = $(whoami) (must be root for data collection)
 Date and time         = $(date)
@@ -248,6 +250,7 @@ readonly OUTPUT_FILE_ISW="${WORKPATH}ins
 readonly OUTPUT_FILE_TC="${WORKPATH}network.out"
 readonly OUTPUT_FILE_VMCMD="${WORKPATH}zvm_runtime.out"
 # Base file names for different output files - no extension !
+readonly OUTPUT_FILE_KUBERNETES="${WORKPATH}kubernetes"
 readonly OUTPUT_FILE_OSAOAT="${WORKPATH}network"
 readonly OUTPUT_FILE_SYSFS="${WORKPATH}sysfs"
 
@@ -267,7 +270,7 @@ ALL_STEPS="\
  collect_bridge\
  collect_ovs\
  collect_kvm\
- collect_docker\
+ collect_container\
  collect_nvme\
  collect_logfiles\
  post_processing\
@@ -519,6 +522,19 @@ DOCKER_CMDS="docker version\
   "
 
 ########################################
+KUBERNETES_CMDS="kubectl version\
+  :oc version   # get also OCP version if installed\
+  :kubectl top pod\
+  :kubectl top node\
+  :kubectl describe pod -A\
+  :kubectl describe node -A\
+  :kubectl describe endpoints\
+  :kubectl cluster-info dump\
+  :ls -l /var/log/containers # list of logs is sufficent\
+  :kubectl cluster-info dump >>${OUTPUT_FILE_KUBERNETES}.dmp\
+  "
+
+########################################
 VM_CMDS="q userid\
   :q users\
   :q privclass\
@@ -929,15 +945,21 @@ collect_ovs() {
 }
 
 ########################################
-collect_docker() {
+collect_container() {
     local container_list
     local network_list
     local item
 
-    # check if docker command exists
+    # check if container environment exists
+    if test "x${DOCKER}" = "xYES" || test "x${KUBERNETES}" = "xYES"; then
+        pr_collect_output "container host"
+    else
+        pr_skip "container host: not found"
+    fi
+
     if [ "x${DOCKER}" = "xYES" ];
     then
-        pr_collect_output "docker"
+        pr_syslog_stdout " docker ..."
         container_list=$(docker ps -qa)
         network_list=$(docker network ls -q)
         ifs_orig="${IFS}"
@@ -961,6 +983,25 @@ collect_docker() {
     else
         pr_skip "docker: not available"
     fi
+
+    # for kubectl command exists
+    if [ "x${KUBERNETES}" = "xYES" ]; then
+      pr_syslog_stdout " Kubernetes ..."
+      container_list=$(kubectl top pod | grep -v "MEMORY(bytes)" | cut -d' ' -f1)
+      ifs_orig="${IFS}"
+      IFS=:
+      for item in ${KUBERNETES_CMDS}; do
+        IFS=${ifs_orig} call_run_command "${item}" "${OUTPUT_FILE_KUBERNETES}.out"
+      done
+      IFS="${ifs_orig}"
+
+      if test -n "${container_list}"; then
+        for item in ${container_list}; do
+                 call_run_command "kubectl logs --tail=${KUBERNETES_LOG_LINES} ${item}"\
+                 "${OUTPUT_FILE_KUBERNETES}.log"
+        done
+      fi
+    fi
 }
 
 ########################################
--- a/scripts/dbginfo.sh.1
+++ b/scripts/dbginfo.sh.1
@@ -1,4 +1,4 @@
-.TH DBGINFO.SH  1 "September 2021" "s390-tools"
+.TH DBGINFO.SH  1 "September 2022" "s390-tools"
 
 .SH NAME
 dbginfo.sh \- collect runtime, configuration and trace information
@@ -14,7 +14,7 @@ for debugging Linux on IBM Z
 This script collects runtime, configuration and trace information that can
 be used to debug a Linux on IBM Z instance.
 For Linux on z/VM, the script also traces information about the z/VM system.
-KVM or DOCKER data ist collected on a host serving this.
+Virtualization platform data ist collected on a host serving this.
 
 The debug information is written to a file
 /<DIRECTORY>/DBGINFO\-<date>\-<time>\-<hostname>\-<processorid>.tgz
@@ -59,7 +59,7 @@ Sample invocation:
 .br
 dbginfo.sh: Debug information script version %S390_TOOLS_VERSION%
 .br
-Copyright IBM Corp. 2002, 2021
+Copyright IBM Corp. 2002, 2022
 .PP
 Hardware platform     = s390x
 .br
@@ -97,8 +97,10 @@ Date and time of info = 2021-08-26-15-27
 .PP
 13 of 18: Skip KVM: no virsh command
 .PP
-14 of 18: Collecting docker output
+14 of 18: Collecting container output
 .PP
+ Kubernetes ...
+.br
 15 of 18: Collecting NVME storage output
 .PP
 16 of 18: Collecting log files
openSUSE Build Service is sponsored by