apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "cacti.fullname" . }}-api
  namespace: {{ .Values.global.namespace }}
  labels:
    {{- include "cacti.labels" . | nindent 4 }}
    component: api
spec:
  replicas: {{ .Values.cactus.api.replicaCount }}
  selector:
    matchLabels:
      {{- include "cacti.selectorLabels" . | nindent 6 }}
      component: api
  template:
    metadata:
      labels:
        {{- include "cacti.selectorLabels" . | nindent 8 }}
        component: api
    spec:
      containers:
      - name: cactus-api
        image: "{{ .Values.cactus.api.image.repository }}:{{ .Values.cactus.api.image.tag }}"
        imagePullPolicy: {{ .Values.cactus.api.image.pullPolicy }}
        env:
        - name: CACTUS_NODE_ID
          value: cactus-node-1
        - name: CACTUS_LOG_LEVEL
          value: info
        - name: HTTP_PORT
          value: "{{ .Values.cactus.api.ports.http }}"
        - name: WS_PORT
          value: "{{ .Values.cactus.api.ports.ws }}"
        ports:
        - containerPort: {{ .Values.cactus.api.ports.http }}
          name: http
        - containerPort: {{ .Values.cactus.api.ports.ws }}
          name: ws
        resources:
          {{- toYaml .Values.cactus.api.resources | nindent 10 }}
        livenessProbe:
          httpGet:
            path: /api/v1/api-server/healthcheck
            port: http
          initialDelaySeconds: 60
          periodSeconds: 30
        readinessProbe:
          httpGet:
            path: /api/v1/api-server/healthcheck
            port: http
          initialDelaySeconds: 30
          periodSeconds: 10
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "cacti.fullname" . }}-besu-connector
  namespace: {{ .Values.global.namespace }}
  labels:
    {{- include "cacti.labels" . | nindent 4 }}
    component: besu-connector
spec:
  replicas: {{ .Values.cactus.besuConnector.replicaCount }}
  selector:
    matchLabels:
      {{- include "cacti.selectorLabels" . | nindent 6 }}
      component: besu-connector
  template:
    metadata:
      labels:
        {{- include "cacti.selectorLabels" . | nindent 8 }}
        component: besu-connector
    spec:
      containers:
      - name: besu-connector
        image: "{{ .Values.cactus.besuConnector.image.repository }}:{{ .Values.cactus.besuConnector.image.tag }}"
        imagePullPolicy: {{ .Values.cactus.besuConnector.image.pullPolicy }}
        env:
        - name: BESU_RPC_HTTP
          value: {{ .Values.cactus.besuConnector.config.rpc.http }}
        - name: BESU_RPC_WS
          value: {{ .Values.cactus.besuConnector.config.rpc.ws }}
        - name: BESU_CHAIN_ID
          value: "{{ .Values.cactus.besuConnector.config.chainId }}"
        - name: CACTUS_API_URL
          value: http://{{ include "cacti.fullname" . }}-api:{{ .Values.cactus.api.ports.http }}
        ports:
        - containerPort: 3000
          name: connector
        resources:
          {{- toYaml .Values.cactus.besuConnector.resources | nindent 10 }}
        livenessProbe:
          httpGet:
            path: /health
            port: connector
          initialDelaySeconds: 30
          periodSeconds: 10
        readinessProbe:
          httpGet:
            path: /health
            port: connector
          initialDelaySeconds: 10
          periodSeconds: 5
---
apiVersion: v1
kind: Service
metadata:
  name: {{ include "cacti.fullname" . }}-api
  namespace: {{ .Values.global.namespace }}
  labels:
    {{- include "cacti.labels" . | nindent 4 }}
spec:
  type: ClusterIP
  ports:
  - port: {{ .Values.cactus.api.ports.http }}
    targetPort: http
    protocol: TCP
    name: http
  - port: {{ .Values.cactus.api.ports.ws }}
    targetPort: ws
    protocol: TCP
    name: ws
  selector:
    {{- include "cacti.selectorLabels" . | nindent 4 }}
    component: api
---
apiVersion: v1
kind: Service
metadata:
  name: {{ include "cacti.fullname" . }}-besu-connector
  namespace: {{ .Values.global.namespace }}
  labels:
    {{- include "cacti.labels" . | nindent 4 }}
spec:
  type: ClusterIP
  ports:
  - port: 3000
    targetPort: connector
    protocol: TCP
    name: connector
  selector:
    {{- include "cacti.selectorLabels" . | nindent 4 }}
    component: besu-connector

