---
apiVersion: v1
kind: Namespace
metadata:
  name: midrandbooks-uat
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: midrandbooks-config
  namespace: midrandbooks-uat
data:
  ASPNETCORE_ENVIRONMENT: "Development"  
  ASPNETCORE_URLS: "http://0.0.0.0:8443"
  Monitoring__Address: "http://aspire-dashboard-service.aspire.svc.cluster.local:18889"
  Monitoring__ServiceName: "MidrandBooks.Uat"
  HasherSettings__MinHashLength: "11"
  BookshopS3Settings__ServiceUrl: "http://garage.garage.svc.cluster.local:3900"
  BookshopS3Settings__Region: "garage"
  BookshopS3Settings__BucketName: "bookshop"
  BookshopS3Settings__CdnBaseUrl: "https://bookshop.cdn.khongisa.co.za"
  PayfastSettings__CheckoutUrl: "https://sandbox.payfast.co.za/eng/process"
  PayfastSettings__ValidHosts__0: "www.payfast.co.za"
  PayfastSettings__ValidHosts__1: "sandbox.payfast.co.za"
  PayfastSettings__ValidHosts__2: "ips.payfast.co.za"
  PayfastSettings__ValidHosts__3: "api.payfast.co.za"
  PayfastSettings__ValidHosts__4: "payment.payfast.io"
  LiteCharmsSettings__Authority: "https://sts.security.khongisa.co.za"
  LiteCharmsSettings__Audience: "midrandbooks-api"
  LiteCharmsClientSettings__Authority: "https://sts.security.khongisa.co.za"
  LiteCharmsClientSettings__GrantType: "client_credentials"
  LiteCharmsClientSettings__Scope: "midrandbooks-api"
---
apiVersion: v1
kind: Secret
metadata:
  name: midrandbooks-secrets
  namespace: midrandbooks-uat
type: Opaque
data:  
  connection-string: SG9zdD0xOTIuMTY4LjEuMTcwO0RhdGFiYXNlPW1pZHJhbmRzaG9wLWRldjtVc2VybmFtZT1taWRyYW5kc2hvcC1kZXYtdXNlcjtQYXNzd29yZD1hUFh5a0tnM3RTOWNtRDtQZXJzaXN0IFNlY3VyaXR5IEluZm89VHJ1ZQ==
  dataprotection-connection-string: SG9zdD0xOTIuMTY4LjEuMTcwO0RhdGFiYXNlPW1pZHJhbmRzaG9wLWRldjtVc2VybmFtZT1taWRyYW5kc2hvcC1kZXYtdXNlcjtQYXNzd29yZD1hUFh5a0tnM3RTOWNtRDtQZXJzaXN0IFNlY3VyaXR5IEluZm89VHJ1ZQ==
  connection-string-quartz: SG9zdD0xOTIuMTY4LjEuMTcwO0RhdGFiYXNlPXNjaGVkdWxlci1kZXY7VXNlcm5hbWU9c2NoZWR1bGVyLWRldi11c2VyO1Bhc3N3b3JkPWtWVm1vV0tKM3h6Z1FYO1BlcnNpc3QgU2VjdXJpdHkgSW5mbz1UcnVl
  aspire-apikey: bWMzRzYzSzJqNVpPRXNpMEFqTW9qTFRYbTFLRVpGY3R6SUlqU3dEaVRHdXQ4cUdTa1B1V3d4R1AxUmJzY0pVbw==
  hasher-salt: VEdsbmFIUWdRMmhoY20xekxDQk5hV1J5WVc1a1FtOXZhM01nYldGclpTQnNiM1J6SUc5bUlHMXZibVY1SUdGdVpDQmhjbVVnWVNCemRXTmpaWE56Wm5Wc0lIWnBjbUZzSUhOMGIzSjVJR2x1SUZOdmRYUm9JRUZtY21sallRPT0=  
  bookshop-s3-accesskey: R0s1MTRkMmNlOGRjNjkyMzdhMDVjMDFlZWY=
  bookshop-s3-secretkey: ZWFhZmVkYTFhZWQ0MDllY2ZlNjA3MTRlY2RhNTQ5YjgyYmRmNWEzZGFmOWYxOGRkNjFmNjZiNDk3M2E2NDgyZQ==
  litecharms-clientid: bWlkcmFuZGJvb2tzLXVhdA==
  litecharms-clientsecret: c2VjcmV0Xzc3OGJkODM3NWFjNGE3Mzg2N2QxZDdhNjcwODJlZTJjNGU4NmUwODYwYmI0Y2ZlZWI5NDExOTQ5OTk2ZThhOGU=
  payfast-passphrase: OUdBSVIwdFdwaFgwcU8=
  payfast-merchantid: MTAwNDkzMDc=
  payfast-merchantkey: anU2bmF2bjBqY2JmMA==
  litecharms-client-clientid: bWlkcmFuZGJvb2tzLWFwaS1zY2FsZXItdWF0
  litecharms-client-clientsecret: c2VjcmV0XzBhOGRjMWY5OTA2MTU5MGE1MmIxMjcyZGIzYTE4NzFkMjc2MWM3OWZiZDA1OGIyYTk2ODkxMTAyOWU0YjIwOGE=
  dataprotection-cert: [encoded data, 4792 characters]
  dataprotection-password: OWlIUSMmcl41eWZYRXc=
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: midrandbooks-pvc
  namespace: midrandbooks-uat
spec:
  accessModes: ["ReadWriteMany"]
  storageClassName: nfs-storage
  resources:
    requests:
      storage: 2Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: midrandbooks
  namespace: midrandbooks-uat
spec:
  replicas: 1
  selector:
    matchLabels:
      app: midrandbooks
  template:
    metadata:
      labels:
        app: midrandbooks
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: node-role.kubernetes.io/control-plane
                    operator: DoesNotExist
      containers:
        - name: midrandbooks
          image: nexus.khongisa.co.za/midrandbooks:latest
          imagePullPolicy: Always
          resources:
            limits:
              memory: "512Mi"
              cpu: "500m"
            requests:
              memory: "256Mi"
              cpu: "100m"
          ports:
            - containerPort: 8443
          envFrom:
            - configMapRef:
                name: midrandbooks-config
          env:
            - name: DataProtection__Certificate
              valueFrom:
                secretKeyRef:
                  name: midrandbooks-secrets
                  key: dataprotection-cert
            - name: DataProtection__Password
              valueFrom:
                secretKeyRef:
                  name: midrandbooks-secrets
                  key: dataprotection-password
            - name: LiteCharmsSettings__ClientId
              valueFrom:
                secretKeyRef:
                  name: midrandbooks-secrets
                  key: litecharms-clientid
            - name: LiteCharmsSettings__ClientSecret
              valueFrom:
                secretKeyRef:
                  name: midrandbooks-secrets
                  key: litecharms-clientsecret
            - name: BookshopS3Settings__AccessKey
              valueFrom:
                secretKeyRef:
                  name: midrandbooks-secrets
                  key: bookshop-s3-accesskey
            - name: BookshopS3Settings__SecretKey
              valueFrom:
                secretKeyRef:
                  name: midrandbooks-secrets
                  key: bookshop-s3-secretkey
            - name: HasherSettings__Salt
              valueFrom:
                secretKeyRef:
                  name: midrandbooks-secrets
                  key: hasher-salt
            - name: PayfastSettings__Passphrase
              valueFrom:
                secretKeyRef:
                  name: midrandbooks-secrets
                  key: payfast-passphrase
            - name: PayfastSettings__MerchantId
              valueFrom:
                secretKeyRef:
                  name: midrandbooks-secrets
                  key: payfast-merchantid
            - name: PayfastSettings__MerchantKey
              valueFrom:
                secretKeyRef:
                  name: midrandbooks-secrets
                  key: payfast-merchantkey
            - name: LiteCharmsClientSettings__ClientId
              valueFrom:
                secretKeyRef:
                  name: midrandbooks-secrets
                  key: litecharms-client-clientid
            - name: LiteCharmsClientSettings__ClientSecret
              valueFrom:
                secretKeyRef:
                  name: midrandbooks-secrets
                  key: litecharms-client-clientsecret
            - name: ConnectionStrings__PostgresScheduler
              valueFrom:
                secretKeyRef:
                  name: midrandbooks-secrets
                  key: connection-string-quartz
            - name: ConnectionStrings__PostgresMidrandBooks
              valueFrom:
                secretKeyRef:
                  name: midrandbooks-secrets
                  key: connection-string
            - name: ConnectionStrings__PostgresDataProtection
              valueFrom:
                secretKeyRef:
                  name: midrandbooks-secrets
                  key: dataprotection-connection-string
            - name: Monitoring__ApiKey
              valueFrom:
                secretKeyRef:
                  name: midrandbooks-secrets
                  key: aspire-apikey
          volumeMounts:
            - name: data
              mountPath: /app/wwwroot/content
              subPath: bookshop-content
          livenessProbe:
            httpGet:
              path: /health
              port: 8443
              scheme: HTTP
            initialDelaySeconds: 5
            periodSeconds: 10
          readinessProbe:
            httpGet:
              path: /health
              port: 8443
              scheme: HTTP
            initialDelaySeconds: 3
            periodSeconds: 5
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: midrandbooks-pvc        
---
apiVersion: v1
kind: Service
metadata:
  name: midrandbooks-service
  namespace: midrandbooks-uat
spec:
  ports:
    - name: https
      port: 443
      targetPort: 8443
  selector:
    app: midrandbooks
---
apiVersion: traefik.io/v1alpha1
kind: ServersTransport
metadata:
  name: midrandbooks-bypass-backend-validation
  namespace: midrandbooks-uat
spec:
  insecureSkipVerify: true
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
  name: midrandbooks-web-secure
  namespace: midrandbooks-uat
spec:
  entryPoints:
    - websecure
  routes:
    - match: Host(`uat.midrandbooks.co.za`)
      kind: Rule
      services:
        - name: midrandbooks-service
          port: 443
          sticky:
            cookie:
              name: "lp-sticky-session"
              httpOnly: true
              secure: true
          scheme: http
          serversTransport: midrandbooks-bypass-backend-validation
  tls: {}
