---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: productpage-v1
  labels:
    app: productpage
    version: v1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: productpage
      version: v1
  template:
    metadata:
      labels:
        app: productpage
        version: v1
    spec:
      serviceAccountName: bookinfo-productpage
      initContainers:
      - name: add-wasm
        image: curlimages/curl
        command:
        - "curl"
        - "-L"
        - "-o"
        - "/var/lib/filters/ratelimit-filter.wasm"
        - "https://github.com/layer5io/advanced-istio-service-mesh-workshop/raw/master/lab-3/ratelimiter/ratelimit-filter.wasm"
        volumeMounts:
        - mountPath: /var/lib/filters
          name: wasm-filter
      containers:
      - name: productpage
        image: docker.io/istio/examples-bookinfo-productpage-v1:1.16.2
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 9080
        volumeMounts:
        - name: tmp
          mountPath: /tmp
        - name: wasm-filter
          mountPath: /var/lib/filters
      volumes:
      - name: tmp
        emptyDir: {}
      - name: wasm-filter
        emptyDir: {}

# kubectl patch deployment -n default productpage-v1 -p '{
#   "spec": {
#     "template": {
#       "metadata": {
#         "annotations": {
#           "sidecar.istio.io/userVolumeMount": "[{\"mountPath\":\"/var/lib/filters\",\"name\":\"wasm-filter\"}]"
#         }
#       }
#     }
#   }
# }'