apiVersion: apps/v1beta2 
kind: Deployment
metadata:
  name: {{ template "ethereum.fullname" . }}-geth-tx
  labels:
    app: {{ template "ethereum.name" . }}
    chart: {{ template "ethereum.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
    component: geth-tx
spec:
  replicas: {{ .Values.geth.tx.replicaCount }}
  selector:
    matchLabels:
      app: {{ template "ethereum.name" . }}
      release: {{ .Release.Name }}
      component: geth-tx
  template:
    metadata:
      labels:
        app: {{ template "ethereum.name" . }}
        release: {{ .Release.Name }}
        component: geth-tx
    spec:
      containers:
      - name: geth-tx
        image: {{ .Values.geth.image.repository }}:{{ .Values.geth.image.tag }}
        imagePullPolicy: {{ .Values.imagePullPolicy }}
        command: ["/bin/sh"]
        args: 
        - "-c"
        - "geth --bootnodes=`cat /root/.ethereum/bootnodes` --rpc --rpcaddr 0.0.0.0 --rpcapi=eth,net,web3 --rpccorsdomain='*' --ws --networkid=${NETWORK_ID} --ethstats=${HOSTNAME}:${ETHSTATS_SECRET}@${ETHSTATS_SVC} --verbosity=5"
        env:
        - name: ETHSTATS_SVC
          value: {{ template "ethereum.fullname" . }}-ethstats.{{ .Release.Namespace }}
        - name: ETHSTATS_SECRET
          valueFrom:
            secretKeyRef:
              name: {{ template "ethereum.fullname" . }}-ethstats
              key: WS_SECRET
        - name: NETWORK_ID
          valueFrom:
            configMapKeyRef:
              name: {{ template "ethereum.fullname" . }}-geth-config
              key: networkid
        ports:
        - name: rpc
          containerPort: 8545
        - name: ws
          containerPort: 8546
        - name: discovery-udp
          containerPort: 30303
          protocol: UDP
        - name: discovery-tcp
          containerPort: 30303
        volumeMounts:
        - name: data
          mountPath: /root/.ethereum
      initContainers:
      - name: init-genesis
        image: {{ .Values.geth.image.repository }}:{{ .Values.geth.image.tag }}
        imagePullPolicy: {{ .Values.imagePullPolicy }}
        args:
        - "init"
        - "/var/geth/genesis.json"
        volumeMounts:
        - name: data
          mountPath: /root/.ethereum
        - name: config
          mountPath: /var/geth
      - name: import-geth-account
        image: {{ .Values.geth.image.repository }}:{{ .Values.geth.image.tag }}
        imagePullPolicy: {{ .Values.imagePullPolicy }}
        command: ["/bin/sh"]
        args:
        - "-c"
        - "geth account import --password /root/.ethereum/account/accountSecret /root/.ethereum/account/accountPrivateKey"
        volumeMounts:
        - name: data
          mountPath: /root/.ethereum
        - name: account
          readOnly: true
          mountPath: /root/.ethereum/account
      - name: get-bootnodes
        image: {{ .Values.geth.image.repository }}:{{ .Values.geth.image.tag }}
        imagePullPolicy: {{ .Values.imagePullPolicy }}
        command: ["/bin/sh"]
        args:
        - "-c"
        - |-
{{ .Files.Get "scripts/get-bootnode.sh" | indent 10 }}
        env:
        - name: BOOTNODE_SVC
          value: {{ template "ethereum.fullname" . }}-bootnode.{{ .Release.Namespace }}
        volumeMounts:
        - name: data
          mountPath: /geth
      volumes:
      - name: data
        emptyDir: {}
      - name: config 
        configMap:
          name: {{ template "ethereum.fullname" . }}-geth-config
      - name: account
        secret:
          secretName: {{ template "ethereum.fullname" . }}-geth-account
    {{- with .Values.nodeSelector }}
      nodeSelector:
{{ toYaml . | indent 8 }}
    {{- end }}