apiVersion: v1
kind: Service
metadata:
  name: <<appenv>>builder-be
  namespace: <<appenv>>builder-be
  labels:
    app: <<appenv>>builder-be
    service: <<appenv>>builder-be
spec:
  ports:
    - port: 80
      name: http-<<appenv>>builder-be
  selector:
    app: <<appenv>>builder-be
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: <<appenv>>builder-be-sync-role
  namespace: <<appenv>>builder-be
rules:
  - apiGroups: ['batch']
    resources: ['jobs']
    verbs: ['get', 'list', 'watch', 'create', 'update', 'patch', 'delete']
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: <<appenv>>builder-be-sync-role-bd
  namespace: <<appenv>>builder-be
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: <<appenv>>builder-be-sync-role
subjects:
  - kind: ServiceAccount
    name: default
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: <<appenv>>builder-be
  namespace: <<appenv>>builder-be
spec:
  replicas: 1
  revisionHistoryLimit: 3
  selector:
    matchLabels:
      app: <<appenv>>builder-be
      version: v1
  template:
    metadata:
      name: <<appenv>>builder-be
      labels:
        app: <<appenv>>builder-be
        version: v1
    spec:
      containers:
        - name: builder-be
          image: docker.adaoncloud.com/ada/<<appenv>>builder-be:<<imagetag>>
          env:
            - name: ADA_APP_ENV
              value: <<appenv>>
            - name: START_RENDER_JOBS
              value: '0'
            - name: ADA_RENDER_ENGINE_IMAGE
              value: 'docker.adaoncloud.com/ada/<<appenv>>render-engine:<<imagetag>>'
            - name: ADA_POD_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: ADA_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: ADA_SERVICE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: TDB_OAUTH_URL
              value: http://sta-tdb-oauth.sta-tdb-oauth.svc.cluster.local:8080
            - name: TDB_OAUTH_DISABLE
              value: '0'
            - name: REDIS_SENTINEL_HOST
              value: ada-redis.sta-ada-redis.svc.cluster.local
            - name: REDIS_SENTINEL_PORT
              value: '26379'
            - name: REDIS_SENTINEL_NAME
              value: sta-ada-master
            - name: REDIS_SENTINEL_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: ada-redis
                  key: redis-password
                  optional: false
            - name: REDIS_SENTINEL_DB
              value: '1'
            - name: MONGO_DB_URL
              value: mongodb://node1-2f76db0a4964324f.database.cloud.ovh.net
            - name: MONGO_DB_NAME
              value: sta_ada-builder-be
            - name: MONGO_DB_USER
              valueFrom:
                secretKeyRef:
                  name: mongo-sta-ada-builder-be
                  key: username
                  optional: false
            - name: MONGO_DB_PASS
              valueFrom:
                secretKeyRef:
                  name: mongo-sta-ada-builder-be
                  key: password
                  optional: false
            - name: ELASTIC_HOST
              value: 'https://ada-elastic-es-http.sta-ada-elastic.svc.cluster.local:9200'
            - name: ELASTIC_REJECTUNAUTHORIZED
              value: 'true'
            - name: ELASTIC_USERNAME
              valueFrom:
                secretKeyRef:
                  name: tdb-logs-es-user-rw
                  key: username
                  optional: false
            - name: ELASTIC_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: tdb-logs-es-user-rw
                  key: password
                  optional: false
            - name: KAFKA_SERVER
              value: 'ada-cluster-kafka-bootstrap.sta-ada-kafka-cluster.svc.cluster.local:9093'
            - name: KAFKA_USERNAME
              valueFrom:
                secretKeyRef:
                  name: kafka-render-engine-user
                  key: username
                  optional: false
            - name: KAFKA_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: kafka-render-engine-user
                  key: password
                  optional: false
            - name: KAFKA_CLIENTID
              valueFrom:
                secretKeyRef:
                  name: kafka-render-engine-user
                  key: clientid
                  optional: false
            - name: KAFKA_TOPIC
              valueFrom:
                secretKeyRef:
                  name: kafka-render-engine-user
                  key: topic
                  optional: false
            - name: KAFKA_GROUPID
              valueFrom:
                secretKeyRef:
                  name: kafka-render-engine-user
                  key: groupid
                  optional: false
            - name: FSTLOGLEVEL
              value: info
            - name: NODE_ENV
              value: sta
          ports:
            - containerPort: 80
          imagePullPolicy: Always
      restartPolicy: Always
      imagePullSecrets:
        - name: ada-registry
