---
apiVersion: v1
kind: Service
metadata:
  name: {{ .NAME }}
  namespace: {{ .NAMESPACE }}
  labels:
    app: {{ .NAME }}
spec:
  type: NodePort
  selector:
    app: {{ .NAME }}
  ports:
    - port: 80
      targetPort: {{ .PORT }}
      name: {{ .NAME }}
      protocol: TCP
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .NAME }}
  namespace: {{ .NAMESPACE }}
spec:
  replicas: {{ .REPLICAS }}
  selector:
    matchLabels:
      app: {{ .NAME }}
  template:
    metadata:
      labels:
        app: {{ .NAME }}
    spec:
      restartPolicy: Always
      terminationGracePeriodSeconds: 40
      containers:
        - name: {{ .NAME }}
          image: {{ .IMAGE_NAME }}
          readinessProbe:
            initialDelaySeconds: 30
            periodSeconds: 20
            timeoutSeconds: 3
            failureThreshold: 3
            httpGet:
              path: /api/v1/ready
              port: {{ .PORT }}
          livenessProbe:
            initialDelaySeconds: 30
            periodSeconds: 30
            timeoutSeconds: 3
            failureThreshold: 3
            httpGet:
              path: /api/v1/health
              port: {{ .PORT }}
          env:
            - name: WORMSCAN_PORT
              value: "{{ .PORT }}"
            - name: WORMSCAN_LOGLEVEL
              value: {{ .WORMSCAN_LOGLEVEL }}
            - name: WORMSCAN_RUNMODE
              value: {{ .WORMSCAN_RUNMODE }}
            - name: WORMSCAN_P2PNETWORK
              value: {{ .WORMSCAN_P2PNETWORK }}
            - name: WORMSCAN_DB_URL
              valueFrom:
                secretKeyRef:
                  name: mongodb
                  key: mongo-uri
            - name: WORMSCAN_DB_NAME
              valueFrom:
                configMapKeyRef:
                  name: config
                  key: mongo-database
            - name: WORMSCAN_CACHE_URL
              valueFrom:
                configMapKeyRef:
                  name: config
                  key: redis-uri
            - name: WORMSCAN_CACHE_ENABLED
              value: "true"
            - name: WORMSCAN_CACHE_CHANNEL
              value: "WORMSCAN:NOTIONAL"
            - name: WORMSCAN_CACHE_TVLKEY
              value: "WORMSCAN:TVL"
            - name: WORMSCAN_CACHE_TVLEXPIRATION
              value: "60"
            - name: WORMSCAN_PPROF_ENABLED
              value: "{{ .WORMSCAN_PPROF_ENABLED }}"
            - name: WORMSCAN_INFLUX_URL
              valueFrom:
                configMapKeyRef:
                  name: config
                  key: influxdb-url
            - name: WORMSCAN_INFLUX_TOKEN
              valueFrom:
                secretKeyRef:
                  name: influxdb
                  key: token
            - name: WORMSCAN_INFLUX_ORGANIZATION
              valueFrom:
                configMapKeyRef:
                  name: config
                  key: influxdb-organization
            - name: WORMSCAN_INFLUX_BUCKETINFINITE
              valueFrom:
                configMapKeyRef:
                  name: config
                  key: influxdb-bucket-infinite
            - name: WORMSCAN_INFLUX_BUCKET30DAYS
              valueFrom:
                configMapKeyRef:
                  name: config
                  key: influxdb-bucket-30-days
            - name: WORMSCAN_INFLUX_BUCKET24HOURS
              valueFrom:
                configMapKeyRef:
                  name: config
                  key: influxdb-bucket-24-hours
          resources:
            limits:
              memory: {{ .RESOURCES_LIMITS_MEMORY }}
              cpu: {{ .RESOURCES_LIMITS_CPU }}
            requests:
              memory: {{ .RESOURCES_REQUESTS_MEMORY }}
              cpu: {{ .RESOURCES_REQUESTS_CPU }}
