apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: atlantis
spec:
  serviceName: atlantis
  replicas: 1
  updateStrategy:
    type: RollingUpdate
    rollingUpdate:
      partition: 0
  selector:
    matchLabels:
      app: atlantis
  template:
    metadata:
      labels:
        app: atlantis
    spec:
      securityContext:
        fsGroup: 1000 # Atlantis group (1000) read/write access to volumes.
      containers:
        - name: atlantis
          image: runatlantis/atlantis:v0.17.6 # 1. Replace <VERSION> with the most recent release.
          env:
            - name: ATLANTIS_REPO_ALLOWLIST
              value: github.com/korosuke613/* # 2. Replace this with your own repo allowlist.

            ### GitHub Config ###
            - name: ATLANTIS_GH_USER
              value: korosuke613 # 3i. If you're using GitHub replace <YOUR_GITHUB_USER> with the username of your Atlantis GitHub user without the `@`.
            - name: ATLANTIS_GH_TOKEN
              valueFrom:
                secretKeyRef:
                  name: atlantis-vcs
                  key: token
            - name: ATLANTIS_GH_WEBHOOK_SECRET
              valueFrom:
                secretKeyRef:
                  name: atlantis-vcs
                  key: webhook-secret
            ### End GitHub Config ###

            - name: ATLANTIS_WEB_BASIC_AUTH
              value: "true"
            - name: ATLANTIS_WEB_USERNAME
              valueFrom:
                secretKeyRef:
                  name: atlantis-basic
                  key: username
            - name: ATLANTIS_WEB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: atlantis-basic
                  key: password

            - name: ATLANTIS_DATA_DIR
              value: /atlantis
            - name: ATLANTIS_PORT
              value: "4141" # Kubernetes sets an ATLANTIS_PORT variable so we need to override.
          volumeMounts:
            - name: atlantis-data
              mountPath: /atlantis
          ports:
            - name: atlantis
              containerPort: 4141
          resources:
            requests:
              memory: 256Mi
              cpu: 100m
            limits:
              memory: 256Mi
              cpu: 100m
          livenessProbe:
            # We only need to check every 60s since Atlantis is not a
            # high-throughput service.
            periodSeconds: 60
            httpGet:
              path: /healthz
              port: 4141
              # If using https, change this to HTTPS
              scheme: HTTP
          readinessProbe:
            periodSeconds: 60
            httpGet:
              path: /healthz
              port: 4141
              # If using https, change this to HTTPS
              scheme: HTTP
  volumeClaimTemplates:
    - metadata:
        name: atlantis-data
      spec:
        accessModes: ["ReadWriteOnce"] # Volume should not be shared by multiple nodes.
        resources:
          requests:
            # The biggest thing Atlantis stores is the Git repo when it checks it out.
            # It deletes the repo after the pull request is merged.
            storage: 5Gi
