---
apiVersion: v1
kind: Service
metadata:
  name: p2w-attest
  labels:
    app: p2w-attest
spec:
  ports:
    - port: 4343
      name: p2w-attest
      protocol: TCP
    - port: 3000
      name: metrics
  clusterIP: None
  selector:
    app: p2w-attest
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: p2w-attest
spec:
  selector:
    matchLabels:
      app: p2w-attest
  serviceName: p2w-attest
  replicas: 1
  template:
    metadata:
      labels:
        app: p2w-attest
    spec:
      restartPolicy: Always
      terminationGracePeriodSeconds: 0
      containers:
        - name: p2w-attest
          image: p2w-attest
          command:
            - python3
            - /usr/src/pyth/p2w_autoattest.py
          env:
            - name: P2W_INITIALIZE_SOL_CONTRACT
              value: "1"
            - name: P2W_EXIT_ON_ERROR
              value: "true"
          tty: true
          # Probes, in order of appearance https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/
          #
          # Startup probe - delays other probes until it gets its first success
          startupProbe:
            httpGet:
              path: /healthcheck
              port: 3000
            failureThreshold: 100 # up to 100 * 10 seconds to report initial healthy status
            periodSeconds: 10
          # Readiness probe - Used to tell load balancers to
          # start/stop sending traffic to the container, *without*
          # restarting it. The attester does not accept any traffic as
          # part of its workflow, which means this isn't very useful.
          # readinessProbe:
          # httpGet:
          #   path: /healthcheck
          #   port: 3000
          # failureThreshold: 1
          # periodSeconds: 10
          #
          # Liveness probe - decides restarts for misbehaving
          # containers
          livenessProbe:
            httpGet:
              path: /healthcheck
              port: 3000
            failureThreshold: 1 # If the attester healthcheck fails once,
            periodSeconds: 10

          ports:
            - containerPort: 4343
              name: p2w-attest
              protocol: TCP
            - containerPort: 3000
              name: metrics
              protocol: TCP
