apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: webapp-MODEL_NAME
spec:
  gateways:
  - kubeflow-gateway
  hosts:
  - '*'
  http:
  - match:
    - uri:
        prefix: /webapp/
    rewrite:
      uri: /
    route:
    - destination:
        host: MODEL_NAME-webappsvc.KUBEFLOW_NAMESPACE.svc.cluster.local
        port:
          number: 80
    timeout: 300s

---

apiVersion: v1
kind: Service
metadata:
  annotations:
    getambassador.io/config: |-
      ---
      apiVersion: ambassador/v0
      kind:  Mapping
      name: webapp-MODEL_NAME
      prefix: /webapp/
      rewrite: /
      timeout_ms: 1200000
      service: MODEL_NAME-webappsvc.KUBEFLOW_NAMESPACE:80
  name: MODEL_NAME-webappsvc
  labels:
    app: ghsumm
    role: frontend
spec:
  type: ClusterIP
  ports:
  - port: 80
    targetPort: "http-server"
  selector:
    app: ghsumm
    role: frontend

---

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: MODEL_NAME-webapp
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: ghsumm
        role: frontend
    spec:
      volumes:
      - name: gcp-credentials-user-gcp-sa
        secret:
          secretName: user-gcp-sa
      containers:
      - name: MODEL_NAME-webapp
        image: gcr.io/google-samples/ml-pipeline-t2tapp:v3ap
        env:
        - name: GOOGLE_APPLICATION_CREDENTIALS
          value: /secret/gcp-credentials/user-gcp-sa.json
        - name: CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE
          value: /secret/gcp-credentials/user-gcp-sa.json
        volumeMounts:
        - mountPath: /secret/gcp-credentials
          name: gcp-credentials-user-gcp-sa
        # resources:
        #   limits:
        #     nvidia.com/gpu: 1
        imagePullPolicy: Always
        env:
        - name: TFSERVING_HOST
          value: MODEL_NAME.KUBEFLOW_NAMESPACE
        - name: TF_SERVABLE_NAME
          value: MODEL_NAME
        - name: GH_TOKEN
          value: GITHUB_TOKEN
        - name: DATADIR
          value: DATA_DIR
        ports:
        - name: http-server
          containerPort: 8080
