apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: suitecrm-db-pvc
  namespace: hf-suitecrm
  annotations:
    argocd.argoproj.io/sync-wave: "1"
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: longhorn
  resources:
    requests:
      storage: 10Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: suitecrm-state-pvc
  namespace: hf-suitecrm
  annotations:
    argocd.argoproj.io/sync-wave: "1"
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: longhorn
  resources:
    requests:
      storage: 10Gi
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: suitecrm-db
  namespace: hf-suitecrm
  labels:
    app: suitecrm-db
  annotations:
    argocd.argoproj.io/sync-wave: "3"
spec:
  serviceName: suitecrm-db
  replicas: 1
  selector:
    matchLabels:
      app: suitecrm-db
  template:
    metadata:
      labels:
        app: suitecrm-db
    spec:
      containers:
        - name: mariadb
          image: docker.io/library/mariadb:10.11
          args:
            - --character-set-server=utf8mb4
            - --collation-server=utf8mb4_unicode_ci
          env:
            - name: MARIADB_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: suitecrm-secret
                  key: MARIADB_ROOT_PASSWORD
            - name: MARIADB_DATABASE
              valueFrom:
                secretKeyRef:
                  name: suitecrm-secret
                  key: MARIADB_DATABASE
            - name: MARIADB_USER
              valueFrom:
                secretKeyRef:
                  name: suitecrm-secret
                  key: MARIADB_USER
            - name: MARIADB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: suitecrm-secret
                  key: MARIADB_PASSWORD
          ports:
            - containerPort: 3306
              name: mysql
          readinessProbe:
            tcpSocket:
              port: mysql
            initialDelaySeconds: 10
            periodSeconds: 10
          volumeMounts:
            - name: suitecrm-db-storage
              mountPath: /var/lib/mysql
      volumes:
        - name: suitecrm-db-storage
          persistentVolumeClaim:
            claimName: suitecrm-db-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: suitecrm-db
  namespace: hf-suitecrm
spec:
  selector:
    app: suitecrm-db
  ports:
    - name: mysql
      protocol: TCP
      port: 3306
      targetPort: mysql
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: suitecrm
  namespace: hf-suitecrm
  labels:
    app: suitecrm
  annotations:
    argocd.argoproj.io/sync-wave: "4"
spec:
  replicas: 1
  selector:
    matchLabels:
      app: suitecrm
  template:
    metadata:
      labels:
        app: suitecrm
    spec:
      containers:
        - name: suitecrm
          image: docker.io/guerchele/suitecrm:8.10.1
          env:
            - name: DB_HOST
              valueFrom:
                secretKeyRef:
                  name: suitecrm-secret
                  key: DB_HOST
            - name: DB_PORT
              valueFrom:
                secretKeyRef:
                  name: suitecrm-secret
                  key: DB_PORT
            - name: DB_NAME
              valueFrom:
                secretKeyRef:
                  name: suitecrm-secret
                  key: DB_NAME
            - name: DB_USER
              valueFrom:
                secretKeyRef:
                  name: suitecrm-secret
                  key: DB_USER
            - name: DB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: suitecrm-secret
                  key: DB_PASSWORD
            - name: SITE_URL
              valueFrom:
                secretKeyRef:
                  name: suitecrm-secret
                  key: SITE_URL
            - name: SUITECRM_AUTO_INSTALL
              value: "1"
            - name: SUITECRM_ADMIN_USER
              valueFrom:
                secretKeyRef:
                  name: suitecrm-secret
                  key: SUITECRM_ADMIN_USER
            - name: SUITECRM_ADMIN_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: suitecrm-secret
                  key: SUITECRM_ADMIN_PASSWORD
            - name: SUITECRM_DEMO_DATA
              value: "no"
            - name: SUITECRM_IGNORE_SYSTEM_CHECK_WARNINGS
              value: "1"
          ports:
            - containerPort: 80
              name: http
          readinessProbe:
            httpGet:
              path: /
              port: http
            initialDelaySeconds: 60
            periodSeconds: 15
          volumeMounts:
            - name: suitecrm-state
              mountPath: /var/lib/suitecrm
      volumes:
        - name: suitecrm-state
          persistentVolumeClaim:
            claimName: suitecrm-state-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: suitecrm
  namespace: hf-suitecrm
spec:
  selector:
    app: suitecrm
  ports:
    - name: http
      protocol: TCP
      port: 80
      targetPort: http
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: suitecrm-ingress
  namespace: hf-suitecrm
  annotations:
    argocd.argoproj.io/sync-wave: "5"
spec:
  ingressClassName: traefik
  rules:
    - host: suitecrm.heckenfels.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: suitecrm
                port:
                  number: 80
