billimek / billimek-charts

DEPRECATED - new home is https://github.com/k8s-at-home/charts
Apache License 2.0
89 stars 52 forks source link

[home-assistant] Allow command (entrypoint) override for HA #277

Closed dcplaya closed 4 years ago

dcplaya commented 4 years ago

Special notes for your reviewer:

Allowed me to use a Nortek zigbee/zwave device by ser2sock and a custom configMap to run socat before HA starts. The default is disabled and also runs HA if it is enabled

Example configMap

kind: ConfigMap
apiVersion: v1
metadata:
  name: zha
  namespace: home-automation
  annotations:
    fluxcd.io/ignore: false
data:
  zha: |
    #!/bin/bash
    case "$1" in
        start)
          socat pty,link=/dev/ttyZHA,raw,user=0,group=0,mode=777 tcp:ser2sock-zigbee.home-automation.svc:10000,forever,interval=10,fork &
          ;;
        stop)
          stop
          ;;
        restart)
          stop
          start
          ;;
        status)
          ;;
        *)
          echo "Usage: $0 {start|stop|status|restart}"
    esac
    exit 0

Checklist

[Place an '[x]' (no spaces) in all applicable fields. Please remove unrelated fields.]

runningman84 commented 4 years ago

I think a sidecar might be a better option here?

dcplaya commented 4 years ago

Probably, I'm new to all of k8s. I can see if I can re-work it into a sidecar (once I actually learn what a sidecar does! :D)

Edit: Looks like I can run a alpine socat container and share the /dev mounts between the two. Not sure if HA will like doing that but I will give it a try and update the PR when I get it

dcplaya commented 4 years ago

Anyone have any experience sharing a /dev device between pods? I shared them like one would share a volume between the two but it does not seem to like that (either HA or Kubernetes). I am still re-working/mucking with it to see if I screwed something up but if anyone has a idea/suggestion, please chime in.

Branch location is here, while I mess around trying to get it to work.

jwalker343 commented 4 years ago

@dcplaya I bashed my head against doing this same thing for a week or so and eventually gave up. There is a lot of deliberate isolation around things in /dev/* as things like /dev/mem exist. I eventually rolled my own docker image to get socat working, but socat was spotty and the image was tedious to maintain.

Ultimately, I deployed zwave2mqtt on my raspberry pi that hosts the usb controller, and then stood up an mqtt broker in Kubernetes. Works flawless, much more stable than socat/ser2net, I would highly recommend.

If you're intent on a sidecar :), the 1.17 feature PodShareProcessNamespace may get you somewhere.

dcplaya commented 4 years ago

I had a feeling things in /dev were special. I haven't revisited it this week, moved on to some other charts to clear my head (got to get some wins every now and then for a moral booster). I'll check out the PodShareProcessNamespace but have a feeling zigbee2mqtt is going to be where I end up. And luckily someone recently added that to the HA chart! I will just have to bite the bullet and re-do some Node-Red flows, not the end of the world.

dcplaya commented 4 years ago

Officially giving up on this. The PodShareProcessNamespace is useful for this scenario but since the PID changes on each pod creation, there is no way to consistently link the two pods together. I will leave the branch active if someone wants to try again but I will be flipping to zigbee2mqtt and re-configuring my setup to use that instead.