apiVersion: v1
kind: Secret
metadata:
  name: klarna-api-credentials
data:
  username: ZjQzZDY3YjEtNzA2Yy00NTk2LTliNTgtYjg1YjU2NDEwZTUw
  password: a2xhcm5hX3Rlc3RfYXBpX0trUWhWVE5yYVZsV2FsTnhTRVp3Y1ZSSFF5UkVNRmxyY25Kd1AxSndQMGdzWmpRelpEWTNZakV0TnpBMll5MDBOVGsyTFRsaU5UZ3RZamcxWWpVMk5ERXdaVFV3TERFc2JUUkNjRFpWU1RsTllsSk1aMlEyVEc4MmRVODNZMkozUlRaaFdEZDViV3AwYkhGV1JqTjVNQzlaYXow
type: Opaque
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: cart-backoffice
    arch: amd64
  name: cart-backoffice-x86
spec:
  replicas: 1
  selector:
    matchLabels:
      app: cart-backoffice
      arch: amd64
  template:
    metadata:
      labels:
        app: cart-backoffice
        arch: amd64
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: kubernetes.io/arch
                    operator: NotIn
                    values:
                      - arm64
      volumes:
        - name: data
          nfs:
            path: /i-data/7a8af061/nfs/cart-actor
            server: 10.10.1.10
      imagePullSecrets:
        - name: regcred
      serviceAccountName: default
      containers:
        - image: registry.knatofs.se/go-cart-actor-amd64:latest
          name: cart-actor-amd64
          imagePullPolicy: Always
          command: ["/go-cart-backoffice"]
          lifecycle:
            preStop:
              exec:
                command: ["sleep", "15"]
          ports:
            - containerPort: 8080
              name: web
          livenessProbe:
            httpGet:
              path: /livez
              port: web
            failureThreshold: 1
            periodSeconds: 30
          readinessProbe:
            httpGet:
              path: /readyz
              port: web
            failureThreshold: 2
            initialDelaySeconds: 2
            periodSeconds: 30
          volumeMounts:
            - mountPath: "/data"
              name: data
          resources:
            limits:
              memory: "768Mi"
            requests:
              memory: "70Mi"
              cpu: "1200m"
          env:
            - name: TZ
              value: "Europe/Stockholm"
            - name: KLARNA_API_USERNAME
              valueFrom:
                secretKeyRef:
                  name: klarna-api-credentials
                  key: username
            - name: KLARNA_API_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: klarna-api-credentials
                  key: password
            - name: AMQP_URL
              value: "amqp://admin:12bananer@rabbitmq.dev:5672/"
            # - name: BASE_URL
            #   value: "https://s10n-no.tornberg.me"
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: cart-actor
    arch: amd64
  name: cart-actor-x86
spec:
  replicas: 3
  selector:
    matchLabels:
      app: cart-actor
      arch: amd64
  template:
    metadata:
      labels:
        app: cart-actor
        actor-pool: cart
        arch: amd64
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: kubernetes.io/arch
                    operator: NotIn
                    values:
                      - arm64
      volumes:
        - name: data
          nfs:
            path: /i-data/7a8af061/nfs/cart-actor
            server: 10.10.1.10
      imagePullSecrets:
        - name: regcred
      serviceAccountName: default
      containers:
        - image: registry.knatofs.se/go-cart-actor-amd64:latest
          name: cart-actor-amd64
          imagePullPolicy: Always
          lifecycle:
            preStop:
              exec:
                command: ["sleep", "15"]
          ports:
            - containerPort: 8080
              name: web
            - containerPort: 8081
              name: debug
            - containerPort: 1337
              name: rpc
          livenessProbe:
            httpGet:
              path: /livez
              port: web
            failureThreshold: 1
            periodSeconds: 30
          readinessProbe:
            httpGet:
              path: /readyz
              port: web
            failureThreshold: 2
            initialDelaySeconds: 2
            periodSeconds: 50
          volumeMounts:
            - mountPath: "/data"
              name: data
          resources:
            limits:
              memory: "768Mi"
            requests:
              memory: "70Mi"
              cpu: "1200m"
          env:
            - name: TZ
              value: "Europe/Stockholm"
            - name: KLARNA_API_USERNAME
              valueFrom:
                secretKeyRef:
                  name: klarna-api-credentials
                  key: username
            - name: REDIS_ADDRESS
              value: "10.10.3.18:6379"
            - name: REDIS_PASSWORD
              value: "slaskredis"
            - name: OTEL_RESOURCE_ATTRIBUTES
              value: "service.name=cart,service.version=0.1.2"
            - name: OTEL_EXPORTER_OTLP_ENDPOINT
              value: "http://otel-debug-service.monitoring:4317"
            - name: KLARNA_API_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: klarna-api-credentials
                  key: password
            - name: POD_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: AMQP_URL
              value: "amqp://admin:12bananer@rabbitmq.dev:5672/"
            # - name: BASE_URL
            #   value: "https://s10n-no.tornberg.me"
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: cart-actor
    arch: arm64
  name: cart-actor-arm64
spec:
  replicas: 0
  selector:
    matchLabels:
      app: cart-actor
      arch: arm64
  template:
    metadata:
      labels:
        app: cart-actor
        actor-pool: cart
        arch: arm64
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: kubernetes.io/hostname
                    operator: NotIn
                    values:
                      - masterpi
                  - key: kubernetes.io/arch
                    operator: In
                    values:
                      - arm64
      volumes:
        - name: data
          nfs:
            path: /i-data/7a8af061/nfs/cart-actor
            server: 10.10.1.10
      imagePullSecrets:
        - name: regcred
      serviceAccountName: default
      containers:
        - image: registry.knatofs.se/go-cart-actor:latest
          name: cart-actor-arm64
          imagePullPolicy: Always
          lifecycle:
            preStop:
              exec:
                command: ["sleep", "15"]
          ports:
            - containerPort: 8080
              name: web
            - containerPort: 8081
              name: debug
            - containerPort: 1337
              name: rpc
          livenessProbe:
            httpGet:
              path: /livez
              port: web
            failureThreshold: 1
            periodSeconds: 30
          readinessProbe:
            httpGet:
              path: /readyz
              port: web
            failureThreshold: 2
            initialDelaySeconds: 2
            periodSeconds: 30
          volumeMounts:
            - mountPath: "/data"
              name: data
          resources:
            limits:
              memory: "768Mi"
            requests:
              memory: "70Mi"
              cpu: "1200m"
          env:
            - name: TZ
              value: "Europe/Stockholm"
            - name: REDIS_ADDRESS
              value: "redis.home:6379"
            - name: REDIS_PASSWORD
              value: "slaskredis"
            - name: OTEL_RESOURCE_ATTRIBUTES
              value: "service.name=cart,service.version=0.1.2"
            - name: OTEL_EXPORTER_OTLP_ENDPOINT
              value: "http://otel-debug-service.monitoring:4317"
            - name: KLARNA_API_USERNAME
              valueFrom:
                secretKeyRef:
                  name: klarna-api-credentials
                  key: username
            - name: KLARNA_API_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: klarna-api-credentials
                  key: password
            - name: POD_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: AMQP_URL
              value: "amqp://admin:12bananer@rabbitmq.dev:5672/"
            # - name: BASE_URL
            #   value: "https://s10n-no.tornberg.me"
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
---
kind: Service
apiVersion: v1
metadata:
  name: cart-actor
  annotations:
    prometheus.io/port: "8081"
    prometheus.io/scrape: "true"
    prometheus.io/path: "/metrics"
spec:
  selector:
    app: cart-actor
  ports:
    - name: web
      port: 8080
---
kind: Service
apiVersion: v1
metadata:
  name: cart-backoffice
spec:
  selector:
    app: cart-backoffice
  ports:
    - name: web
      port: 8080
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: cart-ingress
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod
    nginx.ingress.kubernetes.io/affinity: "cookie"
    nginx.ingress.kubernetes.io/session-cookie-name: "cart-affinity"
    nginx.ingress.kubernetes.io/session-cookie-expires: "172800"
    nginx.ingress.kubernetes.io/session-cookie-max-age: "172800"
    nginx.ingress.kubernetes.io/proxy-body-size: 4m
spec:
  ingressClassName: nginx
  tls:
    - hosts:
        - cart.tornberg.me
      secretName: cart-actor-tls-secret
  rules:
    - host: cart.tornberg.me
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: cart-actor
                port:
                  number: 8080
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: cart-backend-ingress
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
  ingressClassName: nginx
  tls:
    - hosts:
        - slask-cart.tornberg.me
      secretName: cart-backoffice-actor-tls-secret
  rules:
    - host: slask-cart.tornberg.me
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: cart-backoffice
                port:
                  number: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: cart-inventory
    arch: amd64
  name: cart-inventory-x86
spec:
  replicas: 1
  selector:
    matchLabels:
      app: cart-inventory
      arch: amd64
  template:
    metadata:
      labels:
        app: cart-inventory
        arch: amd64
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: kubernetes.io/arch
                    operator: NotIn
                    values:
                      - arm64
      imagePullSecrets:
        - name: regcred
      serviceAccountName: default
      containers:
        - image: registry.knatofs.se/go-cart-actor-amd64:latest
          name: cart-inventory-amd64
          imagePullPolicy: Always
          command: ["/go-cart-inventory"]
          lifecycle:
            preStop:
              exec:
                command: ["sleep", "15"]
          ports:
            - containerPort: 8080
              name: web
          livenessProbe:
            httpGet:
              path: /livez
              port: web
            failureThreshold: 1
            periodSeconds: 30
          readinessProbe:
            httpGet:
              path: /readyz
              port: web
            failureThreshold: 2
            initialDelaySeconds: 2
            periodSeconds: 30
          resources:
            limits:
              memory: "256Mi"
              cpu: "500m"
            requests:
              memory: "50Mi"
              cpu: "500m"
          env:
            - name: TZ
              value: "Europe/Stockholm"
            - name: RABBIT_HOST
              value: amqp://admin:12bananer@rabbitmq.s10n:5672/
            - name: REDIS_ADDRESS
              value: "redis.home:6379"
            - name: REDIS_PASSWORD
              value: "slaskredis"
