apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: istio-pilot
  # TODO: default tempate doesn't have this, which one is right ?
  labels:
    app: istio-pilot
    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
    istio: pilot
  annotations:
    checksum/config-volume: {{ template "istio.configmap.checksum" . }}
spec:
  replicas: {{ .Values.replicaCount }}
  template:
    metadata:
      labels:
        istio: pilot
      annotations:
        sidecar.istio.io/inject: "false"
    spec:
      serviceAccountName: istio-pilot-service-account
      containers:
        - name: discovery
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          args:
          - "discovery"
          - "--admission-service"
          - "istio-pilot"
          ports:
          - containerPort: 8080
          - containerPort: 15010
          - containerPort: 443
          readinessProbe:
            httpGet:
              path: /v1/registration
              port: 8080
            initialDelaySeconds: 30
            periodSeconds: 30
            timeoutSeconds: 5
          env:
          - name: POD_NAME
            valueFrom:
              fieldRef:
                apiVersion: v1
                fieldPath: metadata.name
          - name: POD_NAMESPACE
            valueFrom:
              fieldRef:
                apiVersion: v1
                fieldPath: metadata.namespace
          - name: PILOT_THROTTLE
            value: "200"
          resources:
{{ toYaml .Values.resources | indent 12 }}
          volumeMounts:
          - name: config-volume
            mountPath: /etc/istio/config
        - name: istio-proxy
          image: "{{ .Values.global.proxy.image }}:{{ .Values.global.tag }}"
          imagePullPolicy: {{ .Values.global.imagePullPolicy }}
          ports:
          - containerPort: 15003
          - containerPort: 15005
          - containerPort: 15007
          args:
          - proxy
          - pilot
        {{- if .Values.global.controlPlaneSecurityEnabled }}
          - --discoveryAddress
          - istio-pilot:15005
          - --controlPlaneAuthPolicy
          - MUTUAL_TLS
        {{- else }}
          - --controlPlaneAuthPolicy
          - NONE
          - --discoveryAddress
          - localhost:8080
        {{- end }}
          - --customConfigFile
          - /etc/istio/proxy/envoy_pilot.json
          resources:
{{ toYaml .Values.global.proxy.resources | indent 12 }}
          volumeMounts:
          - name: istio-certs
            mountPath: /etc/certs
            readOnly: true
      volumes:
      - name: config-volume
        configMap:
          name: istio
      - name: istio-certs
        secret:
          secretName: "istio.istio-pilot-service-account"
          optional: true
    {{- if .Values.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
    {{- end }}
