Update the Qemu-build to source in helper script

Qemu build script will now call in the kubernetes helper if launch
is set to pod or job. To satisfy this update, added new templates
to launch the container into kubernetes cluster as a job or a pod.
In addition added the default variables for the template that are not
defined in the qemu-build.sh script.

Change-Id: I92fee4c6a6c2e734f840d16af026afbbab4f3fb1
Signed-off-by: Alanny Lopez <alanny.lopez@ibm.com>
diff --git a/kubernetes/Templates/QEMU-build-job.yaml b/kubernetes/Templates/QEMU-build-job.yaml
new file mode 100644
index 0000000..d5da300
--- /dev/null
+++ b/kubernetes/Templates/QEMU-build-job.yaml
@@ -0,0 +1,42 @@
+apiVersion: batch/v1
+kind: Job
+metadata:
+  name: qemubuild${BUILD_ID}
+  namespace: ${namespace}
+  labels:
+    app: qemu
+    stage: build
+spec:
+  template:
+    metadata:
+      name: ${podname}
+    spec:
+      nodeSelector:
+        worker: \"true\"
+        arch: ${ARCH}
+      volumes:
+      - name: home
+        persistentVolumeClaim:
+          claimName: ${hclaim}
+      - name: qemudir
+        persistentVolumeClaim:
+          claimName: ${qclaim}
+      restartPolicy: Never
+      hostNetwork: True
+      containers:
+      - image: ${imgname}
+        name: builder
+        command: [\"${WORKSPACE}/build.sh\"]
+        workingDir: ${HOME}
+        env:
+        - name: WORKSPACE
+          value: ${WORKSPACE}
+        - name: qemudir
+          value: ${qemudir}
+        volumeMounts:
+        - name: home
+          mountPath: ${HOME}
+        - name: qemudir
+          mountPath: ${qemudir}
+      imagePullSecrets:
+      - name: ${imgplsec}
diff --git a/kubernetes/Templates/QEMU-build-pod.yaml b/kubernetes/Templates/QEMU-build-pod.yaml
new file mode 100644
index 0000000..70ad756
--- /dev/null
+++ b/kubernetes/Templates/QEMU-build-pod.yaml
@@ -0,0 +1,34 @@
+apiVersion: v1
+kind: Pod
+metadata:
+  name: ${podname}
+  namespace: ${namespace}
+spec:
+  nodeSelector:
+    worker: \"true\"
+    arch: ${ARCH}
+  volumes:
+  - name: home
+    persistentVolumeClaim:
+      claimName: ${hclaim}
+  - name: qemudir
+    persistentVolumeClaim:
+      claimName: ${qclaim}
+  hostNetwork: True
+  containers:
+  - image: ${imgname}
+    name: builder
+    command: [\"${WORKSPACE}/build.sh\"]
+    workingDir: ${HOME}
+    env:
+    - name: WORKSPACE
+      value: ${WORKSPACE}
+    - name: qemudir
+      value: ${qemudir}
+    volumeMounts:
+    - name: home
+      mountPath: ${HOME}
+    - name: qemudir
+      mountPath: ${qemudir}
+  imagePullSecrets:
+  - name: ${imgplsec}
diff --git a/kubernetes/kubernetes-launch.sh b/kubernetes/kubernetes-launch.sh
index c403e12..58b548b 100755
--- a/kubernetes/kubernetes-launch.sh
+++ b/kubernetes/kubernetes-launch.sh
@@ -63,6 +63,10 @@
     podname=${podname:-openbmc${BUILD_ID}-${target}-builder}
     ;;
   QEMU-build)
+    podname=${podname:-qemubuild${BUILD_ID}}
+    hclaim=${hclaim:-jenkins}
+    qclaim=${qclaim:-qemu-repo}
+    imgname="${imgrepo}${imgname}"
     ;;
   QEMU-launch)
     ;;
@@ -82,7 +86,7 @@
 # Push the image that was built to the image repository
 docker push ${imgname}
 
-yamlfile=$(eval "echo \"$(<./Templates/${invoker}-${launch}.yaml)\"" )
+yamlfile=$(eval "echo \"$(<./kubernetes/Templates/${invoker}-${launch}.yaml)\"" )
 kubectl create -f - <<< "${yamlfile}"
 
 # Once pod is running track logs
diff --git a/qemu-build.sh b/qemu-build.sh
index b5bbfec..56a7483 100755
--- a/qemu-build.sh
+++ b/qemu-build.sh
@@ -138,7 +138,7 @@
     exit 1
   fi
   mountqemu="-v ""${qemudir}"":""${qemudir}"" "
-  if [[ "${qemudir}" = "${HOME}/"* || "${qemudir}" = "${HOME}" ]];then
+  if [[ "${qemudir}" = "${HOME}/"* || "${qemudir}" = "${HOME}" ]]; then
     mountqemu=""
   fi
   docker run \
@@ -149,7 +149,8 @@
       ${mountqemu} \
       -t ${imgname} \
       ${WORKSPACE}/build.sh
-
+elif [[ "${launch}" == "pod" || "${launch}" == "job" ]]; then
+  . ./kubernetes/kubernetes-launch.sh QEMU-build true true
 else
   echo "Launch Parameter is invalid"
 fi