From 26bf526d7cd33f949c32ac23564d21360bf8d7c1 Mon Sep 17 00:00:00 2001
From: Leonardo Rossetti <lrossett@redhat.com>
Date: Feb 24 2022 16:47:56 +0000
Subject: molecule test jobs


---

diff --git a/defs/jobs/operator-sdk/molecule-test/Jenkinsfile b/defs/jobs/operator-sdk/molecule-test/Jenkinsfile
new file mode 100644
index 0000000..0fd021b
--- /dev/null
+++ b/defs/jobs/operator-sdk/molecule-test/Jenkinsfile
@@ -0,0 +1,74 @@
+#!groovy
+
+def git_url = params.GIT_URL
+def git_refs = params.GIT_REFS
+
+def node_sh(cmd, username='root') {
+    def key_path = '/duffy-ssh-key/ssh-privatekey'
+    def vars = [
+        [var: 'node_hostname', password: node_hostname]
+    ]
+    def regexes = [
+        [regex: ',([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\'']
+    ]
+
+    wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: vars, varMaskRegexes: regexes]) {
+        sh "ssh -o StrictHostKeyChecking=no ${username}@${node_hostname} -i ${key_path} '${cmd}'"
+    }
+}
+
+node('cico-workspace') {
+    stage('cico') {
+        node = sh(script: "cico --debug node get --release 8-stream -f value -c hostname -c comment", returnStdout: true).trim().tokenize(' ')
+        env.node_hostname = "${node[0]}.ci.centos.org"
+        env.node_ssid = "${node[1]}"
+
+        wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[var: 'node_hostname', password: node_hostname]], varMaskRegexes: []]) {
+            node_sh 'cat /etc/centos-release'
+        }
+    }
+
+    stage('dependencies') {
+        // system packages
+        node_sh 'yum install -y make rust cargo podman python3-devel python3-pip python3-setuptools python3-setuptools-*'
+
+        //pip packages
+        node_sh 'pip3 install wheel setuptools-rust'
+        node_sh 'pip3 install ansible molecule'
+        
+        //kustomize
+        node_sh 'curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash'
+        node_sh 'mv kustomize /usr/bin/kustomize'
+        node_sh 'chmod +x /usr/bin/kustomize'
+
+        //minikube
+        node_sh 'curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64'
+        node_sh 'install minikube-linux-amd64 /usr/local/bin/minikube'
+    }
+
+    stage('prepare') {
+        node_sh 'adduser kubesig'
+        node_sh 'usermod -aG wheel kubesig'
+        node_sh 'echo "kubesig ALL=(ALL) NOPASSWD: /usr/bin/podman" >> /etc/sudoers'
+    }
+
+    stage('checkout') {
+        dir('koji-operator') {
+            git branch: git_refs, url: git_url
+
+            node_sh "mkdir -p /tmp/koji-operator"
+
+            wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[var: 'node_hostname', password: node_hostname]], varMaskRegexes: []]) {
+                sh "scp -o StrictHostKeyChecking=no -i /duffy-ssh-key/ssh-privatekey -r operator/* root@${node_hostname}:/tmp/koji-operator"
+            }
+        }
+    }
+
+    stage('test') {
+        node_sh '(cd /tmp/koji-operator; sudo -h kubesig bash -c \'MINIKUBE_DRIVER=podman molecule test -s minikube\')'
+    }
+    
+    stage('cleanup') {
+        sh "cico node done ${node_ssid}"
+    }
+}
\ No newline at end of file
diff --git a/defs/jobs/operator-sdk/molecule-test/job.yaml b/defs/jobs/operator-sdk/molecule-test/job.yaml
new file mode 100644
index 0000000..240c90d
--- /dev/null
+++ b/defs/jobs/operator-sdk/molecule-test/job.yaml
@@ -0,0 +1,21 @@
+- job:
+    name: operator-sdk-molecule-test
+    project-type: pipeline
+    display-name: Operator Molecule Test
+    pipeline-scm:
+      scm:
+        - git:
+            url: https://pagure.io/kube-sig/jenkins.git
+            branches:
+              - master
+            clean:
+              after: true
+      script-path: defs/jobs/operator-sdk/molecule-test/Jenkinsfile
+    parameters:
+      - string:
+          name: "GIT_URL"
+          description: "GIT repository url to pull from"
+      - string:
+          name: "GIT_REFS"
+          description: "GIT refs to use, such as branch, tag, commit, etc"
+          default: "main"
\ No newline at end of file
diff --git a/defs/views.yaml b/defs/views.yaml
index 0f40508..bd7fe33 100644
--- a/defs/views.yaml
+++ b/defs/views.yaml
@@ -10,3 +10,15 @@
       - last-success
       - last-failure
       - last-duration
+- view:
+    name: operator-sdk
+    view-type: list
+    job-name:
+      - operator-sdk-molecule-test
+    columns:
+      - status
+      - weather
+      - job
+      - last-success
+      - last-failure
+      - last-duration

