---
apiVersion: v1
kind: Namespace
metadata:
  name: home-assistant
---
apiVersion: v1
kind: Service
metadata:
  namespace: home-assistant
  name: home-assistant
spec:
  selector:
    app: home-assistant
  type: ClusterIP
  ports:
  - name: http
    protocol: TCP
    port: 80
    targetPort: 8123
---
apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: home-assistant
  name: home-assistant
  labels:
    app: home-assistant
spec:
  replicas: 1
  selector:
    matchLabels:
      app: home-assistant
  template:
    metadata:
      labels:
        app: home-assistant
    spec:
      containers:
      - name: bluez
        image: ghcr.io/mysticrenji/bluez-service:v1.0.0
        securityContext:
          privileged: true
      - name: home-assistant
        image: ghcr.io/mysticrenji/homeassistant-arm64:2023.3.0
        resources:
          requests:
            memory: "256Mi"
          limits:
            memory: "512Mi"
        ports:
        - containerPort: 8123
        volumeMounts:
        - mountPath: /config
          name: config
        - mountPath: /config/configuration.yaml
          subPath: configuration.yaml
          name: configmap-file
        - mountPath: /config/automations.yaml
          subPath: automations.yaml
          name: configmap-file
        - mountPath: /media
          name: media-volume          
        # - mountPath: /run/dbus
        #   name: d-bus
        #   readOnly: true
        - mountPath: /dev/ttyUSB1
          name: zigbee
        #- mountPath: /dev/video0
        #  name: cam
        securityContext:
          privileged: true
          capabilities:
            add:
              - NET_ADMIN
              - NET_RAW
              - SYS_ADMIN
      hostNetwork: true
      volumes:
      - name: config
        persistentVolumeClaim:
          claimName: home-assistant-pvc
      - name: media-volume
        hostPath:
          path: /tmp/media
      - name: configmap-file
        configMap:
          name: home-assistant-configmap
      #  hostPath:
      #    path: /tmp/home-assistant
      #    type: DirectoryOrCreate
      # - name: d-bus
      #   hostPath:
      #     path: /run/dbus
      - name: zigbee
        hostPath:
          path: /dev/ttyACM0
      #- name: cam
      #  hostPath:
      #    path: /dev/video0
---
kind: ConfigMap
apiVersion: v1
metadata:
  name: home-assistant-configmap
  namespace: home-assistant
data:
  known_devices.yaml: |
  automations.yaml: |
  configuration.yaml: |-
    default_config:
    frontend:
      themes: !include_dir_merge_named themes
    automation: !include automations.yaml
    http:
      use_x_forwarded_for: true
      trusted_proxies:
        - 10.10.0.0/16
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: home-assistant-pvc
  labels:
    app: home-assistant
  namespace: home-assistant
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 9Gi 
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: zwavejs2mqtt-pvc
  labels:
    app: zwavejs2mqtt
  namespace: home-assistant
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 500Mi
