apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: nextcloud
    app.kubernetes.io/part-of: nextcloud
  name: nextcloud
  namespace: nextcloud
spec:
  # During installation and upgrade of nextcloud this MUST be set to `1`
  # If set to something else than `1` during installation or upgrade, you may run into issues.
  replicas: 1
  revisionHistoryLimit: 2
  selector:
    matchLabels:
      app.kubernetes.io/name: nextcloud
      app.kubernetes.io/part-of: nextcloud
  template:
    metadata:
      name: nextcloud
      annotations:
        backup.velero.io/backup-volumes: nextcloud-data
      labels:
        app.kubernetes.io/name: nextcloud
        app.kubernetes.io/part-of: nextcloud
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - topologyKey: "kubernetes.io/hostname"
            labelSelector:
              matchExpressions:
              - key: app.kubernetes.io/name
                operator: In
                values:
                - nextcloud
              - key: app.kubernetes.io/part-of
                operator: In
                values:
                - nextcloud
      volumes:
      - name: nextcloud-data
        persistentVolumeClaim:
          claimName: nextcloud-cephfs-pvc
      - name: php-configmap-volume
        configMap:
          name: nextcloud-php-configmap
          items:
          - key: custom-php.ini
            path: custom-php.ini
      containers:
      - image: nextcloud:production-apache
        imagePullPolicy: Always
        name: nextcloud
        env:
        - name: POSTGRES_HOST
          value: nextcloud-db-cluster
        - name: POSTGRES_DB
          value: nextcloud
        - name: POSTGRES_USER
          valueFrom:
            secretKeyRef:
              name: nextcloud.nextcloud-db-cluster.credentials
              key: username
        - name: POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              name: nextcloud.nextcloud-db-cluster.credentials
              key: password
        - name: NEXTCLOUD_ADMIN_USER
          valueFrom:
            secretKeyRef:
              name: nextcloud.admin-user.credentials
              key: nextcloud-admin-username
        - name: NEXTCLOUD_ADMIN_PASSWORD
          valueFrom:
            secretKeyRef:
              name: nextcloud.admin-user.credentials
              key: nextcloud-admin-password
        - name: NEXTCLOUD_TRUSTED_DOMAINS
          value: "crownlabs.polito.it/cloud"
        - name: REDIS_HOST
          value: redis-nextcloud
        ports:
        - containerPort: 80
          name: http
        # Only uncomment after the database installation has completed
        #      livenessProbe:
        #        httpGet:
        #          path: /status.php
        #          port: http
        #          httpHeaders:
        #            - name: Host
        #              value: "crownlabs.polito.it/cloud"
        #        initialDelaySeconds: 10
        #        periodSeconds: 10
        #        timeoutSeconds: 5
        #      readinessProbe:
        #        httpGet:
        #          path: /status.php
        #          port: http
        #          httpHeaders:
        #            - name: Host
        #              value: "crownlabs.polito.it/cloud"
        #        initialDelaySeconds: 10
        #        periodSeconds: 10
        #        timeoutSeconds: 5

        volumeMounts:
        - name: nextcloud-data
          mountPath: /var/www/html
        - name: php-configmap-volume
          mountPath: /usr/local/etc/php/conf.d/custom-php.ini
          subPath: custom-php.ini
