apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: "{service}"

  labels:
    cloud.googleapis.com/location: "{region}"

  annotations:
    run.googleapis.com/ingress: all
    run.googleapis.com/ingress-status: all

spec:
  template:
    metadata:
      labels:
        run.googleapis.com/startupProbeType: Custom

      annotations:
        run.googleapis.com/sessionAffinity: "true"
        run.googleapis.com/vpc-access-egress: private-ranges-only
        autoscaling.knative.dev/minScale: "1"
        autoscaling.knative.dev/maxScale: "2"
        run.googleapis.com/network-interfaces: '[{{"network":"{network}","subnetwork":"{subnetwork}"}}]'
        run.googleapis.com/cpu-throttling: "false"

    spec:
      containerConcurrency: 80
      timeoutSeconds: 60
      serviceAccountName: "{service_account}"
      containers:
        - image: "{image_url}"

          ports:
            - name: http1
              containerPort: 8080

          env:
            - name: CONCIERGE_CHECKPOINTER__TYPE
              value: postgresql
            - name: CONCIERGE_CHECKPOINTER__CONNECTION_URL
              valueFrom:
                secretKeyRef:
                  key: latest
                  name: "{alloydb_secret_name}"

            - name: CONCIERGE_PROJECT
              value: {project}
            - name: CONCIERGE_REGION
              value: {region}

            - name: CONCIERGE_CYMBAL_DATASET_LOCATION
              value: {cymbal_dataset_location}
            - name: CONCIERGE_CYMBAL_PRODUCTS_TABLE_URI
              value: {cymbal_products_table_uri}
            - name: CONCIERGE_CYMBAL_STORES_TABLE_URI
              value: {cymbal_stores_table_uri}
            - name: CONCIERGE_CYMBAL_INVENTORY_TABLE_URI
              value: {cymbal_inventory_table_uri}
            - name: CONCIERGE_CYMBAL_EMBEDDING_MODEL_URI
              value: {cymbal_embedding_model_uri}

          resources:
            limits:
              cpu: "2"
              memory: 2Gi

          startupProbe:
            initialDelaySeconds: 10
            timeoutSeconds: 3
            periodSeconds: 5
            failureThreshold: 10
            httpGet:
              path: /health
              port: 8080

          livenessProbe:
            initialDelaySeconds: 0
            timeoutSeconds: 3
            periodSeconds: 60
            failureThreshold: 5
            httpGet:
              path: /health
              port: 8080

  traffic:
    - percent: 100
      latestRevision: true
