apiVersion: apps/v1
kind: Deployment
metadata:
  name: product
  namespace: jhipster
spec:
  replicas: 1
  selector:
    matchLabels:
      app: product
      version: "v1"
  template:
    metadata:
      labels:
        app: product
        version: "v1"
    spec:
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - podAffinityTerm:
                labelSelector:
                  matchExpressions:
                    - key: app
                      operator: In
                      values:
                        - product
                topologyKey: kubernetes.io/hostname
              weight: 100
      initContainers:
        - name: init-ds
          image: busybox:latest
          command:
            - "/bin/sh"
            - "-c"
            - |
              while true
              do
                rt=$(nc -z -w 1 product-postgresql 5432)
                if [ $? -eq 0 ]; then
                  echo "DB is UP"
                  break
                fi
                echo "DB is not yet reachable;sleep for 10s before retry"
                sleep 10
              done
      containers:
        - name: product-app
          image: deepu105/product-istio
          env:
            - name: SPRING_PROFILES_ACTIVE
              value: prod
            - name: JHIPSTER_SECURITY_AUTHENTICATION_JWT_BASE64_SECRET
              valueFrom:
                secretKeyRef:
                  name: jwt-secret
                  key: secret
            - name: SPRING_DATASOURCE_URL
              value: jdbc:postgresql://product-postgresql.jhipster.svc.cluster.local:5432/product
            - name: SPRING_DATASOURCE_USERNAME
              value: product
            - name: SPRING_DATASOURCE_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: product-postgresql
                  key: postgresql-password
            - name: SPRING_LIQUIBASE_URL
              value: jdbc:postgresql://product-postgresql.jhipster.svc.cluster.local:5432/product
            - name: SPRING_SLEUTH_PROPAGATION_KEYS
              value: "x-request-id,x-ot-span-context"
            - name: JAVA_OPTS
              value: " -Xmx256m -Xms256m"
            - name: SERVER_SHUTDOWN
              value: graceful
          resources:
            requests:
              memory: "512Mi"
              cpu: "500m"
            limits:
              memory: "1Gi"
              cpu: "1"
          ports:
            - name: http
              containerPort: 8081
          readinessProbe:
            httpGet:
              path: /management/health/readiness
              port: http
            initialDelaySeconds: 20
            periodSeconds: 15
            failureThreshold: 6
          livenessProbe:
            httpGet:
              path: /management/health/liveness
              port: http
            initialDelaySeconds: 120
