apiVersion: extensions/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.global.hub }}/pilot:{{ .Values.global.tag }}"
          imagePullPolicy: {{ .Values.imagePullPolicy }}
          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: "500"
          - name: PILOT_CACHE_SQUASH
            value: "5"
          resources:
{{ toYaml .Values.resources | indent 12 }}
          volumeMounts:
          - name: config-volume
            mountPath: /etc/istio/config
        - name: istio-proxy
          image: "{{ .Values.global.hub }}/{{ .Values.global.proxy.image }}:{{ .Values.global.tag }}"
          imagePullPolicy: {{ .Values.global.proxy.imagePullPolicy }}
          ports:
          - containerPort: 15003
          - containerPort: 15005
          - containerPort: 15007
          args:
          - proxy
          - pilot
          - --discoveryAddress
          - localhost:8080
          - --controlPlaneAuthPolicy
          - NONE #--controlPlaneAuthPolicy
          - --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 }}
