apiVersion: template.openshift.io/v1
kind: Template
metadata:
  name: hawtio
parameters:
- name: APPLICATION_NAME
  displayName: Application Name
  required: true
  value: hawtio
- name: VERSION
  displayName: Application Version
  required: true
  value: latest
  description: The name assigned to the Hawtio resources
- name: DEPLOYMENT_TYPE
  displayName: Deployment Type
  required: true
  value: namespace
  description: The deployment type, either "cluster" or "namespace"
- name: OAUTH_CLIENT
  displayName: OAuth Client Name
  required: true
  description: The OAuth client name
- name: REPLICAS
  required: true
  value: "1"
  description: The number of desired replicas
- name: ROUTE_HOSTNAME
  description: The externally-reachable host name that routes to the Hawtio service
objects:
- apiVersion: v1
  kind: ConfigMap
  metadata:
    name: ${APPLICATION_NAME}
  data:
    hawtconfig.json: |
      {
        "about": {
          "title": "Red Hat Fuse Console",
          "productInfo": [],
          "additionalInfo": "The Red Hat Fuse Console eases the discovery and management of Fuse applications deployed on OpenShift.",
          "copyright": "",
          "imgSrc": "../online/img/Logo-RedHat-A-Reverse-RGB.png"
        },
        "branding": {
          "appName": "Fuse Console",
          "appLogoUrl": "../online/img/Logo-Red_Hat-Fuse-A-Reverse-RGB.png"
        },
        "disabledRoutes": []
      }
- apiVersion: v1
  kind: ImageStream
  metadata:
    name: ${APPLICATION_NAME}
    labels:
      app: hawtio
  spec:
    tags:
    - from:
        kind: DockerImage
        name: fuse7/fuse-console-operator:${VERSION}
      importPolicy:
        scheduled: true
      name: ${VERSION}
- apiVersion: v1
  kind: DeploymentConfig
  metadata:
    labels:
      app: hawtio
    name: ${APPLICATION_NAME}
  spec:
    replicas: ${{REPLICAS}}
    selector:
      app: hawtio
      deploymentconfig: ${APPLICATION_NAME}
    strategy:
      rollingParams:
        intervalSeconds: 1
        maxSurge: 25%
        maxUnavailable: 25%
        timeoutSeconds: 600
        updatePeriodSeconds: 1
      type: Rolling
    template:
      metadata:
        labels:
          app: hawtio
          deploymentconfig: ${APPLICATION_NAME}
      spec:
        containers:
        - image: 'hawtio/online'
          imagePullPolicy: Always
          name: hawtio-online
          ports:
          - name: nginx
            containerPort: 8443
          livenessProbe:
            httpGet:
              path: /online
              port: nginx
              scheme: HTTPS
            periodSeconds: 10
            timeoutSeconds: 1
          readinessProbe:
            httpGet:
              path: /online
              port: nginx
              scheme: HTTPS
            initialDelaySeconds: 5
            periodSeconds: 5
            timeoutSeconds: 1
          env:
          - name: HAWTIO_ONLINE_MODE
            value: ${DEPLOYMENT_TYPE}
          - name: HAWTIO_ONLINE_NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
          - name: HAWTIO_OAUTH_CLIENT_ID
            value: ${OAUTH_CLIENT}
          resources:
            requests:
              cpu: 0.2
              memory: 32Mi
            limits:
              cpu: 1.0
              memory: 32Mi
          volumeMounts:
          - name: hawtio-online
            mountPath: /usr/share/nginx/html/online/hawtconfig.json
            subPath: hawtconfig.json
          - name: hawtio-integration
            mountPath: /usr/share/nginx/html/integration/hawtconfig.json
            subPath: hawtconfig.json
          - mountPath: /etc/tls/private
            name: hawtio-online-tls
        volumes:
        - name: hawtio-online
          configMap:
            name: ${APPLICATION_NAME}
        - name: hawtio-integration
          configMap:
            name: ${APPLICATION_NAME}
        - name: hawtio-online-tls
          secret:
            secretName: ${APPLICATION_NAME}-tls
    triggers:
    - imageChangeParams:
        automatic: true
        containerNames:
        - hawtio-online
        from:
          kind: ImageStreamTag
          name: ${APPLICATION_NAME}:${VERSION}
      type: ImageChange
    - type: ConfigChange
- apiVersion: v1
  kind: Service
  metadata:
    labels:
      app: hawtio
    annotations:
      service.alpha.openshift.io/serving-cert-secret-name: ${APPLICATION_NAME}-tls
    name: ${APPLICATION_NAME}
  spec:
    ports:
    - port: 443
      protocol: TCP
      targetPort: nginx
    selector:
      app: hawtio
- apiVersion: v1
  kind: Route
  metadata:
    labels:
      app: hawtio
    name: ${APPLICATION_NAME}
  spec:
    host: ${ROUTE_HOSTNAME}
    to:
      kind: Service
      name: ${APPLICATION_NAME}
    tls:
      insecureEdgeTerminationPolicy: Redirect
      termination: reencrypt%              
