kind: Deployment
apiVersion: apps/v1
metadata:
  name: "{{name}}-keycloak"
  namespace: '{{ meta.namespace }}'
  labels:
    app: "{{name}}"
    container: keycloak
    group: microcks
spec:
  strategy:
    type: Recreate
  replicas: 1
  selector: 
    matchLabels:  
      app: "{{name}}"
      deploymentconfig: keycloak
      container: keycloak
      group: microcks
  template:
    metadata:
      labels:
        app: "{{name}}"
        deploymentconfig: keycloak
        container: keycloak
        group: microcks
    spec:
      containers:
      - name: keycloak-server
        image: jboss/keycloak-openshift:3.4.0.Final
        ports:
        - name: http
          containerPort: 8080
          protocol: TCP
        - name: jolokia
          containerPort: 8778
          protocol: TCP
        args:
        - start-keycloak.sh
        - "-b $(INTERNAL_POD_IP)"
        - "-Djgroups.bind_addr=global"
        - "-Djboss.node.name=$(INTERNAL_POD_IP)"
        - "-Dkeycloak.import=/opt/jboss/keycloak/standalone/configuration/realm/microcks-realm.json"
        env:
        - name: INTERNAL_POD_IP
          valueFrom:
            fieldRef:
              fieldPath: status.podIP
        - name: KEYCLOAK_USER
          valueFrom:
            secretKeyRef:
              key: username
              name: "{{name}}-keycloak-admin"
        - name: KEYCLOAK_PASSWORD
          valueFrom:
            secretKeyRef:
              key: password
              name: "{{name}}-keycloak-admin"
        - name: OPERATING_MODE
          value: clustered
        - name: DB_VENDOR
          value: POSTGRES
        - name: POSTGRES_USER
          valueFrom:
            secretKeyRef:
              key: postgresUsername
              name: "{{name}}-keycloak-admin"
        - name: POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              key: postgresPassword
              name: "{{name}}-keycloak-admin"
        - name: POSTGRES_DATABASE
          value: root
        - name: POSTGRES_PORT_5432_TCP_ADDR
          value: "{{name}}-keycloak-postgresql"
        - name: OPENSHIFT_KUBE_PING_LABELS
          value: deploymentconfig=keycloak
        - name: OPENSHIFT_KUBE_PING_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: PROXY_ADDRESS_FORWARDING
          value: "true"
        volumeMounts:
        - name: "{{name}}-keycloak-config"
          mountPath: "/opt/jboss/keycloak/standalone/configuration/realm"
        securityContext:
          privileged: false
      volumes:
      - name: "{{name}}-keycloak-config"
        configMap:
          name: "{{name}}-keycloak-config"
      restartPolicy: Always
      dnsPolicy: ClusterFirst