Joey Armstrong | af679da | 2023-01-31 14:22:41 -0500 | [diff] [blame] | 1 | #!/usr/bin/env groovy |
| 2 | // ----------------------------------------------------------------------- |
Joey Armstrong | d548772 | 2024-02-11 09:39:14 -0500 | [diff] [blame] | 3 | // Copyright 2021-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Joey Armstrong | af679da | 2023-01-31 14:22:41 -0500 | [diff] [blame] | 4 | // |
| 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 Scandolo | d82d1de | 2021-04-06 14:55:58 -0700 | [diff] [blame] | 17 | // 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 Armstrong | af679da | 2023-01-31 14:22:41 -0500 | [diff] [blame] | 19 | // ----------------------------------------------------------------------- |
| 20 | |
Joey Armstrong | d548772 | 2024-02-11 09:39:14 -0500 | [diff] [blame] | 21 | // ----------------------------------------------------------------------- |
| 22 | // ----------------------------------------------------------------------- |
| 23 | String 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 | // ----------------------------------------------------------------------- |
| 33 | void 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 | // ----------------------------------------------------------------------- |
| 43 | void 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) { |
| 54 | Boolean 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 Scandolo | d82d1de | 2021-04-06 14:55:58 -0700 | [diff] [blame] | 61 | mkdir -p ${dest} |
Joey Armstrong | d548772 | 2024-02-11 09:39:14 -0500 | [diff] [blame] | 62 | |
Matteo Scandolo | 8b62af3 | 2021-05-25 08:41:12 -0700 | [diff] [blame] | 63 | # only tee the main infos |
Matteo Scandolo | d82d1de | 2021-04-06 14:55:58 -0700 | [diff] [blame] | 64 | kubectl get pods --all-namespaces -o wide | tee ${dest}/pods.txt || true |
Matteo Scandolo | 8b62af3 | 2021-05-25 08:41:12 -0700 | [diff] [blame] | 65 | 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 Armstrong | d548772 | 2024-02-11 09:39:14 -0500 | [diff] [blame] | 70 | 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 Scandolo | d82d1de | 2021-04-06 14:55:58 -0700 | [diff] [blame] | 76 | 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 Armstrong | d548772 | 2024-02-11 09:39:14 -0500 | [diff] [blame] | 78 | """) |
| 79 | |
| 80 | return(true) |
Matteo Scandolo | d82d1de | 2021-04-06 14:55:58 -0700 | [diff] [blame] | 81 | } |
Joey Armstrong | d548772 | 2024-02-11 09:39:14 -0500 | [diff] [blame] | 82 | |
| 83 | // ----------------------------------------------------------------------- |
| 84 | // ----------------------------------------------------------------------- |
| 85 | // def call(Map config=[:]) |
| 86 | def call(String dest) |
| 87 | { |
Joey Armstrong | f1aaa04 | 2024-02-11 12:07:22 -0500 | [diff] [blame] | 88 | Map config = [:] // Map config = config ?: [:] |
Joey Armstrong | d548772 | 2024-02-11 09:39:14 -0500 | [diff] [blame] | 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] |