apiVersion: apps/v1
kind: Deployment
metadata:
  name: store
  namespace: gcpdemo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: store
      version: "v1"
  template:
    metadata:
      labels:
        app: store
        version: "v1"
    spec:
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - podAffinityTerm:
                labelSelector:
                  matchExpressions:
                    - key: app
                      operator: In
                      values:
                        - store
                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 store-mongodb 27017)
                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: store-app
          image: keithchenon/store
          env:
            - name: SPRING_PROFILES_ACTIVE
              value: prod
            - name: SPRING_CLOUD_CONFIG_URI
              value: http://admin:${jhipster.registry.password}@jhipster-registry.gcpdemo.svc.cluster.local:8761/config
            - name: JHIPSTER_REGISTRY_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: registry-secret
                  key: registry-admin-password
            - name: EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE
              value: http://admin:${jhipster.registry.password}@jhipster-registry.gcpdemo.svc.cluster.local:8761/eureka/
            - name: SPRING_DATA_MONGODB_DATABASE
              value: store
            - name: SPRING_DATA_MONGODB_URI
              value: "mongodb://store-mongodb-0.store-mongodb.gcpdemo:27017/?waitQueueMultiple=1000,store-mongodb-1.store-mongodb.gcpdemo:27017/?waitQueueMultiple=1000,store-mongodb-2.store-mongodb.gcpdemo:27017/?waitQueueMultiple=1000"
            - 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: 8082
          readinessProbe:
            httpGet:
              path: /management/health/readiness
              port: http
            initialDelaySeconds: 20
            periodSeconds: 15
            failureThreshold: 6
          livenessProbe:
            httpGet:
              path: /management/health/liveness
              port: http
            initialDelaySeconds: 120
