Add log collection for kubernetes events and vcluster pods

Change-Id: I05d92f9a8241c9b98b9ef16a966ace1e7f5b389b
Signed-off-by: mesaj <juanmanuel.mesamendez.ext@telefonica.com>
diff --git a/jenkins/ci-pipelines/ci_stage_3.groovy b/jenkins/ci-pipelines/ci_stage_3.groovy
index 11b4755..6c49cda 100644
--- a/jenkins/ci-pipelines/ci_stage_3.groovy
+++ b/jenkins/ci-pipelines/ci_stage_3.groovy
@@ -516,7 +516,14 @@
 
 void archive_logs(Map remote) {
 
-    sshCommand remote: remote, command: '''mkdir -p logs/dags'''
+    sshCommand remote: remote, command: '''mkdir -p logs/dags logs/vcluster logs/events'''
+    // Collect Kubernetes events
+    sshCommand remote: remote, command: '''
+        echo "Extracting Kubernetes events"
+        kubectl get events --all-namespaces --sort-by='.lastTimestamp' -o wide > logs/events/k8s-events.log 2>&1 || true
+        kubectl get events -n osm --sort-by='.lastTimestamp' -o wide > logs/events/osm-events.log 2>&1 || true
+        kubectl get events -n vcluster --sort-by='.lastTimestamp' -o wide > logs/events/vcluster-events.log 2>&1 || true
+    '''
     if (useCharmedInstaller) {
         sshCommand remote: remote, command: '''
             for pod in `kubectl get pods -n osm | grep -v operator | grep -v NAME| awk '{print $1}'`; do
@@ -545,12 +552,21 @@
             echo "Extracting logs from Airflow DAGs from pod ${schedulerPod}"; \
             kubectl -n osm cp ${schedulerPod}:/opt/airflow/logs/scheduler/latest/dags logs/dags -c scheduler 2>&1 || true
         '''
+        // Collect vcluster namespace logs
+        sshCommand remote: remote, command: '''
+            echo "Extracting logs from vcluster namespace"
+            for pod in `kubectl get pods -n vcluster | grep -v NAME | awk '{print $1}'`; do
+                echo "Extracting log for vcluster pod: $pod"
+                kubectl logs -n vcluster $pod --timestamps=true --all-containers 2>&1 \
+                > logs/vcluster/$pod.log || true
+            done
+        '''
     }
 
     sh 'rm -rf logs'
-    sshCommand remote: remote, command: '''ls -al logs'''
+    sshCommand remote: remote, command: '''ls -al logs logs/vcluster logs/events'''
     sshGet remote: remote, from: 'logs', into: '.', override: true
-    archiveArtifacts artifacts: 'logs/*.log, logs/dags/*.log'
+    archiveArtifacts artifacts: 'logs/*.log, logs/dags/*.log, logs/vcluster/*.log, logs/events/*.log'
 }
 
 String get_value(String key, String output) {