# ------------------- Maestro Broker Deployment ------------------- #
apiVersion: apps/v1
kind: Deployment
metadata:
  name: maestro-broker
spec:
  replicas: 1
  selector:
    matchLabels:
      component: broker
      app: maestro
  template:
    metadata:
      labels:
        component: broker
        app: maestro
    spec:
      affinity:
        nodeAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - weight: 1
              preference:
                matchExpressions:
                  - key: maestro-node-role
                    operator: In
                    values:
                      - infra
      containers:
        - name: broker
          image: maestroperf/maestro-broker:1.5.0
          imagePullPolicy: Always
          livenessProbe:
            httpGet:
              path: /
              port: 8161
            initialDelaySeconds: 5
            timeoutSeconds: 5
            periodSeconds: 20
            failureThreshold: 3
          ports:
            - name: mqtt
              containerPort: 1883
          volumeMounts:
             - mountPath: /opt/maestro/broker/apache-activemq/data
               name: data
             - mountPath: /opt/maestro/broker/apache-activemq/tmp
               name: tmp
      volumes:
        - name: data
          emptyDir: {}
        - name: tmp
          emptyDir: {}

---
# ------------------- Maestro Broker Cluster Service ------------------- #
apiVersion: v1
kind: Service
metadata:
  name: broker
spec:
  type: ClusterIP
  ports:
    - name: mqtt
      port: 1883
      targetPort: mqtt
  selector:
    app: maestro
    component: broker

---
# ------------------- Maestro Broker External Service ------------------- #
apiVersion: v1
kind: Service
metadata:
  name: broker-external
spec:
  type: NodePort
  ports:
    - name: mqtt
      port: 1883
      nodePort: 31983
  selector:
    app: maestro
    component: broker

---
# ------------------- Maestro Reports Service ------------------- #
apiVersion: v1
kind: Service
metadata:
  name: reports-external
  labels:
    app: maestro
spec:
  type: NodePort
  ports:
    - name: http
      port: 6500
      nodePort: 32000
  selector:
    app: maestro
    component: reports

# ---
# ------------------- Maestro Reports Storage ------------------- #
###
###
### Uncomment me for persistent storage if available on the kubernetes cluster

# apiVersion: v1
# kind: PersistentVolumeClaim
# metadata:
#   labels:
#     app: maestro
#   name: reports-data
# spec:
#   accessModes:
#   - ReadWriteOnce
#   resources:
#     requests:
#       storage: 30Gi
#   selector:
#     matchLabels:
#       app: maestro

---
# ------------------- Maestro Reports Deployment ------------------- #
apiVersion: apps/v1
kind: Deployment
metadata:
  name: maestro-reports
spec:
  replicas: 1
  selector:
    matchLabels:
      component: reports
      app: maestro
  template:
    metadata:
      labels:
        component: reports
        app: maestro
    spec:
      strategy:
        type: Recreate
      affinity:
        nodeAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - weight: 1
              preference:
                matchExpressions:
                  - key: maestro-node-role
                    operator: In
                    values:
                      - infra
      containers:
        - name: maestro-reports
          image: maestroperf/maestro-reports:1.5.0
          imagePullPolicy: Always
          livenessProbe:
            httpGet:
              path: /api/live
              port: 6500
            initialDelaySeconds: 5
            timeoutSeconds: 5
            periodSeconds: 20
            failureThreshold: 3
          env:
            - name: MAESTRO_BROKER
              value: mqtt://broker
          ports:
            - name: http
              containerPort: 6500
          volumeMounts:
            - mountPath: /maestro
              name: reports-data
      volumes:
          - name: reports-data
            emptyDir: {}
        # Comment the reports-data above and uncomment me for reports persistency
        # - name: reports-data
        #   persistentVolumeClaim:
        #     claimName: reports-data

---
# ------------------- Maestro Reports Deployment ------------------- #
apiVersion: apps/v1
kind: Deployment
metadata:
  name: maestro-worker
spec:
  replicas: 2
  selector:
    matchLabels:
      component: worker
      app: maestro
  template:
    metadata:
      labels:
        component: worker
        app: maestro
    spec:
      strategy:
        type: Recreate
      affinity:
        nodeAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - weight: 1
              preference:
                matchExpressions:
                  - key: maestro-node-role
                    operator: In
                    values:
                      - worker
      containers:
        - name: worker
          image: maestroperf/maestro-worker:1.5.0
          imagePullPolicy: Always
          env:
            - name: MAESTRO_BROKER
              value: mqtt://broker
          volumeMounts:
            - mountPath: /maestro
              name: data
      volumes:
        - name: data
          emptyDir: {}