# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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:
  labels:
    app: {{ include "adapter.fullname" . | trunc (int (sub 63 (len "-custom-metrics-apiserver"))) | printf "%s-custom-metrics-apiserver" }} 
    {{- include "adapter.labels" . | nindent 4 }}
  name: {{ include "adapter.fullname" . | trunc (int (sub 63 (len "-adapter"))) | printf "%s-adapter" }} 
  namespace: {{ .Release.Namespace }}
spec:
  replicas: {{ .Values.replicas }}
  selector:
    matchLabels:
      app: {{ include "adapter.fullname" . | trunc (int (sub 63 (len "-custom-metrics-apiserver"))) | printf "%s-custom-metrics-apiserver" }} 
      {{- include "adapter.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
        app: {{ include "adapter.fullname" . | trunc (int (sub 63 (len "-custom-metrics-apiserver"))) | printf "%s-custom-metrics-apiserver" }} 
        {{- include "adapter.selectorLabels" . | nindent 8 }}
      name: custom-metrics-apiserver
    spec:
      containers:
      - args:
        - --secure-port={{ .Values.service.port }}
        - --logtostderr=true
        - --v=10
        - --oap-addr=http://{{ .Values.oap.service.name }}.{{ .Values.oap.service.namespace }}:{{ .Values.oap.service.port }}/graphql
        - --cert-dir=/tmp
        command:
        - /adapter
        image: {{ .Values.image.repository }}:{{ required ".adapter.image.tag is required" .Values.image.tag }}
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        name: adapter
        resources:
          {{- toYaml .Values.resources | nindent 12 }}
        ports:
        - containerPort: {{ .Values.service.port }}
          name: https
        volumeMounts:
        - mountPath: /tmp
          name: temp-vol
      serviceAccountName: {{ .Values.serviceAccountName }}
      volumes:
      - emptyDir: {}
        name: temp-vol
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
