From e0874c613f96f9c81fc9f631f97a48bae837fa26 Mon Sep 17 00:00:00 2001
From: Michal Kovarik <mkovarik@redhat.com>
Date: Apr 01 2020 07:43:45 +0000
Subject: Install jenkins without volume for verification


Avoid issue with storage quota and do not request persistent storage for
jenkins master used for c3i role verification.
Get template directly from openshift and set cpu limit to 2.

---

diff --git a/setup/install-jenkins b/setup/install-jenkins
index 3976461..3488b00 100755
--- a/setup/install-jenkins
+++ b/setup/install-jenkins
@@ -3,9 +3,20 @@
 
 while [[ "$#" -gt 0 ]]; do case $1 in
   --jcasc) JCASC="$2"; shift;;
+  --ephemeral) EPHEMERAL=1;;
   *) echo "Unknown parameter passed: $1"; exit 1;;
 esac; shift; done
 
+if [ "$EPHEMERAL" == "1" ]; then
+  TEMPLATE=jenkins-ephemeral
+else
+  TEMPLATE=jenkins-persistent
+  CUSTOM_PARAMS="-p VOLUME_CAPACITY=2Gi"
+fi
+
+# get template and set cpu to 2
+oc get templates --export -n openshift $TEMPLATE -o json | jq '.objects[.objects | map(.kind == "DeploymentConfig") | index(true)].spec.template.spec.containers[0].resources.limits += {"cpu": 2}' > jenkins-template.yml
+
 oc import-image jenkins:2 --confirm --scheduled=true \
   --from=registry.access.redhat.com/openshift3/jenkins-2-rhel7:v3.11
 
@@ -15,9 +26,9 @@ PLUGINS=$(echo -e "$PLUGINS\n$(cat jenkins-plugins.txt)" | sort -u | tr '\n' ','
 
 oc create configmap openshift-jenkins-login-plugin-config --from-literal Overall-Administer=view
 
-oc new-app --file=jenkins-template.yaml \
+oc new-app --file=jenkins-template.yml \
         -p MEMORY_LIMIT=2Gi \
-        -p VOLUME_CAPACITY=2Gi \
+        ${CUSTOM_PARAMS} \
         -p NAMESPACE=$(oc project -q) \
         -e INSTALL_PLUGINS=$PLUGINS \
         -e JENKINS_JAVA_OVERRIDES="-Dpermissive-script-security.enabled=no_security" \
diff --git a/setup/jenkins-template.yaml b/setup/jenkins-template.yaml
deleted file mode 100644
index 8745711..0000000
--- a/setup/jenkins-template.yaml
+++ /dev/null
@@ -1,219 +0,0 @@
-apiVersion: template.openshift.io/v1
-kind: Template
-labels:
-  app: jenkins-persistent
-  template: jenkins-persistent-template
-message: A Jenkins service has been created in your project.  Log into Jenkins with
-  your OpenShift account.  The tutorial at https://github.com/openshift/origin/blob/master/examples/jenkins/README.md
-  contains more information about using this template.
-metadata:
-  annotations:
-    description: |-
-      Jenkins service, with persistent storage.
-
-      NOTE: You must have persistent volumes available in your cluster to use this template.
-    iconClass: icon-jenkins
-    openshift.io/display-name: Jenkins
-    openshift.io/documentation-url: https://docs.openshift.org/latest/using_images/other_images/jenkins.html
-    openshift.io/long-description: This template deploys a Jenkins server capable
-      of managing OpenShift Pipeline builds and supporting OpenShift-based oauth login.
-    openshift.io/provider-display-name: Red Hat, Inc.
-    openshift.io/support-url: https://access.redhat.com
-    tags: instant-app,jenkins
-  name: jenkins-persistent
-objects:
-- apiVersion: v1
-  kind: Route
-  metadata:
-    annotations:
-      haproxy.router.openshift.io/timeout: 4m
-      template.openshift.io/expose-uri: http://{.spec.host}{.spec.path}
-    name: ${JENKINS_SERVICE_NAME}
-  spec:
-    tls:
-      insecureEdgeTerminationPolicy: Redirect
-      termination: edge
-    to:
-      kind: Service
-      name: ${JENKINS_SERVICE_NAME}
-- apiVersion: v1
-  kind: PersistentVolumeClaim
-  metadata:
-    name: ${JENKINS_SERVICE_NAME}
-  spec:
-    accessModes:
-    - ReadWriteOnce
-    resources:
-      requests:
-        storage: ${VOLUME_CAPACITY}
-- apiVersion: v1
-  kind: DeploymentConfig
-  metadata:
-    annotations:
-      template.alpha.openshift.io/wait-for-ready: "true"
-    name: ${JENKINS_SERVICE_NAME}
-  spec:
-    replicas: 1
-    selector:
-      name: ${JENKINS_SERVICE_NAME}
-    strategy:
-      type: Recreate
-    template:
-      metadata:
-        labels:
-          name: ${JENKINS_SERVICE_NAME}
-      spec:
-        containers:
-        - capabilities: {}
-          env:
-          - name: OPENSHIFT_ENABLE_OAUTH
-            value: ${ENABLE_OAUTH}
-          - name: OPENSHIFT_ENABLE_REDIRECT_PROMPT
-            value: "true"
-          - name: DISABLE_ADMINISTRATIVE_MONITORS
-            value: ${DISABLE_ADMINISTRATIVE_MONITORS}
-          - name: KUBERNETES_MASTER
-            value: https://kubernetes.default:443
-          - name: KUBERNETES_TRUST_CERTIFICATES
-            value: "true"
-          - name: JENKINS_SERVICE_NAME
-            value: ${JENKINS_SERVICE_NAME}
-          - name: JNLP_SERVICE_NAME
-            value: ${JNLP_SERVICE_NAME}
-          - name: ENABLE_FATAL_ERROR_LOG_FILE
-            value: ${ENABLE_FATAL_ERROR_LOG_FILE}
-          image: ' '
-          imagePullPolicy: IfNotPresent
-          livenessProbe:
-            failureThreshold: 2
-            httpGet:
-              path: /login
-              port: 8080
-            initialDelaySeconds: 420
-            periodSeconds: 360
-            timeoutSeconds: 240
-          name: jenkins
-          readinessProbe:
-            httpGet:
-              path: /login
-              port: 8080
-            initialDelaySeconds: 3
-            timeoutSeconds: 240
-          resources:
-            limits:
-              memory: ${MEMORY_LIMIT}
-              cpu: 2
-          volumeMounts:
-          - mountPath: /var/lib/jenkins
-            name: ${JENKINS_SERVICE_NAME}-data
-        dnsPolicy: ClusterFirst
-        restartPolicy: Always
-        serviceAccountName: ${JENKINS_SERVICE_NAME}
-        volumes:
-        - name: ${JENKINS_SERVICE_NAME}-data
-          persistentVolumeClaim:
-            claimName: ${JENKINS_SERVICE_NAME}
-    triggers:
-    - imageChangeParams:
-        automatic: true
-        containerNames:
-        - jenkins
-        from:
-          kind: ImageStreamTag
-          name: ${JENKINS_IMAGE_STREAM_TAG}
-          namespace: ${NAMESPACE}
-        lastTriggeredImage: ""
-      type: ImageChange
-    - type: ConfigChange
-- apiVersion: v1
-  kind: ServiceAccount
-  metadata:
-    annotations:
-      serviceaccounts.openshift.io/oauth-redirectreference.jenkins: '{"kind":"OAuthRedirectReference","apiVersion":"v1","reference":{"kind":"Route","name":"${JENKINS_SERVICE_NAME}"}}'
-    name: ${JENKINS_SERVICE_NAME}
-- apiVersion: v1
-  groupNames: null
-  kind: RoleBinding
-  metadata:
-    name: ${JENKINS_SERVICE_NAME}_edit
-  roleRef:
-    name: edit
-  subjects:
-  - kind: ServiceAccount
-    name: ${JENKINS_SERVICE_NAME}
-- apiVersion: v1
-  kind: Service
-  metadata:
-    name: ${JNLP_SERVICE_NAME}
-  spec:
-    ports:
-    - name: agent
-      nodePort: 0
-      port: 50000
-      protocol: TCP
-      targetPort: 50000
-    selector:
-      name: ${JENKINS_SERVICE_NAME}
-    sessionAffinity: None
-    type: ClusterIP
-- apiVersion: v1
-  kind: Service
-  metadata:
-    annotations:
-      service.alpha.openshift.io/dependencies: '[{"name": "${JNLP_SERVICE_NAME}",
-        "namespace": "", "kind": "Service"}]'
-      service.openshift.io/infrastructure: "true"
-    name: ${JENKINS_SERVICE_NAME}
-  spec:
-    ports:
-    - name: web
-      nodePort: 0
-      port: 80
-      protocol: TCP
-      targetPort: 8080
-    selector:
-      name: ${JENKINS_SERVICE_NAME}
-    sessionAffinity: None
-    type: ClusterIP
-parameters:
-- description: The name of the OpenShift Service exposed for the Jenkins container.
-  displayName: Jenkins Service Name
-  name: JENKINS_SERVICE_NAME
-  value: jenkins
-- description: The name of the service used for master/slave communication.
-  displayName: Jenkins JNLP Service Name
-  name: JNLP_SERVICE_NAME
-  value: jenkins-jnlp
-- description: Whether to enable OAuth OpenShift integration. If false, the static
-    account 'admin' will be initialized with the password 'password'.
-  displayName: Enable OAuth in Jenkins
-  name: ENABLE_OAUTH
-  value: "true"
-- description: Maximum amount of memory the container can use.
-  displayName: Memory Limit
-  name: MEMORY_LIMIT
-  value: 512Mi
-- description: Volume space available for data, e.g. 512Mi, 2Gi.
-  displayName: Volume Capacity
-  name: VOLUME_CAPACITY
-  required: true
-  value: 1Gi
-- description: The OpenShift Namespace where the Jenkins ImageStream resides.
-  displayName: Jenkins ImageStream Namespace
-  name: NAMESPACE
-  value: openshift
-- description: Whether to perform memory intensive, possibly slow, synchronization
-    with the Jenkins Update Center on start.  If true, the Jenkins core update monitor
-    and site warnings monitor are disabled.
-  displayName: Disable memory intensive administrative monitors
-  name: DISABLE_ADMINISTRATIVE_MONITORS
-  value: "false"
-- description: Name of the ImageStreamTag to be used for the Jenkins image.
-  displayName: Jenkins ImageStreamTag
-  name: JENKINS_IMAGE_STREAM_TAG
-  value: jenkins:2
-- description: When a fatal error occurs, an error log is created with information
-    and the state obtained at the time of the fatal error.
-  displayName: Fatal Error Log File
-  name: ENABLE_FATAL_ERROR_LOG_FILE
-  value: "false"
diff --git a/verification/c3i-role-verification.Jenkinsfile b/verification/c3i-role-verification.Jenkinsfile
index cf89019..59c52bf 100644
--- a/verification/c3i-role-verification.Jenkinsfile
+++ b/verification/c3i-role-verification.Jenkinsfile
@@ -152,7 +152,7 @@ pipeline {
         script {
           sh "oc project ${env.PIPELINE_ID}"
           dir('setup') {
-             sh "./install-jenkins --jcasc ${env.PAGURE_REQUEST_REPO.replace('/forks/', '/fork/')}/raw/${env.PAGURE_REQUEST_BRANCH}/f/setup/jcasc.yml"
+             sh "./install-jenkins --ephemeral --jcasc ${env.PAGURE_REQUEST_REPO.replace('/forks/', '/fork/')}/raw/${env.PAGURE_REQUEST_BRANCH}/f/setup/jcasc.yml"
           }
           openshift.withCluster() {
             openshift.withProject(env.PIPELINE_ID) {

