[VOL-5020] Update helm charts for repo:voltha-tracing
vars/getPodsInfo.groovy
-----------------------
o Add debugging
o Display ENTER/LEAVE banners when the script is called.
o Wrap logic in a try/catch/finally block to help expose
another silent failure source.
.groovylintrc.json
------------------
o Added an exclusion file to filter some basic opinion
based options that are filing the lint report.
jjb/verify/bbsim-sadis-server.yaml
jjb/verify/bbsim.yaml
----------------------------------
o *.yaml edit made for side effects.
o Regenerate JJB pipelines.
vars/iam.groovy
---------------
o Need to revisit this script, debugging flag added.
o Script creates a closure for invoking pipeline tasks.
o Automates wrapping task with try/catch/finally/ran-to-completion.
o Automates wrapping task with display of ENTER/LEAVE banner.
Change-Id: I1437c336a1fb75a7723c397716f07ce00c1d00ce
diff --git a/.groovylintrc.json b/.groovylintrc.json
new file mode 100644
index 0000000..3392108
--- /dev/null
+++ b/.groovylintrc.json
@@ -0,0 +1,46 @@
+{
+ "extends": "all",
+ "rules": {
+ "basic.DeadCode": "error",
+ "convention.CompileStatic": {
+ "severity": "info"
+ },
+ "convention.FieldTypeRequired": "info",
+ "convention.IfStatementCouldBeTernary": "info",
+ "convention.NoDef": "info",
+ "convention.TrailingComma": "off",
+ "convention.VariableTypeRequired": "info",
+ "dry.DuplicateListLiteral": "info",
+ "dry.DuplicateMapLiteral": "warning",
+ "dry.DuplicateNumberLiteral": {
+ "ignoreNumbers": [0, 1, 2, 3, -1],
+ "severity": "info"
+ },
+ "dry.DuplicateStringLiteral": "info",
+ "exceptions.ThrowException": "info",
+ "exceptions.ThrowNullPointerException": "info",
+ "exceptions.ThrowRuntimeException": "info",
+ "exceptions.ThrowThrowable": "info",
+ "formatting.BracesForClass": "info",
+ "formatting.BracesForForLoop": "info",
+ "formatting.BracesForIfElse": "off",
+ "formatting.BracesForMethod": "off",
+ "formatting.BracesForTryCatchFinally": "off",
+ "formatting.Indentation": {
+ "spacesPerIndentLevel": 4,
+ "severity": "info"
+ },
+ "formatting.SpaceAroundMapEntryColon": "off",
+ "groovyism.ExplicitCallToEqualsMethod": "info",
+ "logging.Println": "off",
+ "unused.UnusedArray": "error",
+ "unused.UnusedObject": "error",
+ "unused.UnusedPrivateField": "error",
+ "unused.UnusedPrivateMethod": "error",
+ "unused.UnusedPrivateMethodParameter": "error",
+ "unused.UnusedVariable": "error",
+ "unnecessary.UnnecessaryReturnKeyword": "off"
+ },
+ "see-also" : {
+ ".groovylintrc-recommended.json" : "https://github.com/nvuillam/npm-groovy-lint/blob/main/lib/.groovylintrc-recommended.json" }
+}
diff --git a/jjb/verify/bbsim-sadis-server.yaml b/jjb/verify/bbsim-sadis-server.yaml
index 0e5a5e0..7460606 100644
--- a/jjb/verify/bbsim-sadis-server.yaml
+++ b/jjb/verify/bbsim-sadis-server.yaml
@@ -59,4 +59,4 @@
docker-repo: 'voltha'
dependency-jobs: 'version-tag_wildcard'
-# [EOF] x 2
+# [EOF] x 3
diff --git a/jjb/verify/bbsim.yaml b/jjb/verify/bbsim.yaml
index 65008b7..8036d72 100644
--- a/jjb/verify/bbsim.yaml
+++ b/jjb/verify/bbsim.yaml
@@ -144,4 +144,4 @@
release-targets: 'release'
artifact-glob: 'release/*'
-# [EOF] x 2-
+# [EOF] x 3
diff --git a/vars/getPodsInfo.groovy b/vars/getPodsInfo.groovy
index 599a824..ecd785c 100644
--- a/vars/getPodsInfo.groovy
+++ b/vars/getPodsInfo.groovy
@@ -1,6 +1,6 @@
#!/usr/bin/env groovy
// -----------------------------------------------------------------------
-// Copyright 2021-2023 Open Networking Foundation (ONF) and the ONF Contributors
+// Copyright 2021-2024 Open Networking Foundation (ONF) and the ONF Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -18,9 +18,48 @@
// the only parameter required is the destination folder to store the collected information
// -----------------------------------------------------------------------
-def call(String dest) {
- sh """
+// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
+String getIam(String func) {
+ // Cannot rely on a stack trace due to jenkins manipulation
+ String src = 'vars/getPodsInfo.groovy'
+ String iam = [src, func].join('::')
+ return iam
+}
+
+// -----------------------------------------------------------------------
+// Intent: Log progress message
+// -----------------------------------------------------------------------
+void enter(String name) {
+ // Announce ourselves for log usability
+ String iam = getIam(name)
+ println("${iam}: ENTER")
+ return
+}
+
+// -----------------------------------------------------------------------
+// Intent: Log progress message
+// -----------------------------------------------------------------------
+void leave(String name) {
+ // Announce ourselves for log usability
+ String iam = getIam(name)
+ println("${iam}: LEAVE")
+ return
+}
+
+// -----------------------------------------------------------------------
+// Intent: Script workhorse
+// -----------------------------------------------------------------------
+// def call(String dest) {
+Boolean process(String dest)
+{
+ // [TODO] post release remove '|| true'
+ // Map cmds = [ label : { cmd, file } ]
+ // cmds.for{ rec -> sh("cmd > file")
+
+ sh("""
mkdir -p ${dest}
+
# only tee the main infos
kubectl get pods --all-namespaces -o wide | tee ${dest}/pods.txt || true
helm ls --all-namespaces | tee ${dest}/helm-charts.txt
@@ -28,9 +67,42 @@
# everything else should not be dumped on the console
kubectl get svc --all-namespaces -o wide > ${dest}/svc.txt || true
kubectl get pvc --all-namespaces -o wide > ${dest}/pvcs.txt || true
- kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\n'}" | sort | uniq > ${dest}/pod-images.txt || true
- kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.imageID}{'\\n'}" | sort | uniq > ${dest}/pod-imagesId.txt || true
+ kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\n'}" \
+ | sort \
+ | uniq > ${dest}/pod-images.txt || true
+ kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.imageID}{'\\n'}" \
+ | sort \
+ | uniq > ${dest}/pod-imagesId.txt || true
kubectl describe pods --all-namespaces -l app.kubernetes.io/part-of=voltha > ${dest}/voltha-pods-describe.txt
kubectl describe pods --all-namespaces -l app=onos-classic > ${dest}/onos-pods-describe.txt
- """
+""")
+
+ return(true)
}
+
+// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
+// def call(Map config=[:])
+def call(String dest)
+{
+ Map config ?: [:]
+
+ try
+ {
+ enter('main')
+ process(dest)
+ }
+ catch (Exception err) // groovylint-disable-line CatchException
+ {
+ String iam = getIam('process')
+ println("** ${iam}: EXCEPTION ${err}")
+ throw err
+ }
+ finally
+ {
+ leave('main')
+ }
+ return
+}
+
+// [EOF]
diff --git a/vars/iam.groovy b/vars/iam.groovy
index e50fc8d..bb33214 100644
--- a/vars/iam.groovy
+++ b/vars/iam.groovy
@@ -1,6 +1,6 @@
#!/usr/bin/env groovy
// -----------------------------------------------------------------------
-// Copyright 2023 Open Networking Foundation (ONF) and the ONF Contributors
+// Copyright 2023-2024 Open Networking Foundation (ONF) and the ONF Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -61,8 +61,8 @@
Boolean process(Map argv)
{
String iam = getIam(argv, 'process')
-
- Boolean leave = false
+ Boolean debug ?: argv.debug
+ Boolean leave ?: argv.leave
// Identify caller with a banner for logging
if (config.containsKey('enter')) {
@@ -71,9 +71,14 @@
else if (config.containsKey('leave')) {
leave = true
}
- else
- {
- println("** ${iam}: HELLO")
+ else if (debug) {
+ println("** ${iam}: DEBUG=true")
+ }
+
+ // Invoke closure passed in
+ if (config.containsKey('invoke')) {
+ Closure invoke = argv.invoke
+ invoke()
}
// Display future enhancement list
@@ -91,11 +96,16 @@
}
// -----------------------------------------------------------------------
-// Intent: Debug method for jenkins jobs identifying caller for logging.
+// Intent: Wrap functions/DSL tokens within a closure to improve logging
+// o Issue a startup banner
+// o Invoke task wrapped within the iam(){} closure
+// o Detect exception/early termination and hilight that detail.
+// o Issue a shutdown banner
// -----------------------------------------------------------------------
// Given:
// self jenkins environment pointer 'this'
// config groovy closure used to pass key/value pairs into argv
+// invoke Groovy closure to invoke: (ENTER, closure, LEAVE)
// enter Display "** {iam} ENTER"
// leave Display "** {iam} LEAVE"
// todo Display future enhancement list
@@ -106,8 +116,10 @@
// o called from a jenkins {pipeline,stage,script} block.
// o iam(this)
// {
-// foo = bar // paramter foo is...
-// tans = fans
+// debug = false
+// enter = true
+// invoke = { println('hello from closure') }
+// leave = true
// }
// -----------------------------------------------------------------------
Boolean call\
@@ -122,7 +134,9 @@
body.delegate = argv
body()
+ // Running within closure
String iam = getIam(argv, 'main')
+ Booelan debug ?: argv.debug
println("** ${iam}: argv=${argv}")
@@ -140,7 +154,7 @@
ranToCompletion = true
}
}
- catch (Exception err)
+ catch (Exception err) // groovylint-disable-line CatchException
{
println("** ${iam}: EXCEPTION ${err}")
throw err
@@ -162,6 +176,7 @@
* -----------------------------------------------------------------------
[SEE ALSO]
o https://rtyler.github.io/jenkins.io/doc/book/pipeline/shared-libraries/#defining-a-more-structured-dsl
+ o https://blog.mrhaki.com/2009/11/groovy-goodness-passing-closures-to.html
* -----------------------------------------------------------------------
*/