# Deployment configuration for the application.
# Referred config values are defined in '.template.configuration.properties' file.
# Referred secret values are defined in '.template.secret.properties' file.
# The configurations and secrets are automatically deployed to the cluster with CI/CD scripts.
#
# Replace the ${VARIABLE} tags with corresponding values
# manually or with 'envsubst' command for example.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ${CI_PROJECT_NAME}
  namespace: default
  annotations:
    app.gitlab.com/app: "$CI_PROJECT_PATH_SLUG"
    app.gitlab.com/env: "$CI_ENVIRONMENT_SLUG"
  labels:
    app: ${CI_PROJECT_NAME}
spec:
  replicas: 2
  selector:
    matchLabels:
      app: ${CI_PROJECT_NAME}
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 2
      maxUnavailable: 0
  template:
    metadata:
      annotations:
        app.gitlab.com/app: "$CI_PROJECT_PATH_SLUG"
        app.gitlab.com/env: "$CI_ENVIRONMENT_SLUG"
      labels:
        app: ${CI_PROJECT_NAME}
        ci-version: "${CI_PIPELINE_IID}" # Ensure that the deployment gets updated every time.
    spec:
      serviceAccountName: ${CI_PROJECT_NAME}-ksa
      containers:
        - name: ${CI_PROJECT_NAME}
          image: ${DOCKER_REGISTRY}/${GCP_PROJECT}/${CI_PROJECT_NAME}:${VERSION}
          imagePullPolicy: Always # Needed when using latest tagging scheme.
          resources:
            requests:
              cpu: 100m
              memory: 64Mi
            limits:
              cpu: 500m
              memory: 128Mi
          ports:
            - containerPort: ${PORT}
          livenessProbe:
            httpGet:
              path: /api/health/liveness
              port: ${PORT}
            initialDelaySeconds: 2
            periodSeconds: 2
          readinessProbe:
            httpGet:
              path: /api/health/readiness
              port: ${PORT}
            initialDelaySeconds: 2
            periodSeconds: 2
          envFrom:
            # Load the Complete ConfigMap for the application.
            - configMapRef:
                name: ${CI_PROJECT_NAME}-config
            # Load the Complete ConfigMap
            - secretRef:
                name: ${CI_PROJECT_NAME}-secret

