apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: dedicated-metering-server
  namespace: metering
spec:
  persistentVolumeClaimRetentionPolicy:
    whenDeleted: Retain
    whenScaled: Retain
  podManagementPolicy: OrderedReady
  replicas: 1
  selector:
    matchLabels:
      app: dedicated-metering-server
  template:
    metadata:
      annotations:
        kubectl.kubernetes.io/default-container: network-metering-server
      labels:
        app: dedicated-metering-server
    spec:
      containers:
        - env:
            - name: API_GATEWAY_AUTH_KEY
              valueFrom:
                secretKeyRef:
                  name: api-gateway-auth
                  key: api-gateway-auth-key
            - name: AWS_DEFAULT_REGION
              value: us-west-2
            - name: AWS_REGION
              value: us-west-2
            - name: AWS_WEB_IDENTITY_TOKEN_FILE
              value: /var/run/secrets/eks.amazonaws.com/serviceaccount/token
            - name: AWS_ROLE_ARN
              value: arn:aws:iam::380838443567:role/gcp-billing-sqs-prod-reporter
          image: gcr.io/dbaas-prod/tidbcloud/network-metering-server:19661eb212cef93565bd10445494be886369349d
          name: network-metering-server
          args: ["networkmetering"]
          ports:
            - containerPort: 8080
          securityContext:
            allowPrivilegeEscalation: false
            capabilities:
              drop:
                - "ALL"
          livenessProbe:
            httpGet:
              path: /healthz
              port: 8081
            initialDelaySeconds: 15
            periodSeconds: 20
          readinessProbe:
            httpGet:
              path: /readyz
              port: 8081
            initialDelaySeconds: 5
            periodSeconds: 10
          imagePullPolicy: Always
          volumeMounts:
            - name: networkmetering
              mountPath: /configs/
            - mountPath: /var/run/secrets/eks.amazonaws.com/serviceaccount/
              name: aws-token
            - name: data
              mountPath: /data/
          resources:
            limits:
              cpu: 1000m
              memory: 4Gi
            requests:
              cpu: 500m
              memory: 2Gi
      volumes:
        - name: networkmetering
          configMap:
            name: networkmetering-config
        - name: aws-token
          projected:
            defaultMode: 420
            sources:
              - serviceAccountToken:
                  audience: sts.amazonaws.com
                  expirationSeconds: 86400
                  path: token
      terminationGracePeriodSeconds: 10
      serviceAccountName: dedicated-metering-server-manager
      serviceAccount: dedicated-metering-server-manager
  volumeClaimTemplates:
    - apiVersion: v1
      kind: PersistentVolumeClaim
      metadata:
        creationTimestamp: null
        name: data
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 200Gi
        storageClassName: standard
        volumeMode: Filesystem
