apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: {{ template "fullname" . }}
  labels:
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
spec:
  replicas: {{ .Values.replicaCount }}
  template:
    metadata:
      labels:
        app: {{ template "fullname" . }}
    spec:
      volumes:
      - name: config
        configMap:
          name: {{ template "fullname" . }}
      containers:
      - name: {{ .Chart.Name }}
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        args:
        - "--config=/etc/chihaya/config.yaml"
        - "--debug"
        - "--json"
        ports:
        - name: bittorrent-http
          containerPort: {{ $v := .Values.config.chihaya.http.addr | split ":" }}{{ $v._1 }}
          protocol: TCP
        - name: bittorrent-udp
          containerPort: {{ $v := .Values.config.chihaya.udp.addr | split ":" }}{{ $v._1 }}
          protocol: UDP
        - name: metrics
          containerPort: {{ $v := .Values.config.chihaya.metrics_addr | split ":" }}{{ $v._1 }}
        livenessProbe:
          httpGet:
            path: /
            port: {{ $v := .Values.config.chihaya.metrics_addr | split ":" }}{{ $v._1 }}
        volumeMounts:
        - name: config
          mountPath: /etc/chihaya
        resources:
{{ toYaml .Values.resources | indent 10 }}