# Deploy withings-sync as a Kubernetes deployment
# Please also see contrib/k8s-job.yaml for a Kubernetes CronJob
#
# To install:
# - kubectl create namespace FOO
# - kubectl -n FOO create -f (this file)
#
# To check logs:
# - kubectl -n FOO logs -l app=withings-sync
#
# Because the app is running without STDIN, it will not pause to wait
# for you to enter the oauth token.  Instead it will throw an error
#   EOFError: EOF when reading a line
# and continue to sleep.  To set up for the first time, run something
# like this manually, and enter the oauth token provided after you
# follow the link given:
#
# - kubectl -n FOO exec -ti $( kubectl -n FOO get pods | awk '$3=="Running" {print $1; exit}' ) -- withings-sync
apiVersion: apps/v1
kind: Deployment
metadata:
  name: withings-sync
spec:
  replicas: 1
  revisionHistoryLimit: 3
  selector:
    matchLabels:
      app: withings-sync
  template:
    metadata:
      labels:
        app: withings-sync
    spec:
      containers:
      - name: withings-sync
        image: docker.io/stv0g/withings-sync
        imagePullPolicy: IfNotPresent

        # override $HOME to put our oauth file in a known place
        env:
        - name: HOME
          value: /data

        # read usernames/passwords from the secret we defined
        envFrom:
        - secretRef:
            name: credentials

        volumeMounts:
        - mountPath: /data
          name: oauth-cache

        # run every 15 minutes, synched to clock time
        command:
        - sh
        - -c
        - while true; do date; withings-sync; echo; sleep 10000; done

      # Never run this container as root
      securityContext:
        fsGroup: 1234
        runAsGroup: 1234
        runAsUser: 1234
        runAsNonRoot: True

      volumes:
      - name: oauth-cache
        persistentVolumeClaim:
          claimName: withings-oauth-cache


