{{- if and ( index .Values "redis-cluster" "enabled" ) .Values.istio.enabled }}
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
  name: {{ .Release.Namespace }}-{{ .Release.Name }}-redis-proxy
  namespace: istio-ingress
spec:
  workloadSelector:
    labels:
      istio: private-ingressgateway
  configPatches:
  - applyTo: NETWORK_FILTER
    match:
      context: GATEWAY
      listener:
        name: 0.0.0.0_{{ default 6379 .Values.istio.port }}
        filterChain:
          filter:
            name: "envoy.filters.network.tcp_proxy"
    patch:
      operation: REPLACE
      value:
        name: envoy.redis_proxy
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.filters.network.redis_proxy.v3.RedisProxy
          stat_prefix: redis_stats
          prefix_routes:
            catch_all_route:
              cluster: {{ .Release.Namespace }}-{{ .Release.Name }}-redis-cluster
          settings:
            op_timeout: 5s
            enable_redirection: true
            enable_command_stats: true
            read_policy: PREFER_MASTER
{{- end }}
