---
# Source: hivemq-operator/templates/hivemq-operator/operator-templates.yaml
apiVersion: v1
data:
  cluster-daemon-set.yaml: |-
    kind: DaemonSet
    apiVersion: apps/v1
    metadata:
      name: "{{ spec.name }}"
      namespace: "{{ spec.namespace }}"
      labels:
        app: "hivemq"
        hivemq-cluster: "{{ spec.name }}"
        {% for entry in spec.labels.entrySet() %}
        {{ entry.key }}: "{{entry.value}}"
        {% endfor %}
      ownerReferences:
      - apiVersion: hivemq.com/v1
        kind: HiveMQCluster
        blockOwnerDeletion: true
        name: "{{ spec.name }}"
        uid: "{{ spec.metadata.uid }}"
    spec:
      selector:
        matchLabels:
          app: "hivemq"
          hivemq-cluster: "{{ spec.name }}"
      template:
        metadata:
          labels:
            app: "hivemq"
            hivemq-cluster: "{{ spec.name }}"
            hivemq.com/node-offline: "false"
        spec:
          initContainers:
          - name: "init-shared"
            image: "busybox:latest"
            command: ["/bin/sh", "-c"]
            args:
              - |
                mkdir -p /opt/hivemq/bin
                mkdir -p /opt/hivemq/backup
                mkdir -p /opt/hivemq/extensions
                mkdir -p /opt/hivemq/conf
                mkdir -p /opt/hivemq/license
                cp -r /opt/hivemq/* /hivemq-data/
                cp -r /opt/hivemq/* /conf-override/
            volumeMounts:
            - name: shared-data
              mountPath: /hivemq-data
            - name: conf-override
              mountPath: /conf-override
              readOnly: false
            - name: live-info
              mountPath: /etc/podinfo
            - name: backup
              mountPath: /opt/hivemq/backup
              readOnly: false
            {% for map in spec.configMaps %}
            {% if map.path != "none" %}
            - name: {{ map.name }}
              mountPath: {{ util:stringReplace(map.path, "/opt/hivemq/", "/conf-override/") }}
            {% endif %}
            {% endfor %}
            {% for extension in spec.extensions %}
            {% if extension.configMap != null %}
            - name: {{ extension.configMap }}
              mountPath: /conf-override/extensions/{{ extension.name }}
            {% endif %}{% endfor %}
          - name: dns-wait
            image: hivemq/init-dns-wait:1.0.0
            volumeMounts:
              - mountPath: /mnt/misc
                name: dns-wait-config
          {% for initContainer in spec.initialization %}
          - name: {{ initContainer.name }}
            image: {{ initContainer.image }}
            command: {{ initContainer.command }}
            args: {{ initContainer.args }}
            volumeMounts:
            {% for map in spec.configMaps %}
            {% if map.path != "none" %}
            - name: {{ map.name }}
              mountPath: {{ util:stringReplace(map.path, "/opt/hivemq/", "/conf-override/") }}
            {% endif %}
            {% endfor %}
            {% for extension in spec.extensions %}
            {% if extension.configMap != null %}
            - name: {{ extension.configMap }}
              mountPath: /conf-override/extensions/{{ extension.name }}
            {% endif %}{% endfor %}
          {% endfor %}
          {% if spec.imagePullSecrets != null && spec.imagePullSecrets.size() > 0 %}
          imagePullSecrets:
          {% for secret in spec.imagePullSecrets %}
          - name: {{ secret }}
          {% endfor %}
          {% endif %}
          {% if spec.serviceAccountName != null %}
          serviceAccountName: "{{ spec.serviceAccountName }}"
          {% endif %}
          securityContext:
            sysctls:
              - name: net.ipv4.ip_local_port_range
                value: "1024 65535"
          containers:
            - name: "hivemq"
              securityContext:
                privileged: false
                allowPrivilegeEscalation: false
              env:
                - name: HIVEMQ_DNS_DISCOVERY_ADDRESS
                  value: "hivemq-{{ spec.name }}-cluster.{{ spec.namespace }}.svc.cluster.local."
                - name: JAVA_OPTS
                  value: "{{ spec.javaOptions }}"
                - name: HIVEMQ_CLUSTER_PORT
                  value: "{{ util:getPort(spec, "cluster").port }}"
                - name: HIVEMQ_MQTT_PORT
                  value: "{{ util:getPort(spec, "mqtt").port }}"
                - name: HIVEMQ_CONTROL_CENTER_PORT
                  value: "{{ util:getPort(spec, "cc").port }}"
                - name: HIVEMQ_REST_API_PORT
                  value: "{{ util:getPort(spec, "api").port }}"
                - name: HIVEMQ_REST_API_ENABLED
                  value: "{{ util:getPort(spec, "api").port != null }}"
                - name: HIVEMQ_CLUSTER_REPLICA_COUNT
                  value: "{{ spec.clusterReplicaCount }}"
                - name: HIVEMQ_CLUSTER_OVERLOAD_PROTECTION
                  value: "{{ spec.clusterOverloadProtection }}"
                - name: HIVEMQ_MAX_CLIENT_ID_LENGTH
                  value: "{{ spec.restrictions.maxClientIdLength }}"
                - name: HIVEMQ_BIND_ADDRESS
                  valueFrom:
                    fieldRef:
                      fieldPath: status.podIP
                - name: HIVEMQ_MAX_TOPIC_LENGTH
                  value: "{{ spec.restrictions.maxTopicLength }}"
                - name: HIVEMQ_MAX_CONNECTIONS
                  value: "{{ spec.restrictions.maxConnections }}"
                - name: HIVEMQ_INCOMING_BANDWIDTH_THROTTLING
                  value: "{{ spec.restrictions.incomingBandwidthThrottling }}"
                - name: HIVEMQ_NO_CONNECT_IDLE_TIMEOUT
                  value: "{{ spec.restrictions.noConnectIdleTimeout }}"
                - name: HIVEMQ_SESSION_EXPIRY_INTERVAL
                  value: "{{ spec.mqtt.sessionExpiryInterval }}"
                - name: HIVEMQ_MAX_PACKET_SIZE
                  value: "{{ spec.mqtt.maxPacketSize }}"
                - name: HIVEMQ_SERVER_RECEIVE_MAXIMUM
                  value: "{{ spec.mqtt.serverReceiveMaximum }}"
                - name: HIVEMQ_KEEPALIVE_MAX
                  value: "{{ spec.mqtt.keepaliveMax }}"
                - name: HIVEMQ_KEEPALIVE_ALLOW_UNLIMITED
                  value: "{{ spec.mqtt.keepaliveAllowUnlimited }}"
                - name: HIVEMQ_TOPIC_ALIAS_ENABLED
                  value: "{{ spec.mqtt.topicAliasEnabled }}"
                - name: HIVEMQ_TOPIC_ALIAS_MAX_PER_CLIENT
                  value: "{{ spec.mqtt.topicAliasMaxPerClient }}"
                - name: HIVEMQ_SUBSCRIPTION_IDENTIFIER_ENABLED
                  value: "{{ spec.mqtt.subscriptionIdentifierEnabled }}"
                - name: HIVEMQ_WILDCARD_SUBSCRIPTION_ENABLED
                  value: "{{ spec.mqtt.wildcardSubscriptionEnabled }}"
                - name: HIVEMQ_SHARED_SUBSCRIPTION_ENABLED
                  value: "{{ spec.mqtt.sharedSubscriptionEnabled }}"
                - name: HIVEMQ_MAX_QOS
                  value: "{{ spec.mqtt.maxQos }}"
                - name: HIVEMQ_RETAINED_MESSAGES_ENABLED
                  value: "{{ spec.mqtt.retainedMessagesEnabled }}"
                - name: HIVEMQ_QUEUED_MESSAGE_MAX_QUEUE_SIZE
                  value: "{{ spec.mqtt.queuedMessageMaxQueueSize }}"
                - name: HIVEMQ_QUEUED_MESSAGE_STRATEGY
                  value: "{{ spec.mqtt.queuedMessageStrategy }}"
                - name: HIVEMQ_ALLOW_EMPTY_CLIENT_ID
                  value: "{{ spec.security.allowEmptyClientId }}"
                - name: HIVEMQ_PAYLOAD_FORMAT_VALIDATION
                  value: "{{ spec.security.payloadFormatValidation }}"
                - name: HIVEMQ_TOPIC_FORMAT_VALIDATION
                  value: "{{ spec.security.topicFormatValidation }}"
                - name: HIVEMQ_ALLOW_REQUEST_PROBLEM_INFORMATION
                  value: "{{ spec.security.allowRequestProblemInformation }}"
                - name: HIVEMQ_ENABLE_PROMETHEUS
                  value: "{{ spec.monitoring.enablePrometheus }}"
                - name: HIVEMQ_CONFIG_OVERRIDE
                  value: |
    {{ util:indent(15, spec.configOverride) }}
                - name: HIVEMQ_LISTENER_CONFIGURATION
                  value: |
    {{ util:indent(15, spec.listenerConfiguration) }}
                - name: HIVEMQ_REST_API_CONFIGURATION
                  value: |
    {{ util:indent(15, spec.restApiConfiguration) }}
              {% for env in spec.env %}
                - name: {{ env.name }}
                  value: |
                    {{ util:indentCustom(15, 0, env.value) }}
              {% endfor %}
              image: "{{ util:getTaggedImage(spec) }}"
              ports:{% for portInstance in spec.ports %}
                - containerPort: {{ portInstance.port }}
                  name: {{ portInstance.name }}{% endfor %}
              imagePullPolicy: "{{ spec.imagePullPolicy }}"
              resources:
                limits:
                  cpu: "{{ util:getCpuLimit(spec) }}"
                  memory: "{{ util:getMemoryLimit(spec) }}"
                  ephemeral-storage: "{{ util:getStorageLimit(spec) }}"
                requests:
                  cpu: "{{ spec.cpu }}"
                  memory: "{{ spec.memory }}"
                  ephemeral-storage: "{{ spec.ephemeralStorage }}"
              readinessProbe:
                exec:
                  command:
                    - /opt/hivemq/bin/readiness_probe.sh
                initialDelaySeconds: 3
                periodSeconds: 5
              livenessProbe:
                tcpSocket:
                  port: {{ util:getPort(spec, "mqtt").port }}
                initialDelaySeconds: 15
                periodSeconds: 30
                failureThreshold: 240
              volumeMounts:
              - name: shared-data
                mountPath: /hivemq-data
                readOnly: false
              - name: conf-override
                mountPath: /conf-override
                readOnly: false
              - name: live-info
                mountPath: /etc/podinfo
              - name: backup
                mountPath: /opt/hivemq/backup
                readOnly: false
              - name: log
                mountPath: /opt/hivemq/log
                readOnly: false
              - name: audit
                mountPath: /opt/hivemq/audit
                readOnly: false
                {% for map in spec.configMaps %}
                - name: {{ map.name }}
                  mountPath: {{ util:stringReplace(map.path, "/opt/hivemq/", "/conf-override/") }}
                {% endfor %}
                {% for extension in spec.extensions %}
                {% if extension.configMap != null %}
                - name: {{ extension.configMap }}
                  mountPath: /conf-override/extensions/{{ extension.name }}
                {% endif %}{% endfor %}
                {% for secret in spec.secrets %}
                {% if secret.path != "none" %}}
                - name: {{ secret.name }}
                  mountPath: {{ util:stringReplace(secret.path, "/opt/hivemq/", "/conf-override/") }}
                {% endif %}
                {% endfor %}
          # Wait longer for replication tasks
          terminationGracePeriodSeconds: 3600
          volumes:
            - name: shared-data
              emptyDir: {}
            # For overriding configuration after init containers have finished without overwriting the directory
            - name: conf-override
              emptyDir: {}
            - name: backup
              emptyDir: {}
            - name: log
              emptyDir: {}
            - name: audit
              emptyDir: {}
            - name: live-info
              configMap:
                name: hivemq-cluster-{{ spec.name }}-dynamic-state
            - name: dns-wait-config
              configMap:
                name: hivemq-cluster-{{ spec.name }}-dns-wait-config
            {% for map in spec.configMaps %}
            - name: {{ map.name }}
              configMap:
                name: {{ map.name }}
            {% endfor %}
            {% for extension in spec.extensions %}
            {% if extension.configMap != null %}
            - name: {{ extension.configMap }}
              configMap:
                name: {{ extension.configMap }}
            {% endif %}{% endfor %}
            {% for secret in spec.secrets %}
            - name: {{ secret.name }}
              secret:
                secretName: {{ secret.name }}
            {% endfor %}
  cluster-deployment-unsafe-sysctls.yaml: |-
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: "{{ spec.name }}"
      namespace: "{{ spec.namespace }}"
      labels:
        app: "hivemq"
        hivemq-cluster: "{{ spec.name }}"
        {% for entry in spec.labels.entrySet() %}
        {{ entry.key }}: "{{entry.value}}"
        {% endfor %}
      ownerReferences:
      - apiVersion: hivemq.com/v1
        kind: HiveMQCluster
        blockOwnerDeletion: true
        name: "{{ spec.name }}"
        uid: "{{ spec.metadata.uid }}"
    spec:
      progressDeadlineSeconds: 10800
      revisionHistoryLimit: 2
      selector:
        matchLabels:
          app: "hivemq"
          hivemq-cluster: "{{ spec.name }}"
      replicas: "{{ spec.nodeCount }}"
      strategy:
        type: RollingUpdate
        rollingUpdate:
          maxSurge: 1
          maxUnavailable: 0
      template:
        metadata:
          labels:
            app: "hivemq"
            hivemq-cluster: "{{ spec.name }}"
            hivemq.com/node-offline: false
        spec:
          initContainers:
          - name: "init-shared"
            image: "busybox:latest"
            command: ["/bin/sh", "-c"]
            args:
              - |
                mkdir -p /opt/hivemq/backup
                mkdir -p /opt/hivemq/extensions
                mkdir -p /opt/hivemq/conf
                mkdir -p /opt/hivemq/license
                cp -r /opt/hivemq/* /hivemq-data/
                cp -r /opt/hivemq/* /conf-override/
            volumeMounts:
            - name: shared-data
              mountPath: /hivemq-data
            - name: conf-override
              mountPath: /conf-override
              readOnly: false
            - name: live-info
              mountPath: /etc/podinfo
            - name: backup
              mountPath: /opt/hivemq/backup
              readOnly: false
            {% for map in spec.configMaps %}
            - name: {{ map.name }}
              mountPath: {{ util:stringReplace(map.path, "/opt/hivemq/", "/conf-override/") }}
            {% endfor %}
            {% for extension in spec.extensions %}
            {% if extension.configMap != null %}
            - name: {{ extension.configMap }}
              mountPath: /conf-override/extensions/{{ extension.name }}
            {% endif %}{% endfor %}
          {% for initContainer in spec.initialization %}
          - name: {{ initContainer.name }}
            image: {{ initContainer.image }}
            command: {{ initContainer.command }}
            args: {{ initContainer.args }}
            volumeMounts:
            {% for map in spec.configMaps %}
            - name: {{ map.name }}
              mountPath: {{ util:stringReplace(map.path, "/opt/hivemq/", "/conf-override/") }}
            {% endfor %}
            {% for extension in spec.extensions %}
            {% if extension.configMap != null %}
            - name: {{ extension.configMap }}
              mountPath: /conf-override/extensions/{{ extension.name }}
            {% endif %}{% endfor %}
          {% endfor %}
          {% if spec.imagePullSecrets != null && spec.imagePullSecrets.size() > 0 %}
          imagePullSecrets:
          {% for secret in spec.imagePullSecrets %}
            - name: {{ secret }}
          {% endfor %}
          {% endif %}
          {% if spec.serviceAccountName != null %}
          serviceAccountName: "{{ spec.serviceAccountName }}"
          {% endif %}
          containers:
          - name: "hivemq"
            securityContext:
              privileged: false
              allowPrivilegeEscalation: false
              sysctls:
                - name: net.core.somaxconn
                  value: "32768"
                - name: net.ipv4.ip_local_port_range
                  value: "1024 65535"
                - name: net.ipv4.tcp_fin_timeout
                  value: "90"
                - name: net.ipv4.tcp_tw_recycle
                  value: "1"
                - name: net.ipv4.tcp_tw_reuse
                  value: "1"
                - name: net.core.rmem_default
                  value: "524288"
                - name: net.core.wmem_default
                  value: "524288"
                - name: net.core.rmem_max
                  value: "67108864"
                - name: net.core.wmem_max
                  value: "67108864"
                - name: net.ipv4.tcp_rmem
                  value: "4096 87380 16777216"
                - name: net.ipv4.tcp_wmem
                  value: "4096 65536 16777216"
                - name: fs.file-max
                  value: "5097152"
            env:
            - name: HIVEMQ_DNS_DISCOVERY_ADDRESS
              value: "hivemq-{{ spec.name }}-cluster.{{ spec.namespace }}.svc.cluster.local."
            - name: JAVA_OPTS
              value: "{{ spec.javaOptions }}"
            - name: HIVEMQ_CLUSTER_PORT
              value: {{ util:getPort(spec, "cluster").port }}
            - name: HIVEMQ_MQTT_PORT
              value: {{ util:getPort(spec, "mqtt").port }}
            - name: HIVEMQ_CONTROL_CENTER_PORT
              value: {{ util:getPort(spec, "cc").port }}
            - name: HIVEMQ_REST_API_PORT
              value: {{ util:getPort(spec, "api").port }}
            - name: HIVEMQ_REST_API_ENABLED
              value: {{ util:getPort(spec, "api").port != null }}
            - name: HIVEMQ_CLUSTER_REPLICA_COUNT
              value: "{{ spec.clusterReplicaCount }}"
            - name: HIVEMQ_CLUSTER_OVERLOAD_PROTECTION
              value: "{{ spec.clusterOverloadProtection }}"
            - name: HIVEMQ_MAX_CLIENT_ID_LENGTH
              value: "{{ spec.restrictions.maxClientIdLength }}"
            - name: HIVEMQ_BIND_ADDRESS
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: HIVEMQ_MAX_TOPIC_LENGTH
              value: "{{ spec.restrictions.maxTopicLength }}"
            - name: HIVEMQ_MAX_CONNECTIONS
              value: "{{ spec.restrictions.maxConnections }}"
            - name: HIVEMQ_INCOMING_BANDWIDTH_THROTTLING
              value: "{{ spec.restrictions.incomingBandwidthThrottling }}"
            - name: HIVEMQ_NO_CONNECT_IDLE_TIMEOUT
              value: "{{ spec.restrictions.noConnectIdleTimeout }}"
            - name: HIVEMQ_SESSION_EXPIRY_INTERVAL
              value: "{{ spec.mqtt.sessionExpiryInterval }}"
            - name: HIVEMQ_MAX_PACKET_SIZE
              value: "{{ spec.mqtt.maxPacketSize }}"
            - name: HIVEMQ_SERVER_RECEIVE_MAXIMUM
              value: "{{ spec.mqtt.serverReceiveMaximum }}"
            - name: HIVEMQ_KEEPALIVE_MAX
              value: "{{ spec.mqtt.keepaliveMax }}"
            - name: HIVEMQ_KEEPALIVE_ALLOW_UNLIMITED
              value: "{{ spec.mqtt.keepaliveAllowUnlimited }}"
            - name: HIVEMQ_TOPIC_ALIAS_ENABLED
              value: "{{ spec.mqtt.topicAliasEnabled }}"
            - name: HIVEMQ_TOPIC_ALIAS_MAX_PER_CLIENT
              value: "{{ spec.mqtt.topicAliasMaxPerClient }}"
            - name: HIVEMQ_SUBSCRIPTION_IDENTIFIER_ENABLED
              value: "{{ spec.mqtt.subscriptionIdentifierEnabled }}"
            - name: HIVEMQ_WILDCARD_SUBSCRIPTION_ENABLED
              value: "{{ spec.mqtt.wildcardSubscriptionEnabled }}"
            - name: HIVEMQ_SHARED_SUBSCRIPTION_ENABLED
              value: "{{ spec.mqtt.sharedSubscriptionEnabled }}"
            - name: HIVEMQ_MAX_QOS
              value: "{{ spec.mqtt.maxQos }}"
            - name: HIVEMQ_RETAINED_MESSAGES_ENABLED
              value: "{{ spec.mqtt.retainedMessagesEnabled }}"
            - name: HIVEMQ_QUEUED_MESSAGE_MAX_QUEUE_SIZE
              value: "{{ spec.mqtt.queuedMessageMaxQueueSize }}"
            - name: HIVEMQ_QUEUED_MESSAGE_STRATEGY
              value: "{{ spec.mqtt.queuedMessageStrategy }}"
            - name: HIVEMQ_ALLOW_EMPTY_CLIENT_ID
              value: "{{ spec.security.allowEmptyClientId }}"
            - name: HIVEMQ_PAYLOAD_FORMAT_VALIDATION
              value: "{{ spec.security.payloadFormatValidation }}"
            - name: HIVEMQ_TOPIC_FORMAT_VALIDATION
              value: "{{ spec.security.topicFormatValidation }}"
            - name: HIVEMQ_ALLOW_REQUEST_PROBLEM_INFORMATION
              value: "{{ spec.security.allowRequestProblemInformation }}"
            - name: HIVEMQ_ENABLE_PROMETHEUS
              value: "{{ spec.monitoring.enablePrometheus }}"
            - name: HIVEMQ_CONFIG_OVERRIDE
              value: |
    {{ util:indent(12, spec.configOverride) }}
            - name: HIVEMQ_LISTENER_CONFIGURATION
              value: |
    {{ util:indent(12, spec.listenerConfiguration) }}
            - name: HIVEMQ_REST_API_CONFIGURATION
              value: |
    {{ util:indent(12, spec.restApiConfiguration) }}
            {% for env in spec.env %}
            - name: {{ env.name }}
              value: {{ env.value }}
            {% endfor %}
            image: "{{ util:getTaggedImage(spec) }}"
            ports:{% for portInstance in spec.ports %}
            - containerPort: {{ portInstance.port }}
              name: {{ portInstance.name }}{% endfor %}
            imagePullPolicy: "{{ spec.imagePullPolicy }}"
            resources:
              limits:
                cpu: "{{ util:getCpuLimit(spec) }}"
                memory: "{{ util:getMemoryLimit(spec) }}"
                ephemeral-storage: "{{ util:getStorageLimit(spec) }}"
              requests:
                cpu: "{{ spec.cpu }}"
                memory: "{{ spec.memory }}"
                ephemeral-storage: "{{ spec.ephemeralStorage }}"
            readinessProbe:
              exec:
                command:
                  - /opt/hivemq/bin/readiness_probe.sh
              initialDelaySeconds: 3
              periodSeconds: 5
            livenessProbe:
              tcpSocket:
                port: {{ util:getPort(spec, "mqtt").port }}
              initialDelaySeconds: 15
              periodSeconds: 30
              failureThreshold: 90
            volumeMounts:
              - name: shared-data
                mountPath: /hivemq-data
              - name: conf-override
                mountPath: /conf-override
                readOnly: false
              - name: live-info
                mountPath: /etc/podinfo
              - name: backup
                mountPath: /opt/hivemq/backup
                readOnly: false
              {% for map in spec.configMaps %}
              - name: {{ map.name }}
                mountPath: {{ util:stringReplace(map.path, "/opt/hivemq/", "/conf-override/") }}
              {% endfor %}
              {% for secret in spec.secrets %}
              - name: {{ secret.name }}
                mountPath: {{ util:stringReplace(secret.path, "/opt/hivemq/", "/conf-override/") }}
              {% endfor %}
              {% for extension in spec.extensions %}
              {% if extension.configMap != null %}
              - name: {{ extension.configMap }}
                mountPath: /conf-override/extensions/{{ extension.name }}
              {% endif %}{% endfor %}
          # Wait longer for replication tasks
          terminationGracePeriodSeconds: 3600
          affinity:
    {{ util:indent(8, util:render(spec, spec.affinity)) }}
          volumes:
            - name: shared-data
              emptyDir: {}
            # For overriding configuration after init containers have finished without overwriting the directory
            - name: conf-override
              emptyDir: {}
            - name: backup
              emptyDir: {}
            - name: live-info
              configMap:
                name: hivemq-cluster-{{ spec.name }}-dynamic-state
            {% for map in spec.configMaps %}
            - name: {{ map.name }}
              configMap:
                name: {{ map.name }}
            {% endfor %}
            {% for extension in spec.extensions %}
            {% if extension.configMap != null %}
            - name: {{ extension.configMap }}
              configMap:
                name: {{ extension.configMap }}
            {% endif %}{% endfor %}
            {% for secret in spec.secrets %}
            - name: {{ secret.name }}
              secret:
                secretName: {{ secret.name }}
            {% endfor %}
  cluster-deployment.yaml: |-
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: "{{ spec.name }}"
      namespace: "{{ spec.namespace }}"
      labels:
        app: "hivemq"
        hivemq-cluster: "{{ spec.name }}"
        {% for entry in spec.labels.entrySet() %}
        {{ entry.key }}: "{{entry.value}}"
        {% endfor %}
      ownerReferences:
      - apiVersion: hivemq.com/v1
        kind: HiveMQCluster
        blockOwnerDeletion: true
        name: "{{ spec.name }}"
        uid: "{{ spec.metadata.uid }}"
    spec:
      minReadySeconds: 30
      progressDeadlineSeconds: 10800
      revisionHistoryLimit: 2
      selector:
        matchLabels:
          app: "hivemq"
          hivemq-cluster: "{{ spec.name }}"
      replicas: {{ spec.nodeCount }}
      strategy:
        type: RollingUpdate
        rollingUpdate:
          maxSurge: 1
          maxUnavailable: 0
      template:
        metadata:
          labels:
            app: "hivemq"
            hivemq-cluster: "{{ spec.name }}"
            hivemq.com/node-offline: "false"
        spec:
          initContainers:
          - name: "init-shared"
            resources:
              limits:
                cpu: "{{ util:getCpuLimit(spec) }}"
                memory: "{{ util:getMemoryLimit(spec) }}"
                ephemeral-storage: "{{ util:getStorageLimit(spec) }}"
              requests:
                cpu: "{{ spec.cpu }}"
                memory: "{{ spec.memory }}"
                ephemeral-storage: "{{ spec.ephemeralStorage }}"
            image: "busybox:latest"
            command: ["/bin/sh", "-c"]
            args:
              - |
                mkdir -p /opt/hivemq/bin
                mkdir -p /opt/hivemq/backup
                mkdir -p /opt/hivemq/extensions
                mkdir -p /opt/hivemq/conf
                mkdir -p /opt/hivemq/license
                cp -r /opt/hivemq/* /conf-override/
                cp -r /opt/hivemq/* /hivemq-data/
            volumeMounts:
            - name: shared-data
              mountPath: /hivemq-data
              readOnly: false
            - name: conf-override
              mountPath: /conf-override
              readOnly: false
            - name: live-info
              mountPath: /etc/podinfo
            - name: backup
              mountPath: /conf-override/backup
              readOnly: false
            - name: log
              mountPath: /conf-override/log
              readOnly: false
            - name: audit
              mountPath: /conf-override/audit
              readOnly: false
            - name: heap-dumps
              mountPath: /opt/hivemq/dumps
              readOnly: false
            {% for map in spec.configMaps %}
            {% if map.path != "none" %}
            - name: {{ map.name }}
              mountPath: {{ util:stringReplace(map.path, "/opt/hivemq/", "/conf-override/") }}
            {% endif %}
            {% endfor %}
            {% for extension in spec.extensions %}
            {% if extension.configMap != null %}
            - name: {{ extension.configMap }}
              mountPath: /conf-override/extensions/{{ extension.name }}
            {% endif %}{% endfor %}
          - name: dns-wait
            image: hivemq/init-dns-wait:1.0.0
            resources:
              limits:
                cpu: "{{ util:getCpuLimit(spec) }}"
                memory: "{{ util:getMemoryLimit(spec) }}"
                ephemeral-storage: "{{ util:getStorageLimit(spec) }}"
              requests:
                cpu: "{{ spec.cpu }}"
                memory: "{{ spec.memory }}"
                ephemeral-storage: "{{ spec.ephemeralStorage }}"
            volumeMounts:
              - mountPath: /mnt/misc
                name: dns-wait-config
          {% for initContainer in spec.initialization %}
          - name: {{ initContainer.name }}
            image: {{ initContainer.image }}
            resources:
              limits:
                cpu: "{{ util:getCpuLimit(spec) }}"
                memory: "{{ util:getMemoryLimit(spec) }}"
                ephemeral-storage: "{{ util:getStorageLimit(spec) }}"
              requests:
                cpu: "{{ spec.cpu }}"
                memory: "{{ spec.memory }}"
                ephemeral-storage: "{{ spec.ephemeralStorage }}"
            command: {{ initContainer.command }}
            args: {{ initContainer.args }}
            volumeMounts:
            - name: shared-data
              mountPath: /hivemq-data
              readOnly: false
            - name: conf-override
              mountPath: /conf-override
              readOnly: false
            - name: backup
              mountPath: /conf-override/backup
              readOnly: false
            - name: log
              mountPath: /conf-override/log
              readOnly: false
            - name: audit
              mountPath: /conf-override/audit
              readOnly: false
            {% for map in spec.configMaps %}
            {% if map.path != "none" %}
            - name: {{ map.name }}
              mountPath: {{ util:stringReplace(map.path, "/opt/hivemq/", "/conf-override/") }}
            {% endif %}
            {% endfor %}
            {% for extension in spec.extensions %}
            {% if extension.configMap != null %}
            - name: {{ extension.configMap }}
              mountPath: /conf-override/extensions/{{ extension.name }}
            {% endif %}{% endfor %}
          {% endfor %}
          {% if spec.imagePullSecrets != null && spec.imagePullSecrets.size() > 0 %}
          imagePullSecrets:
          {% for secret in spec.imagePullSecrets %}
            - name: {{ secret }}
          {% endfor %}
          {% endif %}
          {% if spec.serviceAccountName != null %}
          serviceAccountName: "{{ spec.serviceAccountName }}"
          {% endif %}
          securityContext:
            sysctls:
              - name: net.ipv4.ip_local_port_range
                value: "1024 65535"
          containers:
          - name: "hivemq"
            securityContext:
              privileged: false
              allowPrivilegeEscalation: false
            env:
            - name: HIVEMQ_DNS_DISCOVERY_ADDRESS
              value: "hivemq-{{ spec.name }}-cluster.{{ spec.namespace }}.svc.cluster.local."
            - name: JAVA_OPTS
              value: "{{ spec.javaOptions }}"
            - name: HIVEMQ_CLUSTER_PORT
              value: "{{ util:getPort(spec, "cluster").port }}"
            - name: HIVEMQ_MQTT_PORT
              value: "{{ util:getPort(spec, "mqtt").port }}"
            - name: HIVEMQ_CONTROL_CENTER_PORT
              value: "{{ util:getPort(spec, "cc").port }}"
            - name: HIVEMQ_REST_API_PORT
              value: "{{ util:getPort(spec, "api").port }}"
            - name: HIVEMQ_REST_API_ENABLED
              value: "{{ util:getPort(spec, "api").port != null }}"
            - name: HIVEMQ_CLUSTER_REPLICA_COUNT
              value: "{{ spec.clusterReplicaCount }}"
            - name: HIVEMQ_CLUSTER_OVERLOAD_PROTECTION
              value: "{{ spec.clusterOverloadProtection }}"
            - name: HIVEMQ_MAX_CLIENT_ID_LENGTH
              value: "{{ spec.restrictions.maxClientIdLength }}"
            - name: HIVEMQ_BIND_ADDRESS
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: HIVEMQ_MAX_TOPIC_LENGTH
              value: "{{ spec.restrictions.maxTopicLength }}"
            - name: HIVEMQ_MAX_CONNECTIONS
              value: "{{ spec.restrictions.maxConnections }}"
            - name: HIVEMQ_INCOMING_BANDWIDTH_THROTTLING
              value: "{{ spec.restrictions.incomingBandwidthThrottling }}"
            - name: HIVEMQ_NO_CONNECT_IDLE_TIMEOUT
              value: "{{ spec.restrictions.noConnectIdleTimeout }}"
            - name: HIVEMQ_SESSION_EXPIRY_INTERVAL
              value: "{{ spec.mqtt.sessionExpiryInterval }}"
            - name: HIVEMQ_MAX_PACKET_SIZE
              value: "{{ spec.mqtt.maxPacketSize }}"
            - name: HIVEMQ_SERVER_RECEIVE_MAXIMUM
              value: "{{ spec.mqtt.serverReceiveMaximum }}"
            - name: HIVEMQ_KEEPALIVE_MAX
              value: "{{ spec.mqtt.keepaliveMax }}"
            - name: HIVEMQ_KEEPALIVE_ALLOW_UNLIMITED
              value: "{{ spec.mqtt.keepaliveAllowUnlimited }}"
            - name: HIVEMQ_TOPIC_ALIAS_ENABLED
              value: "{{ spec.mqtt.topicAliasEnabled }}"
            - name: HIVEMQ_TOPIC_ALIAS_MAX_PER_CLIENT
              value: "{{ spec.mqtt.topicAliasMaxPerClient }}"
            - name: HIVEMQ_SUBSCRIPTION_IDENTIFIER_ENABLED
              value: "{{ spec.mqtt.subscriptionIdentifierEnabled }}"
            - name: HIVEMQ_WILDCARD_SUBSCRIPTION_ENABLED
              value: "{{ spec.mqtt.wildcardSubscriptionEnabled }}"
            - name: HIVEMQ_SHARED_SUBSCRIPTION_ENABLED
              value: "{{ spec.mqtt.sharedSubscriptionEnabled }}"
            - name: HIVEMQ_MAX_QOS
              value: "{{ spec.mqtt.maxQos }}"
            - name: HIVEMQ_RETAINED_MESSAGES_ENABLED
              value: "{{ spec.mqtt.retainedMessagesEnabled }}"
            - name: HIVEMQ_QUEUED_MESSAGE_MAX_QUEUE_SIZE
              value: "{{ spec.mqtt.queuedMessageMaxQueueSize }}"
            - name: HIVEMQ_QUEUED_MESSAGE_STRATEGY
              value: "{{ spec.mqtt.queuedMessageStrategy }}"
            - name: HIVEMQ_ALLOW_EMPTY_CLIENT_ID
              value: "{{ spec.security.allowEmptyClientId }}"
            - name: HIVEMQ_PAYLOAD_FORMAT_VALIDATION
              value: "{{ spec.security.payloadFormatValidation }}"
            - name: HIVEMQ_TOPIC_FORMAT_VALIDATION
              value: "{{ spec.security.topicFormatValidation }}"
            - name: HIVEMQ_ALLOW_REQUEST_PROBLEM_INFORMATION
              value: "{{ spec.security.allowRequestProblemInformation }}"
            - name: HIVEMQ_ENABLE_PROMETHEUS
              value: "{{ spec.monitoring.enablePrometheus }}"
            - name: HIVEMQ_CONFIG_OVERRIDE
              value: |
    {{ util:indent(12, spec.configOverride) }}
            - name: HIVEMQ_LISTENER_CONFIGURATION
              value: |
                {{ util:indentCustom(12, 0, spec.listenerConfiguration) }}
            - name: HIVEMQ_REST_API_CONFIGURATION
              value: |
                {{ util:indentCustom(12, 0, spec.restApiConfiguration) }}
            - name: HIVEMQ_HEAPDUMP_FOLDER
              value: /opt/hivemq/dumps
            {% for env in spec.env %}
            - name: {{ env.name }}
              value: |
                {{ util:indentCustom(12, 0, env.value) }}
            {% endfor %}
            image: "{{ util:getTaggedImage(spec) }}"
            ports:{% for portInstance in spec.ports %}
            - containerPort: {{ portInstance.port }}
              name: {{ portInstance.name }}{% endfor %}
            imagePullPolicy: "{{ spec.imagePullPolicy }}"
            resources:
              limits:
                cpu: "{{ util:getCpuLimit(spec) }}"
                memory: "{{ util:getMemoryLimit(spec) }}"
                ephemeral-storage: "{{ util:getStorageLimit(spec) }}"
              requests:
                cpu: "{{ spec.cpu }}"
                memory: "{{ spec.memory }}"
                ephemeral-storage: "{{ spec.ephemeralStorage }}"
            readinessProbe:
              exec:
                command:
                  - /opt/hivemq/bin/readiness_probe.sh
              initialDelaySeconds: 3
              periodSeconds: 5
            livenessProbe:
              tcpSocket:
                port: {{ util:getPort(spec, "mqtt").port }}
              initialDelaySeconds: 15
              periodSeconds: 30
              failureThreshold: 240
            volumeMounts:
              - name: shared-data
                mountPath: /hivemq-data
                readOnly: false
              - name: conf-override
                mountPath: /conf-override
                readOnly: false
              - name: live-info
                mountPath: /etc/podinfo
              - name: backup
                mountPath: /opt/hivemq/backup
                readOnly: false
              - name: log
                mountPath: /opt/hivemq/log
                readOnly: false
              - name: audit
                mountPath: /opt/hivemq/audit
                readOnly: false
              - name: heap-dumps
                mountPath: /opt/hivemq/dumps
                readOnly: false
              {% for map in spec.configMaps %}
              {% if map.path != "none" %}
              - name: {{ map.name }}
                mountPath: {{ util:stringReplace(map.path, "/opt/hivemq/", "/conf-override/") }}
              {% endif %}
              {% endfor %}
              {% for secret in spec.secrets %}
              {% if secret.path != "none" %}
              - name: {{ secret.name }}
                mountPath: {{ util:stringReplace(secret.path, "/opt/hivemq/", "/conf-override/") }}
              {% endif %}
              {% endfor %}
              {% for extension in spec.extensions %}
              {% if extension.configMap != null %}
              - name: {{ extension.configMap }}
                mountPath: /conf-override/extensions/{{ extension.name }}
              {% endif %}{% endfor %}
          # Wait longer for replication tasks
          terminationGracePeriodSeconds: 3600
          affinity:
    {{ util:indent(8, util:render(spec, spec.affinity)) }}
          volumes:
            - name: shared-data
              emptyDir: {}
            # For overriding configuration after init containers have finished without overwriting the directory
            - name: conf-override
              emptyDir: {}
            - name: backup
              emptyDir: {}
            - name: audit
              emptyDir: {}
            - name: log
              emptyDir: {}
            - name: heap-dumps
              emptyDir: {}
            - name: live-info
              configMap:
                name: hivemq-cluster-{{ spec.name }}-dynamic-state
            - name: dns-wait-config
              configMap:
                name: hivemq-cluster-{{ spec.name }}-dns-wait-config
            {% for map in spec.configMaps %}
            - name: {{ map.name }}
              configMap:
                name: {{ map.name }}
            {% endfor %}
            {% for extension in spec.extensions %}
            {% if extension.configMap != null %}
            - name: {{ extension.configMap }}
              configMap:
                name: {{ extension.configMap }}
            {% endif %}{% endfor %}
            {% for secret in spec.secrets %}
            - name: {{ secret.name }}
              secret:
                secretName: {{ secret.name }}
            {% endfor %}
  cluster-stateful-set.yaml: |-
    kind: StatefulSet
    apiVersion: apps/v1
    metadata:
      name: "{{ spec.name }}"
      namespace: "{{ spec.namespace }}"
      labels:
        app: "hivemq"
        hivemq-cluster: "{{ spec.name }}"
        {% for entry in spec.labels.entrySet() %}
        {{ entry.key }}: "{{entry.value}}"
        {% endfor %}
      ownerReferences:
      - apiVersion: hivemq.com/v1
        kind: HiveMQCluster
        blockOwnerDeletion: true
        name: "{{ spec.name }}"
        uid: "{{ spec.metadata.uid }}"
    spec:
      serviceName: hivemq-{{ spec.name }}-cluster
      replicas: {{ spec.nodeCount }}
      selector:
        matchLabels:
          app: "hivemq"
          hivemq-cluster: "{{ spec.name }}"
      template:
        metadata:
          labels:
            app: "hivemq"
            hivemq-cluster: "{{ spec.name }}"
            hivemq.com/node-offline: "false"
        spec:
          initContainers:
          - name: "init-shared"
            image: "busybox:latest"
            command: ["/bin/sh", "-c"]
            args:
              - |
                mkdir -p /opt/hivemq/bin
                mkdir -p /opt/hivemq/backup
                mkdir -p /opt/hivemq/extensions
                mkdir -p /opt/hivemq/conf
                mkdir -p /opt/hivemq/license
                cp -r /opt/hivemq/* /hivemq-data/
                cp -r /opt/hivemq/* /conf-override/
            volumeMounts:
            - name: shared-data
              mountPath: /hivemq-data
              readOnly: false
            - name: conf-override
              mountPath: /conf-override
              readOnly: false
            - name: live-info
              mountPath: /etc/podinfo
            - name: backup
              mountPath: /conf-override/backup
              readOnly: false
            - name: log
              mountPath: /conf-override/log
              readOnly: false
            - name: audit
              mountPath: /conf-override/audit
              readOnly: false
            {% for map in spec.configMaps %}
            {% if map.path != "none" %}
            - name: {{ map.name }}
              mountPath: {{ util:stringReplace(map.path, "/opt/hivemq/", "/conf-override/") }}
            {% endif %}
            {% endfor %}
            {% for extension in spec.extensions %}
            {% if extension.configMap != null %}
            - name: {{ extension.configMap }}
              mountPath: /conf-override/extensions/{{ extension.name }}
            {% endif %}{% endfor %}
          - name: dns-wait
            image: hivemq/init-dns-wait:1.0.0
            volumeMounts:
              - mountPath: /mnt/misc
                name: dns-wait-config
          {% for initContainer in spec.initialization %}
          - name: {{ initContainer.name }}
            image: {{ initContainer.image }}
            command: {{ initContainer.command }}
            args: {{ initContainer.args }}
            volumeMounts:
            - name: shared-data
              mountPath: /hivemq-data
              readOnly: false
            - name: conf-override
              mountPath: /conf-override
              readOnly: false
            - name: live-info
              mountPath: /etc/podinfo
            - name: backup
              mountPath: /conf-override/backup
              readOnly: false
            - name: log
              mountPath: /conf-override/log
              readOnly: false
            - name: audit
              mountPath: /conf-override/audit
              readOnly: false
            {% for map in spec.configMaps %}
            {% if map.path != "none" %}
            - name: {{ map.name }}
              mountPath: {{ util:stringReplace(map.path, "/opt/hivemq/", "/conf-override/") }}
            {% endif %}
            {% endfor %}
            {% for extension in spec.extensions %}
            {% if extension.configMap != null %}
            - name: {{ extension.configMap }}
              mountPath: /conf-override/extensions/{{ extension.name }}
            {% endif %}{% endfor %}
          {% endfor %}
          {% if spec.imagePullSecrets != null && spec.imagePullSecrets.size() > 0 %}
          imagePullSecrets:
          {% for secret in spec.imagePullSecrets %}
          - name: {{ secret }}
          {% endfor %}
          {% endif %}
          {% if spec.serviceAccountName != null %}
          serviceAccountName: "{{ spec.serviceAccountName }}"
          {% endif %}
          securityContext:
            sysctls:
              - name: net.ipv4.ip_local_port_range
                value: "1024 65535"
          containers:
            - name: "hivemq"
              securityContext:
                privileged: false
                allowPrivilegeEscalation: false
              env:
                - name: HIVEMQ_DNS_DISCOVERY_ADDRESS
                  value: "hivemq-{{ spec.name }}-cluster.{{ spec.namespace }}.svc.cluster.local."
                - name: JAVA_OPTS
                  value: "{{ spec.javaOptions }}"
                - name: HIVEMQ_CLUSTER_PORT
                  value: {{ util:getPort(spec, "cluster").port }}
                - name: HIVEMQ_MQTT_PORT
                  value: {{ util:getPort(spec, "mqtt").port }}
                - name: HIVEMQ_CONTROL_CENTER_PORT
                  value: {{ util:getPort(spec, "cc").port }}
                - name: HIVEMQ_REST_API_PORT
                  value: {{ util:getPort(spec, "api").port }}
                - name: HIVEMQ_REST_API_ENABLED
                  value: {{ util:getPort(spec, "api").port != null }}
                - name: HIVEMQ_CLUSTER_REPLICA_COUNT
                  value: "{{ spec.clusterReplicaCount }}"
                - name: HIVEMQ_CLUSTER_OVERLOAD_PROTECTION
                  value: "{{ spec.clusterOverloadProtection }}"
                - name: HIVEMQ_MAX_CLIENT_ID_LENGTH
                  value: "{{ spec.restrictions.maxClientIdLength }}"
                - name: HIVEMQ_BIND_ADDRESS
                  valueFrom:
                    fieldRef:
                      fieldPath: status.podIP
                - name: HIVEMQ_MAX_TOPIC_LENGTH
                  value: "{{ spec.restrictions.maxTopicLength }}"
                - name: HIVEMQ_MAX_CONNECTIONS
                  value: "{{ spec.restrictions.maxConnections }}"
                - name: HIVEMQ_INCOMING_BANDWIDTH_THROTTLING
                  value: "{{ spec.restrictions.incomingBandwidthThrottling }}"
                - name: HIVEMQ_NO_CONNECT_IDLE_TIMEOUT
                  value: "{{ spec.restrictions.noConnectIdleTimeout }}"
                - name: HIVEMQ_SESSION_EXPIRY_INTERVAL
                  value: "{{ spec.mqtt.sessionExpiryInterval }}"
                - name: HIVEMQ_MAX_PACKET_SIZE
                  value: "{{ spec.mqtt.maxPacketSize }}"
                - name: HIVEMQ_SERVER_RECEIVE_MAXIMUM
                  value: "{{ spec.mqtt.serverReceiveMaximum }}"
                - name: HIVEMQ_KEEPALIVE_MAX
                  value: "{{ spec.mqtt.keepaliveMax }}"
                - name: HIVEMQ_KEEPALIVE_ALLOW_UNLIMITED
                  value: "{{ spec.mqtt.keepaliveAllowUnlimited }}"
                - name: HIVEMQ_TOPIC_ALIAS_ENABLED
                  value: "{{ spec.mqtt.topicAliasEnabled }}"
                - name: HIVEMQ_TOPIC_ALIAS_MAX_PER_CLIENT
                  value: "{{ spec.mqtt.topicAliasMaxPerClient }}"
                - name: HIVEMQ_SUBSCRIPTION_IDENTIFIER_ENABLED
                  value: "{{ spec.mqtt.subscriptionIdentifierEnabled }}"
                - name: HIVEMQ_WILDCARD_SUBSCRIPTION_ENABLED
                  value: "{{ spec.mqtt.wildcardSubscriptionEnabled }}"
                - name: HIVEMQ_SHARED_SUBSCRIPTION_ENABLED
                  value: "{{ spec.mqtt.sharedSubscriptionEnabled }}"
                - name: HIVEMQ_MAX_QOS
                  value: "{{ spec.mqtt.maxQos }}"
                - name: HIVEMQ_RETAINED_MESSAGES_ENABLED
                  value: "{{ spec.mqtt.retainedMessagesEnabled }}"
                - name: HIVEMQ_QUEUED_MESSAGE_MAX_QUEUE_SIZE
                  value: "{{ spec.mqtt.queuedMessageMaxQueueSize }}"
                - name: HIVEMQ_QUEUED_MESSAGE_STRATEGY
                  value: "{{ spec.mqtt.queuedMessageStrategy }}"
                - name: HIVEMQ_ALLOW_EMPTY_CLIENT_ID
                  value: "{{ spec.security.allowEmptyClientId }}"
                - name: HIVEMQ_PAYLOAD_FORMAT_VALIDATION
                  value: "{{ spec.security.payloadFormatValidation }}"
                - name: HIVEMQ_TOPIC_FORMAT_VALIDATION
                  value: "{{ spec.security.topicFormatValidation }}"
                - name: HIVEMQ_ALLOW_REQUEST_PROBLEM_INFORMATION
                  value: "{{ spec.security.allowRequestProblemInformation }}"
                - name: HIVEMQ_ENABLE_PROMETHEUS
                  value: "{{ spec.monitoring.enablePrometheus }}"
  
                - name: HIVEMQ_CONFIG_OVERRIDE
                  value: |
    {{ util:indent(15, spec.configOverride) }}
                - name: HIVEMQ_LISTENER_CONFIGURATION
                  value: |
    {{ util:indent(15, spec.listenerConfiguration) }}
                - name: HIVEMQ_REST_API_CONFIGURATION
                  value: |
    {{ util:indent(15, spec.restApiConfiguration) }}
                  {% for env in spec.env %}
                - name: {{ env.name }}
                  value: |
                    {{ util:indentCustom(15, 0, env.value) }}
                  {% endfor %}
              image: "{{ util:getTaggedImage(spec) }}"
              ports:{% for portInstance in spec.ports %}
                - containerPort: {{ portInstance.port }}
                  name: {{ portInstance.name }}{% endfor %}
              imagePullPolicy: "{{ spec.imagePullPolicy }}"
              resources:
                limits:
                  cpu: "{{ util:getCpuLimit(spec) }}"
                  memory: "{{ util:getMemoryLimit(spec) }}"
                  ephemeral-storage: "{{ util:getStorageLimit(spec) }}"
                requests:
                  cpu: "{{ spec.cpu }}"
                  memory: "{{ spec.memory }}"
                  ephemeral-storage: "{{ spec.ephemeralStorage }}"
              readinessProbe:
                exec:
                  command:
                    - /opt/hivemq/bin/readiness_probe.sh
                initialDelaySeconds: 3
                periodSeconds: 5
              livenessProbe:
                tcpSocket:
                  port: {{ util:getPort(spec, "mqtt").port }}
                initialDelaySeconds: 15
                periodSeconds: 30
                failureThreshold: 240
              volumeMounts:
              - name: shared-data
                mountPath: /hivemq-data
                readOnly: false
              - name: conf-override
                mountPath: /conf-override
                readOnly: false
              - name: live-info
                mountPath: /etc/podinfo
              - name: backup
                mountPath: /opt/hivemq/backup
                readOnly: false
              - name: log
                mountPath: /opt/hivemq/log
                readOnly: false
              - name: audit
                mountPath: /opt/hivemq/audit
                readOnly: false
                {% for map in spec.configMaps %}
                - name: {{ map.name }}
                  mountPath: {{ util:stringReplace(map.path, "/opt/hivemq/", "/conf-override/") }}
                {% endfor %}
                {% for extension in spec.extensions %}
                {% if extension.configMap != null %}
                - name: {{ extension.configMap }}
                  mountPath: /conf-override/extensions/{{ extension.name }}
                {% endif %}{% endfor %}
                {% for secret in spec.secrets %}
                {% if map.path != "none" %}
                - name: {{ secret.name }}
                  mountPath: {{ util:stringReplace(secret.path, "/opt/hivemq/", "/conf-override/") }}
                {% endif %}
                {% endfor %}
          # Wait longer for replication tasks
          terminationGracePeriodSeconds: 3600
          volumes:
            - name: shared-data
              emptyDir: {}
            # For overriding configuration after init containers have finished without overwriting the directory
            - name: conf-override
              emptyDir: {}
            - name: backup
              emptyDir: {}
            - name: log
              emptyDir: {}
            - name: audit
              emptyDir: { }
            - name: live-info
              configMap:
                name: hivemq-cluster-{{ spec.name }}-dynamic-state
            - name: dns-wait-config
              configMap:
                name: hivemq-cluster-{{ spec.name }}-dns-wait-config
            {% for map in spec.configMaps %}
            - name: {{ map.name }}
              configMap:
                name: {{ map.name }}
            {% endfor %}
            {% for extension in spec.extensions %}
            {% if extension.configMap != null %}
            - name: {{ extension.configMap }}
              configMap:
                name: {{ extension.configMap }}
            {% endif %}{% endfor %}
            {% for secret in spec.secrets %}
            - name: {{ secret.name }}
              secret:
                secretName: {{ secret.name }}
            {% endfor %}
  service-monitor.yaml: |
    apiVersion: monitoring.coreos.com/v1
    kind: ServiceMonitor
    metadata:
      labels:
        hivemq-cluster: {{ spec.name }}
        {% if spec.metadata.labels.containsKey("app.kubernetes.io/instance") %}
        release: {{ spec.metadata.labels.get("app.kubernetes.io/instance") }}
        {% endif %}
      name: {{ spec.name }}
      ownerReferences:
      - apiVersion: hivemq.com/v1
        kind: HiveMQCluster
        blockOwnerDeletion: true
        name: "{{ spec.name }}"
        uid: "{{ spec.metadata.uid }}"
    spec:
      endpoints:
        - port: metrics
      jobLabel: hivemq-cluster
      selector:
        matchLabels:
          hivemq-cluster: {{ spec.name }}
kind: ConfigMap
metadata:
  name: "hivemq-operator-templates"
  namespace: hivemq
