# helm_charts_geth-miner.deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "ethereum.fullname" . }}-geth-miner
  labels:
    app: {{ template "ethereum.name" . }}
    chart: {{ template "ethereum.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
    component: geth-miner
spec:
  replicas: {{ .Values.geth.miner.replicaCount }}
  selector:
    matchLabels:
      app: {{ template "ethereum.name" . }}
      release: {{ .Release.Name }}
      component: geth-miner
  template:
    metadata:
      labels:
        app: {{ template "ethereum.name" . }}
        release: {{ .Release.Name }}
        component: geth-miner
    spec:
      containers:
      - name: geth-miner
        image: {{ .Values.geth.image.repository }}:{{ .Values.geth.image.tag }}
        imagePullPolicy: {{ .Values.imagePullPolicy }}
        command: ["/bin/sh"]
        args:
        - "-c"
        - "geth --bootnodes=`cat /root/.ethereum/bootnodes` --mine --etherbase=0 --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: 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 }}