apiVersion: batch/v1
kind: Job
metadata:
  name: ${FQDN}-install
  namespace: ${DOMAIN}
spec:
  template:
    spec:
      containers:
      - command:
        - /install.sh
        env:
        - name: VERSION
          value: ${NC_VERSION}
        - name: OBJECTSTORE_S3_KEY 
          valueFrom:
            secretKeyRef:
              key: AWS_ACCESS_KEY_ID 
              name: ${FQDN}-s3
        - name: OBJECTSTORE_S3_SECRET 
          valueFrom:
            secretKeyRef:
              key: AWS_SECRET_ACCESS_KEY
              name: ${FQDN}-s3
        - name: MAIL_FROM_ADDRESS 
          valueFrom:
            secretKeyRef:
              key: mail_from_address
              name: ${DOMAIN}-smtp
        - name: SMTP_PASSWORD
          valueFrom:
            secretKeyRef:
              key: password 
              name: ${DOMAIN}-smtp
        - name: SMTP_NAME 
          valueFrom:
            secretKeyRef:
              key: username
              name: ${DOMAIN}-smtp
        - name: DB_PASSWORD 
          valueFrom:
            secretKeyRef:
              key: password 
              name: nextcloud.pg-${DOMAIN}.credentials
        - name: SAML_CERT
          valueFrom:
            secretKeyRef:
              key: tls.crt
              name: ${FQDN}-saml
        - name: SAML_KEY
          valueFrom:
            secretKeyRef:
              key: tls.key
              name: ${FQDN}-saml
        - name: SAML_IDP_CERT
          valueFrom:
            secretKeyRef:
              key: tls.crt
              name: ${DOMAIN}-realm
        envFrom:
        - secretRef:
            name: ${FQDN}-app
        - secretRef:
            name: ${FQDN}-oo
        image: libresh/nextcloud:${NC_IMAGE_TAG}
        imagePullPolicy: IfNotPresent
        name: install-nuage
        volumeMounts:
        - name: realm
          mountPath: "/etc/tls/idp"
          readOnly: true
        - name: saml
          mountPath: "/etc/tls/saml"
          readOnly: true
      volumes:
      - name: saml
        secret:
          secretName: ${FQDN}-saml
      - name: realm
        secret:
          secretName: ${DOMAIN}-realm
      restartPolicy: Never
      securityContext:
        fsGroup: 82
        runAsGroup: 82
        runAsUser: 82
