kind: StatefulSet
apiVersion: apps/v1
metadata:
  name: homeassistant
  # labels:
  # name: homeassistant
spec:
  replicas: 1
  serviceName: homeassistant
  selector:
    matchLabels:
      name: homeassistant
  template:
    metadata:
      labels:
        name: homeassistant
    spec:
      securityContext:
        runAsUser: 1000
        runAsGroup: 3000
        fsGroup: 2000

      volumes:
        - name: pvc
          persistentVolumeClaim:
            claimName: homeassistant
        - name: config
          configMap:
            name: config
        - name: secrets
          secret:
            secretName: aws-certs

      initContainers:
        - name: init
          image: busybox
          command:
            [
              "sh",
              "-c",
              "mkdir -p /config/.storage ; cp -vL /configmap/* /config",
            ]
          securityContext:
            allowPrivilegeEscalation: false
          volumeMounts:
            - name: pvc
              mountPath: /config
            - name: config
              mountPath: /configmap

      containers:
        - image: homeassistant/home-assistant
          name: homeassistant
          securityContext:
            allowPrivilegeEscalation: false
          ports:
            - name: http
              containerPort: 8123
          envFrom:
            - secretRef:
                name: secrets
          env:
            - name: TZ
              value: Europe/London
          volumeMounts:
            - name: pvc
              mountPath: /config
            - name: secrets
              mountPath: /secrets
              readOnly: true
      restartPolicy: Always
