objectStore: s3
bucket: influxdb
s3:
  auth:
    accessKeyId: some-access-key-id
    secretAccessKey: some-secret-access-key
    existingSecret: seaweedfs
  endpoint: http://seaweedfs:8333
databases: foo
containerPorts:
  http: 8181
containerSecurityContext:
  enabled: true
  runAsUser: 1002
podSecurityContext:
  enabled: true
  fsGroup: 1002
service:
  type: LoadBalancer
  ports:
    http: 80
serviceAccount:
  create: true
  automountServiceAccountToken: true
# Using Helm hooks is incompatible with 'extra-deploy' objects given
# the pre-install hook requires these 'extra-deploy' objects to be created
# in advance, hence we'll run 'create-admin-token' as a normal K8s job
useHelmHooks: false
createAdminTokenJob:
  enabled: true
  cleanup: false
  waitForS3:
    retryAttempts: 30
    retryInterval: 5
extraDeploy:
- apiVersion: v1
  kind: Secret
  metadata:
    name: seaweedfs
    namespace: "{{ include \"common.names.namespace\" . }}"
    labels:
      app.kubernetes.io/part-of: influxdb
      app.kubernetes.io/component: seaweedfs
  type: Opaque
  data:
    s3-access-key-id: "{{ .Values.s3.auth.accessKeyId | b64enc }}"
    s3-secret-access-key: "{{ .Values.s3.auth.secretAccessKey | b64enc }}"
- apiVersion: apps/v1
  kind: StatefulSet
  metadata:
    name: seaweedfs
    namespace: "{{ include \"common.names.namespace\" . }}"
    labels:
      app.kubernetes.io/part-of: influxdb
      app.kubernetes.io/component: seaweedfs
  spec:
    replicas: 1
    selector:
      matchLabels:
        app.kubernetes.io/part-of: influxdb
        app.kubernetes.io/component: seaweedfs
    serviceName: seaweedfs
    template:
      metadata:
        labels:
          app.kubernetes.io/part-of: influxdb
          app.kubernetes.io/component: seaweedfs
      spec:
        initContainers:
        - name: auth-config-init
          image: docker.io/bitnami/seaweedfs:latest
          command:
          - bash
          args:
          - -ec
          - |
            cat > "/s3/config.json" <<EOF
            {
              "identities": [
                {
                  "name": "admin",
                  "credentials": [
                    {
                      "accessKey": "${ADMIN_ACCESS_KEY_ID}",
                      "secretKey": "${ADMIN_SECRET_ACCESS_KEY}"
                    }
                  ],
                  "actions": [
                    "Admin",
                    "Read",
                    "List",
                    "Tagging",
                    "Write"
                  ]
                }
              ]
            }
            EOF
          env:
          - name: ADMIN_ACCESS_KEY_ID
            valueFrom:
              secretKeyRef:
                name: seaweedfs
                key: s3-access-key-id
          - name: ADMIN_SECRET_ACCESS_KEY
            valueFrom:
              secretKeyRef:
                name: seaweedfs
                key: s3-secret-access-key
          volumeMounts:
          - name: empty-dir
            mountPath: /s3
            subPath: s3-dir
        containers:
        - name: seaweedfs
          image: docker.io/bitnami/seaweedfs:latest
          securityContext:
            runAsNonRoot: true
            privileged: false
            allowPrivilegeEscalation: false
            capabilities:
              drop: ["ALL"]
            seccompProfile:
              type: "RuntimeDefault"
          command:
          - weed
          args:
          - server
          - -s3
          - "-s3.port=8333"
          - "-s3.config=/s3/config.json"
          ports:
          - name: http
            containerPort: 8333
          livenessProbe:
            failureThreshold: 6
            initialDelaySeconds: 30
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 5
            tcpSocket:
              port: http
          readinessProbe:
            failureThreshold: 6
            initialDelaySeconds: 30
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 5
            httpGet:
              path: /status
              port: http
          volumeMounts:
          - mountPath: /s3
            name: empty-dir
            subPath: s3-dir
            readOnly: true
        - name: bucket-creator
          image: bitnami/aws-cli:latest
          securityContext:
            runAsNonRoot: true
            privileged: false
            allowPrivilegeEscalation: false
            capabilities:
              drop: ["ALL"]
            seccompProfile:
              type: "RuntimeDefault"
          command:
          - bash
          args:
          - -ec
          - |
            retry_while() {
                local cmd="${1:?cmd is missing}"
                local return_value=1

                read -r -a command <<<"$cmd"
                for ((i = 1; i <= 12; i += 1)); do
                    "${command[@]}" && return_value=0 && break
                    sleep 5
                done
                return $return_value
            }
            if ! retry_while "aws --endpoint-url http://127.0.0.1:8333 s3 ls"; then
                error "Error connecting to S3"
                exit 1
            fi
            aws --endpoint-url http://127.0.0.1:8333 s3 mb s3://{{ .Values.bucket }}
            sleep infinity
          env:
          - name: AWS_ACCESS_KEY_ID
            valueFrom:
              secretKeyRef:
                name: seaweedfs
                key: s3-access-key-id
          - name: AWS_SECRET_ACCESS_KEY
            valueFrom:
              secretKeyRef:
                name: seaweedfs
                key: s3-secret-access-key
        volumes:
        - name: empty-dir
          emptyDir: {}
- apiVersion: v1
  kind: Service
  metadata:
    name: seaweedfs
    namespace: "{{ include \"common.names.namespace\" . }}"
    labels:
      app.kubernetes.io/part-of: influxdb
      app.kubernetes.io/component: seaweedfs
  spec:
    type: ClusterIP
    ports:
    - name: http
      port: 8333
      targetPort: http
    selector:
      app.kubernetes.io/part-of: influxdb
      app.kubernetes.io/component: seaweedfs
