# this openshift template should match (except nodeSelector) jinja2 template in
# ../templates/eventrouter-template.j2
kind: Template
apiVersion: v1
metadata:
  name: eventrouter-template
  annotations:
    description: "A pod forwarding kubernetes events to EFK aggregated logging stack."
    tags: "events,EFK,logging"
objects:
  - kind: ServiceAccount
    apiVersion: v1
    metadata:
      name: aggregated-logging-eventrouter
  - kind: ClusterRole
    apiVersion: v1
    metadata:
      name: event-reader
    rules:
    - apiGroups: [""]
      resources: ["events"]
      verbs: ["get", "watch", "list"]
  - kind: ConfigMap
    apiVersion: v1
    metadata:
      name: logging-eventrouter
    data:
      config.json: |- 
        {
          "sink": "${SINK}"
        }
  - kind: DeploymentConfig
    apiVersion: v1
    metadata:
      name: logging-eventrouter
      labels:
        component: eventrouter
        logging-infra: eventrouter
        provider: openshift
    spec:
      selector:
        component: eventrouter
        logging-infra: eventrouter
        provider: openshift
      replicas: ${REPLICAS}
      template:
        metadata:
          labels:
            component: eventrouter
            logging-infra: eventrouter
            provider: openshift
          name: logging-eventrouter
        spec:
          serviceAccount: aggregated-logging-eventrouter
          serviceAccountName: aggregated-logging-eventrouter
          containers:
            - name: kube-eventrouter
              image: ${IMAGE}
              imagePullPolicy: IfNotPresent
              resources:
                limits:
                  memory: ${MEMORY} 
                  cpu: ${CPU}
                requires:
                  memory: ${MEMORY}
              volumeMounts:
              - name: config-volume
                mountPath: /etc/eventrouter
          volumes:
            - name: config-volume
              configMap:
                name: logging-eventrouter
  - kind: ClusterRoleBinding
    apiVersion: v1
    metadata:
      name: event-reader-binding
    subjects:
    - kind: ServiceAccount
      name: aggregated-logging-eventrouter
      namespace: ${NAMESPACE}
    roleRef:
      kind: ClusterRole
      name: event-reader

parameters:
  - name: SINK
    displayName: Sink
    value: stdout
  - name: REPLICAS
    displayName: Replicas
    value: "1"
  - name: IMAGE
    displayName: Image
    value: "docker.io/openshift/origin-logging-eventrouter:latest"
  - name: MEMORY
    displayName: Memory
    value: "128Mi"
  - name: CPU
    displayName: CPU
    value: "100m"
  - name: NAMESPACE
    displayName: Namespace
    value: default
