---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Release.Name }}-uncloud
spec:
  selector:
    matchLabels:
      app: {{ .Release.Name }}-uncloud
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: {{ .Release.Name }}-uncloud
        use-as-service: {{ .Release.Name }}
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/nginxconf.yaml") . | sha256sum }}
    spec:
      containers:
        - name: uncloud
          image: harbor.ungleich.svc.p10.k8s.ooo/ungleich-public/uncloud:{{ .Chart.AppVersion }}
          ports:
            - containerPort: 3000
          env:
            - name: UNCLOUD__database__HOST
              value: {{ .Release.Name }}-postgres
            - name: UNCLOUD__database__NAME
              valueFrom:
                secretKeyRef:
                  name: {{ .Release.Name }}-postgres-config
                  key: POSTGRES_DB
            - name: UNCLOUD__database__USER
              valueFrom:
                secretKeyRef:
                  name: {{ .Release.Name }}-postgres-config
                  key: POSTGRES_USER
            - name: UNCLOUD__database__PASSWD
              valueFrom:
                secretKeyRef:
                  name: {{ .Release.Name }}-postgres-config
                  key: POSTGRES_PASSWORD
          volumeMounts:
            - name: data
              mountPath: "/data"
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: {{ .Release.Name }}-data
---
apiVersion: v1
kind: Service
metadata:
  name: {{ .Release.Name }}
  labels:
    app: {{ .Release.Name }}
spec:
  type: ClusterIP
  ports:
   - port: 8000
     name: django
  selector:
   use-as-service: {{ .Release.Name }}
---
apiVersion: v1
kind: Secret
metadata:
  name: {{ .Release.Name }}-postgres-config
  annotations:
    secret-generator.v1.mittwald.de/autogenerate: POSTGRES_PASSWORD
    hosting: {{ .Release.Name }}
stringData:
  POSTGRES_USER: "uncloud"
  POSTGRES_DB: "uncloud"
