apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: spire-server
  namespace: spire
  labels:
    app: spire-server
spec:
  replicas: 1
  selector:
    matchLabels:
      app: spire-server
  serviceName: spire-server
  template:
    metadata:
      namespace: spire
      labels:
        app: spire-server
    spec:
      serviceAccountName: spire-server
      shareProcessNamespace: true
      containers:
        - name: spire-server
          image: gcr.io/spiffe-io/spire-server:0.12.0
          args:
            - -config
            - /run/spire/config/server.conf
          livenessProbe:
            exec:
              command: ["/opt/spire/bin/spire-server", "healthcheck", "-registrationUDSPath", "/tmp/spire-server/private/api.sock"]
            failureThreshold: 2
            initialDelaySeconds: 15
            periodSeconds: 60
            timeoutSeconds: 3
          readinessProbe:
            exec:
              command: ["/opt/spire/bin/spire-server", "healthcheck", "--shallow", "-registrationUDSPath", "/tmp/spire-server/private/api.sock"]
            initialDelaySeconds: 5
            periodSeconds: 5
          ports:
            - containerPort: 8081
          volumeMounts:
            - name: spire-config
              mountPath: /run/spire/config
              readOnly: true
            - name: spire-secrets
              mountPath: /run/spire/secrets
              readOnly: true
            - name: spire-data
              mountPath: /run/spire/data
              readOnly: false
            - name: spire-registration-socket
              mountPath: /tmp/spire-server/private
              readOnly: false
        - name: k8s-workload-registrar
          # image: fmemon/k8s-workload-registrar:latest
          image: gcr.io/spiffe-io/k8s-workload-registrar:0.12.0
          args:
            - -config
            - /run/spire/config/k8s-workload-registrar.conf
          # env:
          #   - name: MY_POD_UID
          #     valueFrom:
          #       fieldRef:
          #         fieldPath: metadata.uid
          ports:
            - containerPort: 9443
              name: webhook
              protocol: TCP
          volumeMounts:
            - mountPath: /run/spire/config
              name: k8s-workload-registrar-config
              readOnly: true
            # - mountPath: /tmp/spire-agent/public # is it necessary?? i think not
            #   name: spire-agent-socket
            #   readOnly: true
            - name: spire-registration-socket
              mountPath: /tmp/spire-server/private
              readOnly: true
      volumes:
        - name: spire-config
          configMap:
            name: spire-server
        - name: spire-secrets
          secret:
            secretName: spire-server
        # - name: spire-agent-socket
        #   hostPath:
        #     path: /run/spire/agent-sockets
        #     type: DirectoryOrCreate
        - name: k8s-workload-registrar-config
          configMap:
            name: k8s-workload-registrar
        - name: spire-registration-socket
          hostPath:
            path: /run/spire/server-sockets
            type: DirectoryOrCreate
  volumeClaimTemplates:
    - metadata:
        name: spire-data
        namespace: spire
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 1Gi
