apiVersion: apps/v1
kind: Deployment
metadata:
  name: selenium-node-firefox
  labels:
    app: selenium-node-firefox
spec:
  replicas: 1
  selector:
    matchLabels:
      app: selenium-node-firefox
  template:
    metadata:
      labels:
        app: selenium-node-firefox
    spec:
      volumes:
      - name: dshm
        emptyDir:
          medium: Memory
      containers:
      - name: selenium-node-firefox
        image: selenium/node-firefox:4.0.0
        imagePullPolicy: Always
        ports:
          - containerPort: 5555
        volumeMounts:
          - mountPath: /dev/shm
            name: dshm
        env:
          - name: HUB_HOST
            value: "selenium-hub"
          - name: SE_EVENT_BUS_HOST
            value: "selenium-hub"
          - name: SE_EVENT_BUS_PUBLISH_PORT
            value: "4442"
          - name: SE_EVENT_BUS_SUBSCRIBE_PORT
            value: "4443"
        resources:
          limits:
            memory: "1000Mi"
            cpu: ".5"
#        livenessProbe:
#          httpGet:
#            path: /status
#            port: 5555
#          initialDelaySeconds: 30
#          timeoutSeconds: 5
        lifecycle:
          preStop:
            exec:
              command: [
                "/bin/sh", 
                "-c", 
                "while [ $(curl http://localhost:5555/status | jq '.value.node.slots[0].session.sessionId | length') -ge 1 ]; do sleep 5; echo 'Shutdown requested but session running'; done; \ 
                  nodeid=$(curl http://localhost:5555/status | jq '.value.node.id' | awk '{print substr($1, 2, 36)}'); \
                  curl -X DELETE http://{{ .Values.hub.name }}:4444/se/grid/distributor/node/$nodeid --header 'X-REGISTRATION-SECRET;'"
                ]
      terminationGracePeriodSeconds: 3600
      