blob: ecd785c279ef025674c37bb539022dabca8afe5c [file] [log] [blame]
Joey Armstrongaf679da2023-01-31 14:22:41 -05001#!/usr/bin/env groovy
2// -----------------------------------------------------------------------
Joey Armstrongd5487722024-02-11 09:39:14 -05003// Copyright 2021-2024 Open Networking Foundation (ONF) and the ONF Contributors
Joey Armstrongaf679da2023-01-31 14:22:41 -05004//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16// -----------------------------------------------------------------------
Matteo Scandolod82d1de2021-04-06 14:55:58 -070017// This keyword will get all the kubernetes pods info needed for debugging
18// the only parameter required is the destination folder to store the collected information
Joey Armstrongaf679da2023-01-31 14:22:41 -050019// -----------------------------------------------------------------------
20
Joey Armstrongd5487722024-02-11 09:39:14 -050021// -----------------------------------------------------------------------
22// -----------------------------------------------------------------------
23String getIam(String func) {
24 // Cannot rely on a stack trace due to jenkins manipulation
25 String src = 'vars/getPodsInfo.groovy'
26 String iam = [src, func].join('::')
27 return iam
28}
29
30// -----------------------------------------------------------------------
31// Intent: Log progress message
32// -----------------------------------------------------------------------
33void enter(String name) {
34 // Announce ourselves for log usability
35 String iam = getIam(name)
36 println("${iam}: ENTER")
37 return
38}
39
40// -----------------------------------------------------------------------
41// Intent: Log progress message
42// -----------------------------------------------------------------------
43void leave(String name) {
44 // Announce ourselves for log usability
45 String iam = getIam(name)
46 println("${iam}: LEAVE")
47 return
48}
49
50// -----------------------------------------------------------------------
51// Intent: Script workhorse
52// -----------------------------------------------------------------------
53// def call(String dest) {
54Boolean process(String dest)
55{
56 // [TODO] post release remove '|| true'
57 // Map cmds = [ label : { cmd, file } ]
58 // cmds.for{ rec -> sh("cmd > file")
59
60 sh("""
Matteo Scandolod82d1de2021-04-06 14:55:58 -070061 mkdir -p ${dest}
Joey Armstrongd5487722024-02-11 09:39:14 -050062
Matteo Scandolo8b62af32021-05-25 08:41:12 -070063 # only tee the main infos
Matteo Scandolod82d1de2021-04-06 14:55:58 -070064 kubectl get pods --all-namespaces -o wide | tee ${dest}/pods.txt || true
Matteo Scandolo8b62af32021-05-25 08:41:12 -070065 helm ls --all-namespaces | tee ${dest}/helm-charts.txt
66
67 # everything else should not be dumped on the console
68 kubectl get svc --all-namespaces -o wide > ${dest}/svc.txt || true
69 kubectl get pvc --all-namespaces -o wide > ${dest}/pvcs.txt || true
Joey Armstrongd5487722024-02-11 09:39:14 -050070 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\n'}" \
71 | sort \
72 | uniq > ${dest}/pod-images.txt || true
73 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.imageID}{'\\n'}" \
74 | sort \
75 | uniq > ${dest}/pod-imagesId.txt || true
Matteo Scandolod82d1de2021-04-06 14:55:58 -070076 kubectl describe pods --all-namespaces -l app.kubernetes.io/part-of=voltha > ${dest}/voltha-pods-describe.txt
77 kubectl describe pods --all-namespaces -l app=onos-classic > ${dest}/onos-pods-describe.txt
Joey Armstrongd5487722024-02-11 09:39:14 -050078""")
79
80 return(true)
Matteo Scandolod82d1de2021-04-06 14:55:58 -070081}
Joey Armstrongd5487722024-02-11 09:39:14 -050082
83// -----------------------------------------------------------------------
84// -----------------------------------------------------------------------
85// def call(Map config=[:])
86def call(String dest)
87{
88 Map config ?: [:]
89
90 try
91 {
92 enter('main')
93 process(dest)
94 }
95 catch (Exception err) // groovylint-disable-line CatchException
96 {
97 String iam = getIam('process')
98 println("** ${iam}: EXCEPTION ${err}")
99 throw err
100 }
101 finally
102 {
103 leave('main')
104 }
105 return
106}
107
108// [EOF]