apiVersion: v1
kind: ConfigMap
metadata:
  name: qs-app-deployment-template
data:
  app-deployment-template.yaml: |
    apiVersion: template.openshift.io/v1
    kind: Template
    metadata:
      annotations:
        template.openshift.io/bindable: "false"
      name: create-deployment
    objects:
    apiVersion: template.openshift.io/v1
    kind: Template
    metadata:
      annotations:
        template.openshift.io/bindable: "false"
      name: create-service
    objects:
      - apiVersion: v1
        kind: Service
        metadata:
          annotations:
            description: ${APP_NAME} Port 8080 Service.
          labels:
            app: "${APP_NAME}"
          name: ${APP_NAME}
        spec:
          ports:
          - name: 8080-tcp
            port: 8080
            protocol: TCP
            targetPort: 8080
          selector:
            app: "${APP_NAME}"
      - apiVersion: route.openshift.io/v1
        kind: Route
        metadata:
          labels:
            app: "${APP_NAME}"
          name: "${APP_NAME}"
        spec:
          port:
            targetPort: 8080-tcp
          to:
            kind: Service
            name: quarkus-api-with-cache-on-openshift

      - apiVersion: apps/v1
        kind: Deployment
        metadata:
          annotations:
            description: ${APP_NAME} Deployment.
          labels:
            app: "${APP_NAME}"
          name: ${APP_NAME}
        spec:
          replicas: 0
          selector:
            matchLabels:
              app: "${APP_NAME}"
          strategy:
            type: RollingUpdate
            RollingUpdate:
              maxSurge: 33%
              maxUnavailable: 33%
          template:
            metadata:
              labels:
                app: "${APP_NAME}"
                app: "${APP_NAME}"
              name: ${APP_NAME}
            spec:
              initContainers:
              - args:
                  - '-c'
                  - >-
                    cd /tmp && csplit -z -f crt- $ca_bundle '/-----BEGIN CERTIFICATE-----/' '{*}'
                    && for file in crt-*; do keytool -import -noprompt -keystore
                    $truststore_jks -file $file -storepass $password -alias
                    service-$file; done
                command:
                  - /bin/bash
                env:
                  - name: ca_bundle
                    value: /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt
                  - name: truststore_jks
                    value: /var/run/secrets/java.io/keystores/truststore.jks
                  - name: password
                    value: changeit
                image: 'image-registry.openshift-image-registry.svc:5000/openshift/delta-jdk-11-app-runner:latest'
                imagePullPolicy: IfNotPresent
                name: pem-to-truststore
                resources: {}
                terminationMessagePath: /dev/termination-log
                terminationMessagePolicy: File
                volumeMounts:
                  - mountPath: /var/run/secrets/java.io/keystores
                    name: keystore-volume
              containers: 
              - env:
                - name: JAVA_OPTIONS
                  value: '-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager -Djavax.net.ssl.trustStore=/var/run/secrets/java.io/keystores/truststore.jks -Djavax.net.ssl.trustStorePassword=changeit'
                image: ${APP_NAME}
                imagePullPolicy: Always
                name: ${APP_NAME}
                ports:
                - containerPort: 8778
                  name: jolokia
                  protocol: TCP
                - containerPort: 8080
                  name: http
                  protocol: TCP
                - containerPort: 8443
                  name: https
                  protocol: TCP
                volumeMounts:
                - mountPath: /var/run/secrets/java.io/keystores
                  name: keystore-volume
                readinessProbe:
                  tcpSocket:
                    port: 8080
                  initialDelaySeconds: 1
                  periodSeconds: 10
                  successThreshold: 1
                  failureThreshold: 3
                livenessProbe:
                  tcpSocket:
                    port: 8080
                  initialDelaySeconds: 1
                  periodSeconds: 10
                  successThreshold: 1
                  failureThreshold: 3
              terminationGracePeriodSeconds: 5
              volumes:
              - emptyDir: {}
                name: keystore-volume

    parameters:
      -
        name: APP_NAME
        required: true
