# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: '{{ .Values.namespace }}'
  name: '{{ .Values.project_id }}-publisher-deployment-{{ .Values.region }}'
  labels:
    app: publisher
    operator: '{{ .Values.operator }}'
spec:
  replicas: 1
  selector:
    matchLabels:
      app: publisher
  template:
    metadata:
      labels:
        app: publisher
    spec:
      serviceAccountName: '{{ .Values.k8s_service_account_name }}'
      containers:
        - env:
          - name: GOOGLE_CLOUD_PROJECT
            value: '{{ .Values.project_id }}'
          - name: EVENT_TOPIC
            valueFrom:
              configMapKeyRef:
                key: EVENT_TOPIC
                name: '{{ .Values.project_id }}-publisher-config-maps-{{ .Values.region }}'
          - name: PUBLISHER_THREADS
            valueFrom:
              configMapKeyRef:
                key: PUBLISHER_THREADS
                name: '{{ .Values.project_id }}-publisher-config-maps-{{ .Values.region }}'
          - name: PUBLISHER_FLOW_CONTROL_MAX_OUTSTANDING_MESSAGES
            valueFrom:
              configMapKeyRef:
                key: PUBLISHER_FLOW_CONTROL_MAX_OUTSTANDING_MESSAGES
                name: '{{ .Values.project_id }}-publisher-config-maps-{{ .Values.region }}'
          - name: REST_PORT
            valueFrom:
              configMapKeyRef:
                key: REST_PORT
                name: '{{ .Values.project_id }}-publisher-config-maps-{{ .Values.region }}'
          - name: GOOGLE_CLOUD_LOCATION
            value: '{{ .Values.region }}'
          - name: EVENT_GENERATOR_THREADS
            valueFrom:
              configMapKeyRef:
                key: EVENT_GENERATOR_THREADS
                name: '{{ .Values.project_id }}-publisher-config-maps-{{ .Values.region }}'
          - name: EVENT_GENERATOR_RUNTIME
            valueFrom:
              configMapKeyRef:
                key: EVENT_GENERATOR_RUNTIME
                name: '{{ .Values.project_id }}-publisher-config-maps-{{ .Values.region }}'
          - name: PUBLISHER_RETRY_INITIAL_TIMEOUT
            valueFrom:
              configMapKeyRef:
                key: PUBLISHER_RETRY_INITIAL_TIMEOUT
                name: '{{ .Values.project_id }}-publisher-config-maps-{{ .Values.region }}'
          - name: PUBLISHER_RETRY_TOTAL_TIMEOUT
            valueFrom:
              configMapKeyRef:
                key: PUBLISHER_RETRY_TOTAL_TIMEOUT
                name: '{{ .Values.project_id }}-publisher-config-maps-{{ .Values.region }}'
          - name: PUBLISHER_BATCH_SIZE
            valueFrom:
              configMapKeyRef:
                key: PUBLISHER_BATCH_SIZE
                name: '{{ .Values.project_id }}-publisher-config-maps-{{ .Values.region }}'
          name: '{{ .Values.project_id }}-publisher-{{ .Values.region }}'
          image: '{{ .Values.image }}'
          resources:
            requests:
              cpu: "1000m"
