apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: {{ template "bitcoind.fullname" . }}
  labels:
    app: {{ template "bitcoind.name" . }}
    chart: {{ template "bitcoind.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: {{ template "bitcoind.name" . }}
      release: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app: {{ template "bitcoind.name" . }}
        release: {{ .Release.Name }}
    spec:
      {{- if .Values.configurationFile }}
      initContainers:
        - name: copy-bitcoind-config
          image: busybox
          command: ['sh', '-c', 'cp /configmap/bitcoin.conf /bitcoin/.bitcoin/bitcoin.conf']
          volumeMounts:
            - name: configmap
              mountPath: /configmap
            - name: config
              mountPath: /bitcoin/.bitcoin/
      {{- end }}
      containers:
        - name: {{ template "bitcoind.fullname" . }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
          resources:
  {{ toYaml .Values.resources | indent 10 }}
          ports:
            - name: rpc
              containerPort: {{ .Values.service.rpcPort }}
            - name: p2p
              containerPort: {{ .Values.service.p2pPort }}
            - name: testnet
              containerPort: {{ .Values.service.testnetPort }}
            - name: testnetp2pport
              containerPort: {{ .Values.service.testnetP2pPort }}
          volumeMounts:
            - name: data
              mountPath: /bitcoin
            {{- if .Values.configurationFile }}
            - name: config
              mountPath: /bitcoin/.bitcoin/bitcoin.conf
              subPath: bitcoin.conf
            {{- end }}
      volumes:
        {{- if .Values.configurationFile }}
        - name: config
          emptyDir: {}
        - name: configmap
          configMap:
            name: {{ template "bitcoind.fullname" . }}
        {{- end }}
        - name: data
        {{- if .Values.persistence.enabled }}
          persistentVolumeClaim:
            claimName: {{ .Values.persistence.existingClaim | default (include "bitcoind.fullname" .) }}
        {{- else }}
          emptyDir: {}
        {{- end -}}
