# ===========================
# Hookshot Deployment
# ===========================
apiVersion: apps/v1
kind: Deployment
metadata:
  name: matrix-hookshot
  namespace: matrix
spec:
  replicas: 1
  selector:
    matchLabels:
      app: matrix-hookshot
  template:
    metadata:
      labels:
        app: matrix-hookshot
    spec:
      containers:
        - name: hookshot
          image: halfshot/matrix-hookshot:latest
          imagePullPolicy: Always
          ports:
            - containerPort: 9000  # webhooks
            - containerPort: 9001  # metrics
            - containerPort: 9002  # widgets
            - containerPort: 9003  # appservice
          env:
            # tell hookshot where to find files
            - name: CONFIG_PATH
              value: /data/config.yml
            - name: REGISTRATION_PATH
              value: /data/registration.yml
            - name: TRANSFORM_PATH
              value: /data/transformationFunction.js
          volumeMounts:
            - name: hookshot-data
              mountPath: /data
            - name: hookshot-registration
              mountPath: /data/registration.yml
              subPath: registration.yml
      volumes:
        - name: hookshot-data
          persistentVolumeClaim:
            claimName: hookshot-pvc
        - name: hookshot-registration
          secret:
            secretName: matrix-hookshot-registration

---

# ===========================
# Hookshot Service
# ===========================
apiVersion: v1
kind: Service
metadata:
  name: matrix-hookshot
  namespace: matrix
spec:
  selector:
    app: matrix-hookshot
  ports:
    - name: webhooks
      port: 9000
      targetPort: 9000
    - name: metrics
      port: 9001
      targetPort: 9000
    - name: widgets
      port: 9002
      targetPort: 9000
    - name: appservice
      port: 9003
      targetPort: 9003
    - name: matrix
      port: 9993
      targetPort: 9993

---
# ===========================
# Hookshot IngressRoute
# ===========================
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
  name: matrix-hookshot-http
  namespace: matrix
spec:
  entryPoints:
    - web
  routes:
    - match: Host(`hookshot-lp.allarddcs.nl`) && PathPrefix(`/webhook`)
      kind: Rule
      services:
        - name: matrix-hookshot
          port: 9000
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
  name: matrix-hookshot-tls
  namespace: matrix
spec:
  entryPoints:
    - websecure
  routes:
    - match: Host(`hookshot-lp.allarddcs.nl`) && PathPrefix(`/webhook`)
      kind: Rule
      services:
        - name: matrix-hookshot
          port: 9000
  tls:
    secretName: hookshot.allarddcs.nl-tls
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: hookshot-pv
spec:
  storageClassName: ""
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  mountOptions:
    - hard
    - nfsvers=4.1
  nfs:
    server: 192.168.2.110
    path: /mnt/nfs_share/hookshot
    readOnly: false
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: hookshot-pvc
  namespace: matrix
spec:
  storageClassName: ""
  volumeName: hookshot-pv
  accessModes:
    - ReadWriteMany
  volumeMode: Filesystem
  resources:
    requests:
      storage: 1Gi
