# // Copyright 2020 Stefan Prisca
# //
# // Licensed under the Apache License, Version 2.0 (the "License");
# // you may not use this file except in compliance with the License.
# // You may obtain a copy of the License at
# //
# //     http://www.apache.org/licenses/LICENSE-2.0
# //
# // Unless required by applicable law or agreed to in writing, software
# // distributed under the License is distributed on an "AS IS" BASIS,
# // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# // See the License for the specific language governing permissions and
# // limitations under the License.

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: persister
spec:
  selector:
    matchLabels:
      app: persister # has to match .spec.template.metadata.labels
  serviceName: "persister"
  replicas: 1 # by default is 1
  template:
    metadata:
      labels:
        app: persister # has to match .spec.selector.matchLabels
        klight.networkId: myFirstNetwork # the label that KLight operator listens to to connect the pod to the network.
    spec:
      containers:
      - name: persister
        image: localhost:32000/persister:0.1.0
        imagePullPolicy: Always
        command: ["./persister"]
        args: ["-lpAddress=$(LP_ADDRESS)"]
        env:
          - name: LP_ADDRESS
            value: ":9081"
      - name: lightpeer
        image: localhost:32000/lightpeer:v0.1.0-k8s
        imagePullPolicy: Always
        command: ["./lightpeer"]
        args: ["-repo=$(LP_BLOCKREPO)", "-host=0.0.0.0", "-otlp=otel-collector.observability.svc.cluster.local:55680", "-v"]
        resources:
          limits:
            cpu: 100m
            memory: 100Mi
          requests:
            cpu: 50m
            memory: 50Mi
        env:
          - name: LP_BLOCKREPO
            value: "/blockRepository"
          - name: REL_STO_PATH
            value: "foo/faa" 
        ports:
        - containerPort: 9081 # gRPC port.
        volumeMounts:
        - name: persister-lightpeer-sto
          mountPath: /blockRepository
  volumeClaimTemplates:
  - metadata:
      name: persister-lightpeer-sto
      namespace: lightchain
    spec:
      accessModes: 
        - ReadWriteOnce
      resources:
        requests:
          storage: 50Mi
