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