---
# Source: istiod/templates/serviceaccount.yaml
# Created if this is not a remote istiod, OR if it is and is also a config cluster
apiVersion: v1
kind: ServiceAccount
metadata:
  name: istiod
  namespace: istio-system
  labels:
    app: istiod
    release: istiod
    app.kubernetes.io/name: "istiod"
    app.kubernetes.io/managed-by: "Helm"
    app.kubernetes.io/instance: "istiod"
    app.kubernetes.io/part-of: "istio"
    app.kubernetes.io/version: "1.30.0"
    helm.sh/chart: istiod-1.30.0
---
# Source: istiod/templates/configmap-values.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: values
  namespace: default
  annotations:
    kubernetes.io/description: This ConfigMap contains the Helm values used during chart rendering. This ConfigMap is rendered for debugging purposes and external tooling; modifying these values has no effect.
  labels:
    istio.io/rev: "default"
    install.operator.istio.io/owning-resource: unknown
    operator.istio.io/component: "Pilot"
    release: istiod
    app.kubernetes.io/name: "istiod"
    app.kubernetes.io/managed-by: "Helm"
    app.kubernetes.io/instance: "istiod"
    app.kubernetes.io/part-of: "istio"
    app.kubernetes.io/version: "1.30.0"
    helm.sh/chart: istiod-1.30.0
data:
  original-values: |-
    {}
  merged-values: |-
    {
      "affinity": {},
      "autoscaleBehavior": {},
      "autoscaleEnabled": true,
      "autoscaleMax": 5,
      "autoscaleMin": 1,
      "base": {
        "enableIstioConfigCRDs": true
      },
      "cni": {
        "enabled": false,
        "provider": "default"
      },
      "configMap": true,
      "cpu": {
        "targetAverageUtilization": 80
      },
      "deploymentAnnotations": {},
      "deploymentLabels": {},
      "env": {},
      "envVarFrom": [],
      "experimental": {
        "stableValidationPolicy": false
      },
      "extraContainerArgs": [],
      "gatewayClasses": {},
      "gateways": {
        "seccompProfile": {},
        "securityContext": {}
      },
      "global": {
        "caAddress": "",
        "caName": "",
        "certSigners": [],
        "configCluster": false,
        "configValidation": true,
        "defaultPodDisruptionBudget": {
          "enabled": true
        },
        "defaultResources": {
          "requests": {
            "cpu": "10m"
          }
        },
        "externalIstiod": false,
        "hub": "registry.istio.io/release",
        "imagePullPolicy": "",
        "imagePullSecrets": [],
        "istioNamespace": "istio-system",
        "istiod": {
          "enableAnalysis": false
        },
        "logAsJson": false,
        "logging": {
          "level": "default:info"
        },
        "meshID": "",
        "meshNetworks": {},
        "mountMtlsCerts": false,
        "multiCluster": {
          "clusterName": ""
        },
        "nativeNftables": false,
        "network": "",
        "networkPolicy": {
          "enabled": false
        },
        "omitSidecarInjectorConfigMap": false,
        "operatorManageWebhooks": false,
        "pilotCertProvider": "istiod",
        "priorityClassName": "",
        "proxy": {
          "autoInject": "enabled",
          "clusterDomain": "cluster.local",
          "componentLogLevel": "misc:error",
          "excludeIPRanges": "",
          "excludeInboundPorts": "",
          "excludeOutboundPorts": "",
          "image": "proxyv2",
          "includeIPRanges": "*",
          "includeInboundPorts": "*",
          "includeOutboundPorts": "",
          "logLevel": "warning",
          "outlierLogPath": "",
          "privileged": false,
          "readinessFailureThreshold": 4,
          "readinessInitialDelaySeconds": 0,
          "readinessPeriodSeconds": 15,
          "resources": {
            "limits": {
              "cpu": "2000m",
              "memory": "1024Mi"
            },
            "requests": {
              "cpu": "100m",
              "memory": "128Mi"
            }
          },
          "seccompProfile": {},
          "startupProbe": {
            "enabled": true,
            "failureThreshold": 600
          },
          "statusPort": 15020,
          "tracer": "none"
        },
        "proxy_init": {
          "forceApplyIptables": false,
          "image": "proxyv2"
        },
        "remotePilotAddress": "",
        "resourceScope": "all",
        "sds": {
          "token": {
            "aud": "istio-ca"
          }
        },
        "sts": {
          "servicePort": 0
        },
        "tag": "1.30.0",
        "variant": "",
        "waypoint": {
          "affinity": {},
          "nodeSelector": {},
          "resources": {
            "limits": {
              "cpu": "2",
              "memory": "1Gi"
            },
            "requests": {
              "cpu": "100m",
              "memory": "128Mi"
            }
          },
          "tolerations": [],
          "topologySpreadConstraints": []
        }
      },
      "hub": "",
      "image": "pilot",
      "initContainers": [],
      "ipFamilies": [],
      "ipFamilyPolicy": "",
      "istiodRemote": {
        "enabled": false,
        "enabledLocalInjectorIstiod": false,
        "injectionCABundle": "",
        "injectionPath": "/inject",
        "injectionURL": ""
      },
      "jwksResolverExtraRootCA": "",
      "keepaliveMaxServerConnectionAge": "30m",
      "memory": {},
      "meshConfig": {
        "enablePrometheusMerge": true
      },
      "nodeSelector": {},
      "ownerName": "",
      "pdb": {
        "minAvailable": 1,
        "unhealthyPodEvictionPolicy": ""
      },
      "podAnnotations": {},
      "podLabels": {},
      "replicaCount": 1,
      "resources": {
        "requests": {
          "cpu": "500m",
          "memory": "2048Mi"
        }
      },
      "revision": "",
      "revisionTags": [],
      "rollingMaxSurge": "100%",
      "rollingMaxUnavailable": "25%",
      "seccompProfile": {},
      "serviceAccountAnnotations": {},
      "serviceAnnotations": {},
      "sidecarInjectorWebhook": {
        "alwaysInjectSelector": [],
        "defaultTemplates": [],
        "enableNamespacesByDefault": false,
        "injectedAnnotations": {},
        "neverInjectSelector": [],
        "reinvocationPolicy": "Never",
        "rewriteAppHTTPProbe": true,
        "templates": {}
      },
      "sidecarInjectorWebhookAnnotations": {},
      "tag": "",
      "taint": {
        "enabled": false,
        "namespace": ""
      },
      "telemetry": {
        "enabled": true,
        "v2": {
          "enabled": true,
          "prometheus": {
            "enabled": true
          },
          "stackdriver": {
            "enabled": false
          }
        }
      },
      "tolerations": [],
      "topologySpreadConstraints": [],
      "traceSampling": 1,
      "trustedZtunnelName": "",
      "trustedZtunnelNamespace": "",
      "variant": "",
      "volumeMounts": [],
      "volumes": []
    }
---
# Source: istiod/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: istio
  namespace: default
  labels:
    istio.io/rev: "default"
    install.operator.istio.io/owning-resource: unknown
    operator.istio.io/component: "Pilot"
    release: istiod
    app.kubernetes.io/name: "istiod"
    app.kubernetes.io/managed-by: "Helm"
    app.kubernetes.io/instance: "istiod"
    app.kubernetes.io/part-of: "istio"
    app.kubernetes.io/version: "1.30.0"
    helm.sh/chart: istiod-1.30.0
data:

  # Configuration file for the mesh networks to be used by the Split Horizon EDS.
  meshNetworks: |-
    networks: {}

  mesh: |-
    defaultConfig:
      discoveryAddress: istiod.default.svc:15012
    defaultProviders:
      metrics:
      - prometheus
    enablePrometheusMerge: true
    rootNamespace: istio-system
    trustDomain: cluster.local
---
# Source: istiod/templates/istiod-injector-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: istio-sidecar-injector
  namespace: default
  labels:
    istio.io/rev: "default"
    install.operator.istio.io/owning-resource: unknown
    operator.istio.io/component: "Pilot"
    release: istiod
    app.kubernetes.io/name: "istiod"
    app.kubernetes.io/managed-by: "Helm"
    app.kubernetes.io/instance: "istiod"
    app.kubernetes.io/part-of: "istio"
    app.kubernetes.io/version: "1.30.0"
    helm.sh/chart: istiod-1.30.0
data:

  values: |-
    {
      "gateways": {
        "seccompProfile": {},
        "securityContext": {}
      },
      "global": {
        "caAddress": "",
        "caName": "",
        "certSigners": [],
        "configCluster": false,
        "configValidation": true,
        "defaultPodDisruptionBudget": {
          "enabled": true
        },
        "defaultResources": {
          "requests": {
            "cpu": "10m"
          }
        },
        "externalIstiod": false,
        "hub": "registry.istio.io/release",
        "imagePullPolicy": "",
        "imagePullSecrets": [],
        "istioNamespace": "istio-system",
        "istiod": {
          "enableAnalysis": false
        },
        "logAsJson": false,
        "logging": {
          "level": "default:info"
        },
        "meshID": "",
        "meshNetworks": {},
        "mountMtlsCerts": false,
        "multiCluster": {
          "clusterName": ""
        },
        "nativeNftables": false,
        "network": "",
        "networkPolicy": {
          "enabled": false
        },
        "omitSidecarInjectorConfigMap": false,
        "operatorManageWebhooks": false,
        "pilotCertProvider": "istiod",
        "priorityClassName": "",
        "proxy": {
          "autoInject": "enabled",
          "clusterDomain": "cluster.local",
          "componentLogLevel": "misc:error",
          "excludeIPRanges": "",
          "excludeInboundPorts": "",
          "excludeOutboundPorts": "",
          "image": "proxyv2",
          "includeIPRanges": "*",
          "includeInboundPorts": "*",
          "includeOutboundPorts": "",
          "logLevel": "warning",
          "outlierLogPath": "",
          "privileged": false,
          "readinessFailureThreshold": 4,
          "readinessInitialDelaySeconds": 0,
          "readinessPeriodSeconds": 15,
          "resources": {
            "limits": {
              "cpu": "2000m",
              "memory": "1024Mi"
            },
            "requests": {
              "cpu": "100m",
              "memory": "128Mi"
            }
          },
          "seccompProfile": {},
          "startupProbe": {
            "enabled": true,
            "failureThreshold": 600
          },
          "statusPort": 15020,
          "tracer": "none"
        },
        "proxy_init": {
          "forceApplyIptables": false,
          "image": "proxyv2"
        },
        "remotePilotAddress": "",
        "resourceScope": "all",
        "sds": {
          "token": {
            "aud": "istio-ca"
          }
        },
        "sts": {
          "servicePort": 0
        },
        "tag": "1.30.0",
        "variant": "",
        "waypoint": {
          "affinity": {},
          "nodeSelector": {},
          "resources": {
            "limits": {
              "cpu": "2",
              "memory": "1Gi"
            },
            "requests": {
              "cpu": "100m",
              "memory": "128Mi"
            }
          },
          "tolerations": [],
          "topologySpreadConstraints": []
        }
      },
      "pilot": {
        "cni": {
          "enabled": false,
          "provider": "default"
        },
        "env": {}
      },
      "revision": "",
      "sidecarInjectorWebhook": {
        "alwaysInjectSelector": [],
        "defaultTemplates": [],
        "enableNamespacesByDefault": false,
        "injectedAnnotations": {},
        "neverInjectSelector": [],
        "reinvocationPolicy": "Never",
        "rewriteAppHTTPProbe": true,
        "templates": {}
      }
    }

  # To disable injection: use omitSidecarInjectorConfigMap, which disables the webhook patching
  # and istiod webhook functionality.
  #
  # New fields should not use Values - it is a 'primary' config object, users should be able
  # to fine tune it or use it with kube-inject.
  config: |-
    # defaultTemplates defines the default template to use for pods that do not explicitly specify a template
    defaultTemplates: [sidecar]
    policy: enabled
    alwaysInjectSelector:
      []
    neverInjectSelector:
      []
    injectedAnnotations:
    template: "{{ Template_Version_And_Istio_Version_Mismatched_Check_Installation }}"
    templates:
      sidecar: |
        {{- define "resources"  }}
          {{- if or (isset .ObjectMeta.Annotations `sidecar.istio.io/proxyCPU`) (isset .ObjectMeta.Annotations `sidecar.istio.io/proxyMemory`) (isset .ObjectMeta.Annotations `sidecar.istio.io/proxyCPULimit`) (isset .ObjectMeta.Annotations `sidecar.istio.io/proxyMemoryLimit`) }}
            {{- if or (isset .ObjectMeta.Annotations `sidecar.istio.io/proxyCPU`) (isset .ObjectMeta.Annotations `sidecar.istio.io/proxyMemory`) }}
              requests:
                {{ if (isset .ObjectMeta.Annotations `sidecar.istio.io/proxyCPU`) -}}
                cpu: {{ index .ObjectMeta.Annotations `sidecar.istio.io/proxyCPU` | quote }}
                {{ end }}
                {{ if (isset .ObjectMeta.Annotations `sidecar.istio.io/proxyMemory`) -}}
                memory: {{ index .ObjectMeta.Annotations `sidecar.istio.io/proxyMemory` | quote }}
                {{ end }}
            {{- end }}
            {{- if or (isset .ObjectMeta.Annotations `sidecar.istio.io/proxyCPULimit`) (isset .ObjectMeta.Annotations `sidecar.istio.io/proxyMemoryLimit`) }}
              limits:
                {{ if (isset .ObjectMeta.Annotations `sidecar.istio.io/proxyCPULimit`) -}}
                cpu: {{ index .ObjectMeta.Annotations `sidecar.istio.io/proxyCPULimit` | quote }}
                {{ end }}
                {{ if (isset .ObjectMeta.Annotations `sidecar.istio.io/proxyMemoryLimit`) -}}
                memory: {{ index .ObjectMeta.Annotations `sidecar.istio.io/proxyMemoryLimit` | quote }}
                {{ end }}
            {{- end }}
          {{- else }}
            {{- if .Values.global.proxy.resources }}
              {{ toYaml (omitNil .Values.global.proxy.resources) | indent 6 }}
            {{- end }}
          {{- end }}
        {{- end }}
        {{ $tproxy := (eq (annotation .ObjectMeta `sidecar.istio.io/interceptionMode` .ProxyConfig.InterceptionMode) `TPROXY`) }}
        {{ $capNetBindService := (eq (annotation .ObjectMeta `sidecar.istio.io/capNetBindService` .Values.global.proxy.capNetBindService) `true`) }}
        {{ $nativeSidecar := ne (index .ObjectMeta.Annotations `sidecar.istio.io/nativeSidecar` | default (printf "%t" .NativeSidecars)) "false" }}
        {{- $containers := list }}
        {{- range $index, $container := .Spec.Containers }}{{ if not (eq $container.Name "istio-proxy") }}{{ $containers = append $containers $container.Name }}{{end}}{{- end}}
        metadata:
          labels:
            security.istio.io/tlsMode: {{ index .ObjectMeta.Labels `security.istio.io/tlsMode` | default "istio"  | quote }}
            {{- if eq (index .ProxyConfig.ProxyMetadata "ISTIO_META_ENABLE_HBONE") "true" }}
            networking.istio.io/tunnel: {{ index .ObjectMeta.Labels `networking.istio.io/tunnel` | default "http"  | quote }}
            {{- end }}
            service.istio.io/canonical-name: {{ index .ObjectMeta.Labels `service.istio.io/canonical-name` | default (index .ObjectMeta.Labels `app.kubernetes.io/name`) | default (index .ObjectMeta.Labels `app`) | default .DeploymentMeta.Name  | trunc 63 | trimSuffix "-" | quote }}
            service.istio.io/canonical-revision: {{ index .ObjectMeta.Labels `service.istio.io/canonical-revision` | default (index .ObjectMeta.Labels `app.kubernetes.io/version`) | default (index .ObjectMeta.Labels `version`) | default "latest"  | quote }}
          annotations: {
            istio.io/rev: {{ .Revision | default "default" | quote }},
            {{- if ge (len $containers) 1 }}
            {{- if not (isset .ObjectMeta.Annotations `kubectl.kubernetes.io/default-logs-container`) }}
            kubectl.kubernetes.io/default-logs-container: "{{ index $containers 0 }}",
            {{- end }}
            {{- if not (isset .ObjectMeta.Annotations `kubectl.kubernetes.io/default-container`) }}
            kubectl.kubernetes.io/default-container: "{{ index $containers 0 }}",
            {{- end }}
            {{- end }}
        {{- if .Values.pilot.cni.enabled }}
            {{- if eq .Values.pilot.cni.provider "multus" }}
            k8s.v1.cni.cncf.io/networks: '{{ appendMultusNetwork (index .ObjectMeta.Annotations `k8s.v1.cni.cncf.io/networks`) `default/istio-cni` }}',
            {{- end }}
            sidecar.istio.io/interceptionMode: "{{ annotation .ObjectMeta `sidecar.istio.io/interceptionMode` .ProxyConfig.InterceptionMode }}",
            {{ with annotation .ObjectMeta `traffic.sidecar.istio.io/includeOutboundIPRanges` .Values.global.proxy.includeIPRanges }}traffic.sidecar.istio.io/includeOutboundIPRanges: "{{.}}",{{ end }}
            {{ with annotation .ObjectMeta `traffic.sidecar.istio.io/excludeOutboundIPRanges` .Values.global.proxy.excludeIPRanges }}traffic.sidecar.istio.io/excludeOutboundIPRanges: "{{.}}",{{ end }}
            traffic.sidecar.istio.io/includeInboundPorts: "{{ annotation .ObjectMeta `traffic.sidecar.istio.io/includeInboundPorts` .Values.global.proxy.includeInboundPorts }}",
            traffic.sidecar.istio.io/excludeInboundPorts: "{{ excludeInboundPort (annotation .ObjectMeta `status.sidecar.istio.io/port` .Values.global.proxy.statusPort) (annotation .ObjectMeta `traffic.sidecar.istio.io/excludeInboundPorts` .Values.global.proxy.excludeInboundPorts) }}",
            {{ if or (isset .ObjectMeta.Annotations `traffic.sidecar.istio.io/includeOutboundPorts`) (ne (valueOrDefault .Values.global.proxy.includeOutboundPorts "") "") }}
            traffic.sidecar.istio.io/includeOutboundPorts: "{{ annotation .ObjectMeta `traffic.sidecar.istio.io/includeOutboundPorts` .Values.global.proxy.includeOutboundPorts }}",
            {{- end }}
            {{ if or (isset .ObjectMeta.Annotations `traffic.sidecar.istio.io/excludeOutboundPorts`) (ne .Values.global.proxy.excludeOutboundPorts "") }}
            traffic.sidecar.istio.io/excludeOutboundPorts: "{{ annotation .ObjectMeta `traffic.sidecar.istio.io/excludeOutboundPorts` .Values.global.proxy.excludeOutboundPorts }}",
            {{- end }}
            {{ with index .ObjectMeta.Annotations `traffic.sidecar.istio.io/kubevirtInterfaces` }}traffic.sidecar.istio.io/kubevirtInterfaces: "{{.}}",{{ end }}
            {{ with index .ObjectMeta.Annotations `istio.io/reroute-virtual-interfaces` }}istio.io/reroute-virtual-interfaces: "{{.}}",{{ end }}
            {{ with index .ObjectMeta.Annotations `traffic.sidecar.istio.io/excludeInterfaces` }}traffic.sidecar.istio.io/excludeInterfaces: "{{.}}",{{ end }}
        {{- end }}
          }
        spec:
          {{- $holdProxy := and
              (or .ProxyConfig.HoldApplicationUntilProxyStarts.GetValue .Values.global.proxy.holdApplicationUntilProxyStarts)
              (not $nativeSidecar) }}
          {{- $noInitContainer := and
              (eq (annotation .ObjectMeta `sidecar.istio.io/interceptionMode` .ProxyConfig.InterceptionMode) `NONE`)
              (not $nativeSidecar) }}
          {{ if $noInitContainer }}
          initContainers: []
          {{ else -}}
          initContainers:
          {{ if ne (annotation .ObjectMeta `sidecar.istio.io/interceptionMode` .ProxyConfig.InterceptionMode) `NONE` }}
          {{ if .Values.pilot.cni.enabled -}}
          - name: istio-validation
          {{ else -}}
          - name: istio-init
          {{ end -}}
          {{- if contains "/" (annotation .ObjectMeta `sidecar.istio.io/proxyImage` .Values.global.proxy_init.image) }}
            image: "{{ annotation .ObjectMeta `sidecar.istio.io/proxyImage` .Values.global.proxy_init.image }}"
          {{- else }}
            image: "{{ .ProxyImage }}"
          {{- end }}
            args:
            - istio-iptables
            - "-p"
            - {{ .MeshConfig.ProxyListenPort | default "15001" | quote }}
            - "-z"
            - {{ .MeshConfig.ProxyInboundListenPort | default "15006" | quote }}
            - "-u"
            - {{ if $tproxy }} "1337" {{ else }} {{ .ProxyUID | default "1337" | quote }} {{ end }}
            - "-m"
            - "{{ annotation .ObjectMeta `sidecar.istio.io/interceptionMode` .ProxyConfig.InterceptionMode }}"
            - "-i"
            - "{{ annotation .ObjectMeta `traffic.sidecar.istio.io/includeOutboundIPRanges` .Values.global.proxy.includeIPRanges }}"
            - "-x"
            - "{{ annotation .ObjectMeta `traffic.sidecar.istio.io/excludeOutboundIPRanges` .Values.global.proxy.excludeIPRanges }}"
            - "-b"
            - "{{ annotation .ObjectMeta `traffic.sidecar.istio.io/includeInboundPorts` .Values.global.proxy.includeInboundPorts }}"
            - "-d"
          {{- if excludeInboundPort (annotation .ObjectMeta `status.sidecar.istio.io/port` .Values.global.proxy.statusPort) (annotation .ObjectMeta `traffic.sidecar.istio.io/excludeInboundPorts` .Values.global.proxy.excludeInboundPorts) }}
            - "15090,15021,{{ excludeInboundPort (annotation .ObjectMeta `status.sidecar.istio.io/port` .Values.global.proxy.statusPort) (annotation .ObjectMeta `traffic.sidecar.istio.io/excludeInboundPorts` .Values.global.proxy.excludeInboundPorts) }}"
          {{- else }}
            - "15090,15021"
          {{- end }}
            {{ if or (isset .ObjectMeta.Annotations `traffic.sidecar.istio.io/includeOutboundPorts`) (ne (valueOrDefault .Values.global.proxy.includeOutboundPorts "") "") -}}
            - "-q"
            - "{{ annotation .ObjectMeta `traffic.sidecar.istio.io/includeOutboundPorts` .Values.global.proxy.includeOutboundPorts }}"
            {{ end -}}
            {{ if or (isset .ObjectMeta.Annotations `traffic.sidecar.istio.io/excludeOutboundPorts`) (ne (valueOrDefault .Values.global.proxy.excludeOutboundPorts "") "") -}}
            - "-o"
            - "{{ annotation .ObjectMeta `traffic.sidecar.istio.io/excludeOutboundPorts` .Values.global.proxy.excludeOutboundPorts }}"
            {{ end -}}
            {{ if (isset .ObjectMeta.Annotations `istio.io/reroute-virtual-interfaces`) -}}
            - "-k"
            - "{{ index .ObjectMeta.Annotations `istio.io/reroute-virtual-interfaces` }}"
            {{ else if (isset .ObjectMeta.Annotations `traffic.sidecar.istio.io/kubevirtInterfaces`) -}}
            - "-k"
            - "{{ index .ObjectMeta.Annotations `traffic.sidecar.istio.io/kubevirtInterfaces` }}"
            {{ end -}}
             {{ if (isset .ObjectMeta.Annotations `traffic.sidecar.istio.io/excludeInterfaces`) -}}
            - "-c"
            - "{{ index .ObjectMeta.Annotations `traffic.sidecar.istio.io/excludeInterfaces` }}"
            {{ end -}}
            - "--log_output_level={{ annotation .ObjectMeta `sidecar.istio.io/agentLogLevel` .Values.global.logging.level }}"
            {{ if .Values.global.logAsJson -}}
            - "--log_as_json"
            {{ end -}}
            {{ if .Values.pilot.cni.enabled -}}
            - "--run-validation"
            - "--skip-rule-apply"
            {{ else if .Values.global.proxy_init.forceApplyIptables -}}
            - "--force-apply"
            {{ end -}}
            {{ if .Values.global.nativeNftables -}}
            - "--native-nftables"
            {{ end -}}
            {{with .Values.global.imagePullPolicy }}imagePullPolicy: "{{.}}"{{end}}
          {{- if .ProxyConfig.ProxyMetadata }}
            env:
            {{- range $key, $value := .ProxyConfig.ProxyMetadata }}
            - name: {{ $key }}
              value: "{{ $value }}"
            {{- end }}
          {{- end }}
            resources:
          {{ template "resources" . }}
            securityContext:
              allowPrivilegeEscalation: {{ .Values.global.proxy.privileged }}
              privileged: {{ .Values.global.proxy.privileged }}
              capabilities:
            {{- if not .Values.pilot.cni.enabled }}
                add:
                - NET_ADMIN
                - NET_RAW
            {{- end }}
                drop:
                - ALL
            {{- if not .Values.pilot.cni.enabled }}
              readOnlyRootFilesystem: false
              runAsGroup: 0
              runAsNonRoot: false
              runAsUser: 0
            {{- else }}
              readOnlyRootFilesystem: true
              runAsGroup: {{ if $tproxy }} 1337 {{ else }} {{ .ProxyGID | default "1337" }} {{ end }}
              runAsUser: {{ if $tproxy }} 1337 {{ else }} {{ .ProxyUID | default "1337" }} {{ end }}
              runAsNonRoot: true
            {{- end }}
            {{- if .Values.global.proxy.seccompProfile }}
              seccompProfile:
            {{- toYaml .Values.global.proxy.seccompProfile | nindent 8 }}
            {{- end }}
          {{ end -}}
          {{ end -}}
          {{ if not $nativeSidecar }}
          containers:
          {{ end }}
          - name: istio-proxy
          {{- if contains "/" (annotation .ObjectMeta `sidecar.istio.io/proxyImage` .Values.global.proxy.image) }}
            image: "{{ annotation .ObjectMeta `sidecar.istio.io/proxyImage` .Values.global.proxy.image }}"
          {{- else }}
            image: "{{ .ProxyImage }}"
          {{- end }}
            {{ if $nativeSidecar }}restartPolicy: Always{{end}}
            ports:
            - containerPort: 15090
              protocol: TCP
              name: http-envoy-prom
            args:
            - proxy
            - sidecar
            - --domain
            - $(POD_NAMESPACE).svc.{{ .Values.global.proxy.clusterDomain }}
            - --proxyLogLevel={{ annotation .ObjectMeta `sidecar.istio.io/logLevel` .Values.global.proxy.logLevel }}
            - --proxyComponentLogLevel={{ annotation .ObjectMeta `sidecar.istio.io/componentLogLevel` .Values.global.proxy.componentLogLevel }}
            - --log_output_level={{ annotation .ObjectMeta `sidecar.istio.io/agentLogLevel` .Values.global.logging.level }}
          {{- if .Values.global.sts.servicePort }}
            - --stsPort={{ .Values.global.sts.servicePort }}
          {{- end }}
          {{- if .Values.global.logAsJson }}
            - --log_as_json
          {{- end }}
          {{- if .Values.global.proxy.outlierLogPath }}
            - --outlierLogPath={{ .Values.global.proxy.outlierLogPath }}
          {{- end}}
          {{- if .Values.global.proxy.lifecycle }}
            lifecycle:
              {{ toYaml .Values.global.proxy.lifecycle | indent 6 }}
          {{- else if $holdProxy }}
            lifecycle:
              postStart:
                exec:
                  command:
                  - pilot-agent
                  - wait
          {{- else if $nativeSidecar }}
            {{- /* preStop is called when the pod starts shutdown. Initialize drain. We will get SIGTERM once applications are torn down. */}}
            lifecycle:
              preStop:
                exec:
                  command:
                  - pilot-agent
                  - request
                  - --debug-port={{(annotation .ObjectMeta `status.sidecar.istio.io/port` .Values.global.proxy.statusPort)}}
                  - POST
                  - drain
          {{- end }}
            env:
            {{- if eq .InboundTrafficPolicyMode "localhost" }}
            - name: REWRITE_PROBE_LEGACY_LOCALHOST_DESTINATION
              value: "true"
            {{- end }}
            - name: PILOT_CERT_PROVIDER
              value: {{ .Values.global.pilotCertProvider }}
            - name: CA_ADDR
            {{- if .Values.global.caAddress }}
              value: {{ .Values.global.caAddress }}
            {{- else }}
              value: istiod{{- if not (eq .Values.revision "") }}-{{ .Values.revision }}{{- end }}.{{ .Values.global.istioNamespace }}.svc:15012
            {{- end }}
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: INSTANCE_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: SERVICE_ACCOUNT
              valueFrom:
                fieldRef:
                  fieldPath: spec.serviceAccountName
            - name: HOST_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.hostIP
            - name: ISTIO_CPU_LIMIT
              valueFrom:
                resourceFieldRef:
                  resource: limits.cpu
                  divisor: "1"
            - name: PROXY_CONFIG
              value: |
                     {{ protoToJSON .ProxyConfig }}
            - name: ISTIO_META_POD_PORTS
              value: |-
                [
                {{- $first := true }}
                {{- range $index1, $c := .Spec.Containers }}
                  {{- range $index2, $p := $c.Ports }}
                    {{- if (structToJSON $p) }}
                    {{if not $first}},{{end}}{{ structToJSON $p }}
                    {{- $first = false }}
                    {{- end }}
                  {{- end}}
                {{- end}}
                ]
            - name: ISTIO_META_APP_CONTAINERS
              value: "{{ $containers | join "," }}"
            - name: GOMEMLIMIT
              valueFrom:
                resourceFieldRef:
                  resource: limits.memory
                  divisor: "1"
            - name: GOMAXPROCS
              valueFrom:
                resourceFieldRef:
                  resource: limits.cpu
                  divisor: "1"
            {{- if .CompliancePolicy }}
            - name: COMPLIANCE_POLICY
              value: "{{ .CompliancePolicy }}"
            {{- end }}
            - name: ISTIO_META_CLUSTER_ID
              value: "{{ valueOrDefault .Values.global.multiCluster.clusterName `Kubernetes` }}"
            - name: ISTIO_META_NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: ISTIO_META_INTERCEPTION_MODE
              value: "{{ or (index .ObjectMeta.Annotations `sidecar.istio.io/interceptionMode`) .ProxyConfig.InterceptionMode.String }}"
            {{- if .Values.global.network }}
            - name: ISTIO_META_NETWORK
              value: "{{ .Values.global.network }}"
            {{- end }}
            {{- with (index .ObjectMeta.Labels `service.istio.io/workload-name` | default .DeploymentMeta.Name) }}
            - name: ISTIO_META_WORKLOAD_NAME
              value: "{{ . }}"
            {{ end }}
            {{- if and .TypeMeta.APIVersion .DeploymentMeta.Name }}
            - name: ISTIO_META_OWNER
              value: kubernetes://apis/{{ .TypeMeta.APIVersion }}/namespaces/{{ valueOrDefault .DeploymentMeta.Namespace `default` }}/{{ toLower .TypeMeta.Kind}}s/{{ .DeploymentMeta.Name }}
            {{- end}}
            {{- if (isset .ObjectMeta.Annotations `sidecar.istio.io/bootstrapOverride`) }}
            - name: ISTIO_BOOTSTRAP_OVERRIDE
              value: "/etc/istio/custom-bootstrap/custom_bootstrap.json"
            {{- end }}
            {{- if .Values.global.meshID }}
            - name: ISTIO_META_MESH_ID
              value: "{{ .Values.global.meshID }}"
            {{- else if (valueOrDefault .MeshConfig.TrustDomain .Values.global.trustDomain) }}
            - name: ISTIO_META_MESH_ID
              value: "{{ (valueOrDefault .MeshConfig.TrustDomain .Values.global.trustDomain) }}"
            {{- end }}
            {{- with (valueOrDefault .MeshConfig.TrustDomain .Values.global.trustDomain)  }}
            - name: TRUST_DOMAIN
              value: "{{ . }}"
            {{- end }}
            {{- if and (eq .Values.global.proxy.tracer "datadog") (isset .ObjectMeta.Annotations `apm.datadoghq.com/env`) }}
            {{- range $key, $value := fromJSON (index .ObjectMeta.Annotations `apm.datadoghq.com/env`) }}
            - name: {{ $key }}
              value: "{{ $value }}"
            {{- end }}
            {{- end }}
            {{- $otelResAttrs := otelResourceAttributes .MeshConfig .ObjectMeta.Annotations .ObjectMeta.Labels .DeploymentMeta.Namespace .Spec.Containers }}
            {{- if $otelResAttrs }}
            - name: OTEL_RESOURCE_ATTRIBUTES
              value: "{{ $otelResAttrs }}"
            {{- end }}
            {{- range $key, $value := .ProxyConfig.ProxyMetadata }}
            - name: {{ $key }}
              value: "{{ $value }}"
            {{- end }}
            {{with .Values.global.imagePullPolicy }}imagePullPolicy: "{{.}}"{{end}}
            {{ if ne (annotation .ObjectMeta `status.sidecar.istio.io/port` .Values.global.proxy.statusPort) `0` }}
          {{ if .Values.global.proxy.startupProbe.enabled }}
            startupProbe:
              httpGet:
                path: /healthz/ready
                port: 15021
              initialDelaySeconds: 0
              periodSeconds: 1
              timeoutSeconds: 3
              failureThreshold: {{ .Values.global.proxy.startupProbe.failureThreshold }}
          {{ end }}
            readinessProbe:
              httpGet:
                path: /healthz/ready
                port: 15021
              initialDelaySeconds: {{ annotation .ObjectMeta `readiness.status.sidecar.istio.io/initialDelaySeconds` .Values.global.proxy.readinessInitialDelaySeconds }}
              periodSeconds: {{ annotation .ObjectMeta `readiness.status.sidecar.istio.io/periodSeconds` .Values.global.proxy.readinessPeriodSeconds }}
              timeoutSeconds: 3
              failureThreshold: {{ annotation .ObjectMeta `readiness.status.sidecar.istio.io/failureThreshold` .Values.global.proxy.readinessFailureThreshold }}
            {{ end -}}
            securityContext:
              {{- if eq (index .ProxyConfig.ProxyMetadata "IPTABLES_TRACE_LOGGING") "true" }}
              allowPrivilegeEscalation: true
              capabilities:
                add:
                - NET_ADMIN
                drop:
                - ALL
              privileged: true
              readOnlyRootFilesystem: true
              runAsGroup: {{ .ProxyGID | default "1337" }}
              runAsNonRoot: false
              runAsUser: 0
              {{- else }}
              allowPrivilegeEscalation: {{ .Values.global.proxy.privileged }}
              capabilities:
                {{ if or $tproxy $capNetBindService -}}
                add:
                {{ if $tproxy -}}
                - NET_ADMIN
                {{- end }}
                {{ if $capNetBindService -}}
                - NET_BIND_SERVICE
                {{- end }}
                {{- end }}
                drop:
                - ALL
              privileged: {{ .Values.global.proxy.privileged }}
              readOnlyRootFilesystem: true
              {{ if or $tproxy $capNetBindService -}}
              runAsNonRoot: false
              runAsUser: 0
              runAsGroup: 1337
              {{- else -}}
              runAsNonRoot: true
              runAsUser: {{ .ProxyUID | default "1337" }}
              runAsGroup: {{ .ProxyGID | default "1337" }}
              {{- end }}
              {{- end }}
            {{- if .Values.global.proxy.seccompProfile }}
              seccompProfile:
            {{- toYaml .Values.global.proxy.seccompProfile | nindent 8 }}
            {{- end }}
            resources:
          {{ template "resources" . }}
            volumeMounts:
            - name: workload-socket
              mountPath: /var/run/secrets/workload-spiffe-uds
            - name: credential-socket
              mountPath: /var/run/secrets/credential-uds
            {{- if eq .Values.global.caName "GkeWorkloadCertificate" }}
            - name: gke-workload-certificate
              mountPath: /var/run/secrets/workload-spiffe-credentials
              readOnly: true
            {{- else }}
            - name: workload-certs
              mountPath: /var/run/secrets/workload-spiffe-credentials
            {{- end }}
            {{- if eq .Values.global.pilotCertProvider "istiod" }}
            - mountPath: /var/run/secrets/istio
              name: istiod-ca-cert
            - mountPath: /var/run/secrets/istio/crl
              name: istio-ca-crl
            {{- end }}
            - mountPath: /var/lib/istio/data
              name: istio-data
            {{ if (isset .ObjectMeta.Annotations `sidecar.istio.io/bootstrapOverride`) }}
            - mountPath: /etc/istio/custom-bootstrap
              name: custom-bootstrap-volume
            {{- end }}
            # SDS channel between istioagent and Envoy
            - mountPath: /etc/istio/proxy
              name: istio-envoy
            - mountPath: /var/run/secrets/tokens
              name: istio-token
            {{- if .Values.global.mountMtlsCerts }}
            # Use the key and cert mounted to /etc/certs/ for the in-cluster mTLS communications.
            - mountPath: /etc/certs/
              name: istio-certs
              readOnly: true
            {{- end }}
            - name: istio-podinfo
              mountPath: /etc/istio/pod
             {{- if and (eq .Values.global.proxy.tracer "lightstep") .ProxyConfig.GetTracing.GetTlsSettings }}
            - mountPath: {{ directory .ProxyConfig.GetTracing.GetTlsSettings.GetCaCertificates }}
              name: lightstep-certs
              readOnly: true
            {{- end }}
              {{- if isset .ObjectMeta.Annotations `sidecar.istio.io/userVolumeMount` }}
              {{ range $index, $value := fromJSON (index .ObjectMeta.Annotations `sidecar.istio.io/userVolumeMount`) }}
            - name: "{{  $index }}"
              {{ toYaml $value | indent 6 }}
              {{ end }}
              {{- end }}
          volumes:
          - emptyDir:
            name: workload-socket
          - emptyDir:
            name: credential-socket
          {{- if eq .Values.global.caName "GkeWorkloadCertificate" }}
          - name: gke-workload-certificate
            csi:
              driver: workloadcertificates.security.cloud.google.com
          {{- else }}
          - emptyDir:
            name: workload-certs
          {{- end }}
          {{- if (isset .ObjectMeta.Annotations `sidecar.istio.io/bootstrapOverride`) }}
          - name: custom-bootstrap-volume
            configMap:
              name: {{ annotation .ObjectMeta `sidecar.istio.io/bootstrapOverride` "" }}
          {{- end }}
          # SDS channel between istioagent and Envoy
          - emptyDir:
              medium: Memory
            name: istio-envoy
          - name: istio-data
            emptyDir: {}
          - name: istio-podinfo
            downwardAPI:
              items:
                - path: "labels"
                  fieldRef:
                    fieldPath: metadata.labels
                - path: "annotations"
                  fieldRef:
                    fieldPath: metadata.annotations
          - name: istio-token
            projected:
              sources:
              - serviceAccountToken:
                  path: istio-token
                  expirationSeconds: 43200
                  audience: {{ .Values.global.sds.token.aud }}
          {{- if eq .Values.global.pilotCertProvider "istiod" }}
          - name: istiod-ca-cert
          {{- if eq (.Values.pilot.env).ENABLE_CLUSTER_TRUST_BUNDLE_API true }}
            projected:
              sources:
              - clusterTrustBundle:
                  name: istio.io:istiod-ca:{{ .Values.global.trustBundleName | default "root-cert" }}
                  path: root-cert.pem
          {{- else }}
            configMap:
              name: {{ .Values.global.trustBundleName | default "istio-ca-root-cert" }}
          {{- end }}
          {{- end }}
          - name: istio-ca-crl
            configMap:
              name: {{ .Values.pilot.crlConfigMapName | default "istio-ca-crl" }}
              optional: true
          {{- if .Values.global.mountMtlsCerts }}
          # Use the key and cert mounted to /etc/certs/ for the in-cluster mTLS communications.
          - name: istio-certs
            secret:
              optional: true
              {{ if eq .Spec.ServiceAccountName "" }}
              secretName: istio.default
              {{ else -}}
              secretName: {{  printf "istio.%s" .Spec.ServiceAccountName }}
              {{  end -}}
          {{- end }}
            {{- if isset .ObjectMeta.Annotations `sidecar.istio.io/userVolume` }}
            {{range $index, $value := fromJSON (index .ObjectMeta.Annotations `sidecar.istio.io/userVolume`) }}
          - name: "{{ $index }}"
            {{ toYaml $value | indent 4 }}
            {{ end }}
            {{ end }}
          {{- if and (eq .Values.global.proxy.tracer "lightstep") .ProxyConfig.GetTracing.GetTlsSettings }}
          - name: lightstep-certs
            secret:
              optional: true
              secretName: lightstep.cacert
          {{- end }}
          {{- if .Values.global.imagePullSecrets }}
          imagePullSecrets:
            {{- range .Values.global.imagePullSecrets }}
            - name: {{ . }}
            {{- end }}
          {{- end }}
      gateway: |
        {{- $containers := list }}
        {{- range $index, $container := .Spec.Containers }}{{ if not (eq $container.Name "istio-proxy") }}{{ $containers = append $containers $container.Name }}{{end}}{{- end}}
        metadata:
          labels:
            service.istio.io/canonical-name: {{ index .ObjectMeta.Labels `service.istio.io/canonical-name` | default (index .ObjectMeta.Labels `app.kubernetes.io/name`) | default (index .ObjectMeta.Labels `app`) | default .DeploymentMeta.Name  | quote }}
            service.istio.io/canonical-revision: {{ index .ObjectMeta.Labels `service.istio.io/canonical-revision` | default (index .ObjectMeta.Labels `app.kubernetes.io/version`) | default (index .ObjectMeta.Labels `version`) | default "latest"  | quote }}
          annotations:
            istio.io/rev: {{ .Revision | default "default" | quote }}
            {{- if ge (len $containers) 1 }}
            {{- if not (isset .ObjectMeta.Annotations `kubectl.kubernetes.io/default-logs-container`) }}
            kubectl.kubernetes.io/default-logs-container: "{{ index $containers 0 }}"
            {{- end }}
            {{- if not (isset .ObjectMeta.Annotations `kubectl.kubernetes.io/default-container`) }}
            kubectl.kubernetes.io/default-container: "{{ index $containers 0 }}"
            {{- end }}
            {{- end }}
        spec:
          securityContext:
          {{- if .Values.gateways.securityContext }}
            {{- toYaml .Values.gateways.securityContext | nindent 4 }}
          {{- else }}
            sysctls:
            - name: net.ipv4.ip_unprivileged_port_start
              value: "0"
          {{- end }}
          containers:
          - name: istio-proxy
          {{- if contains "/" (annotation .ObjectMeta `sidecar.istio.io/proxyImage` .Values.global.proxy.image) }}
            image: "{{ annotation .ObjectMeta `sidecar.istio.io/proxyImage` .Values.global.proxy.image }}"
          {{- else }}
            image: "{{ .ProxyImage }}"
          {{- end }}
            ports:
            - containerPort: 15090
              protocol: TCP
              name: http-envoy-prom
            args:
            - proxy
            - router
            - --domain
            - $(POD_NAMESPACE).svc.{{ .Values.global.proxy.clusterDomain }}
            - --proxyLogLevel={{ annotation .ObjectMeta `sidecar.istio.io/logLevel` .Values.global.proxy.logLevel }}
            - --proxyComponentLogLevel={{ annotation .ObjectMeta `sidecar.istio.io/componentLogLevel` .Values.global.proxy.componentLogLevel }}
            - --log_output_level={{ annotation .ObjectMeta `sidecar.istio.io/agentLogLevel` .Values.global.logging.level }}
          {{- if .Values.global.sts.servicePort }}
            - --stsPort={{ .Values.global.sts.servicePort }}
          {{- end }}
          {{- if .Values.global.logAsJson }}
            - --log_as_json
          {{- end }}
          {{- if .Values.global.proxy.lifecycle }}
            lifecycle:
              {{ toYaml .Values.global.proxy.lifecycle | indent 6 }}
          {{- end }}
            securityContext:
              runAsUser: {{ .ProxyUID | default "1337" }}
              runAsGroup: {{ .ProxyGID | default "1337" }}
            env:
            - name: PILOT_CERT_PROVIDER
              value: {{ .Values.global.pilotCertProvider }}
            - name: CA_ADDR
            {{- if .Values.global.caAddress }}
              value: {{ .Values.global.caAddress }}
            {{- else }}
              value: istiod{{- if not (eq .Values.revision "") }}-{{ .Values.revision }}{{- end }}.{{ .Values.global.istioNamespace }}.svc:15012
            {{- end }}
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: INSTANCE_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: SERVICE_ACCOUNT
              valueFrom:
                fieldRef:
                  fieldPath: spec.serviceAccountName
            - name: HOST_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.hostIP
            - name: ISTIO_CPU_LIMIT
              valueFrom:
                resourceFieldRef:
                  resource: limits.cpu
                  divisor: "1"
            - name: PROXY_CONFIG
              value: |
                     {{ protoToJSON .ProxyConfig }}
            - name: ISTIO_META_POD_PORTS
              value: |-
                [
                {{- $first := true }}
                {{- range $index1, $c := .Spec.Containers }}
                  {{- range $index2, $p := $c.Ports }}
                    {{- if (structToJSON $p) }}
                    {{if not $first}},{{end}}{{ structToJSON $p }}
                    {{- $first = false }}
                    {{- end }}
                  {{- end}}
                {{- end}}
                ]
            - name: GOMEMLIMIT
              valueFrom:
                resourceFieldRef:
                  resource: limits.memory
                  divisor: "1"
            - name: GOMAXPROCS
              valueFrom:
                resourceFieldRef:
                  resource: limits.cpu
                  divisor: "1"
            {{- if .CompliancePolicy }}
            - name: COMPLIANCE_POLICY
              value: "{{ .CompliancePolicy }}"
            {{- end }}
            - name: ISTIO_META_APP_CONTAINERS
              value: "{{ $containers | join "," }}"
            - name: ISTIO_META_CLUSTER_ID
              value: "{{ valueOrDefault .Values.global.multiCluster.clusterName `Kubernetes` }}"
            - name: ISTIO_META_NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: ISTIO_META_INTERCEPTION_MODE
              value: "{{ .ProxyConfig.InterceptionMode.String }}"
            {{- if .Values.global.network }}
            - name: ISTIO_META_NETWORK
              value: "{{ .Values.global.network }}"
            {{- end }}
            {{- if .DeploymentMeta.Name }}
            - name: ISTIO_META_WORKLOAD_NAME
              value: "{{ .DeploymentMeta.Name }}"
            {{ end }}
            {{- if and .TypeMeta.APIVersion .DeploymentMeta.Name }}
            - name: ISTIO_META_OWNER
              value: kubernetes://apis/{{ .TypeMeta.APIVersion }}/namespaces/{{ valueOrDefault .DeploymentMeta.Namespace `default` }}/{{ toLower .TypeMeta.Kind}}s/{{ .DeploymentMeta.Name }}
            {{- end}}
            {{- if (isset .ObjectMeta.Annotations `sidecar.istio.io/bootstrapOverride`) }}
            - name: ISTIO_BOOTSTRAP_OVERRIDE
              value: "/etc/istio/custom-bootstrap/custom_bootstrap.json"
            {{- end }}
            {{- if .Values.global.meshID }}
            - name: ISTIO_META_MESH_ID
              value: "{{ .Values.global.meshID }}"
            {{- else if (valueOrDefault .MeshConfig.TrustDomain .Values.global.trustDomain) }}
            - name: ISTIO_META_MESH_ID
              value: "{{ (valueOrDefault .MeshConfig.TrustDomain .Values.global.trustDomain) }}"
            {{- end }}
            {{- with (valueOrDefault .MeshConfig.TrustDomain .Values.global.trustDomain)  }}
            - name: TRUST_DOMAIN
              value: "{{ . }}"
            {{- end }}
            {{- range $key, $value := .ProxyConfig.ProxyMetadata }}
            - name: {{ $key }}
              value: "{{ $value }}"
            {{- end }}
            {{with .Values.global.imagePullPolicy }}imagePullPolicy: "{{.}}"{{end}}
            readinessProbe:
              httpGet:
                path: /healthz/ready
                port: 15021
              initialDelaySeconds: {{.Values.global.proxy.readinessInitialDelaySeconds }}
              periodSeconds: {{ .Values.global.proxy.readinessPeriodSeconds }}
              timeoutSeconds: 3
              failureThreshold: {{ .Values.global.proxy.readinessFailureThreshold }}
            volumeMounts:
            - name: workload-socket
              mountPath: /var/run/secrets/workload-spiffe-uds
            - name: credential-socket
              mountPath: /var/run/secrets/credential-uds
            {{- if eq .Values.global.caName "GkeWorkloadCertificate" }}
            - name: gke-workload-certificate
              mountPath: /var/run/secrets/workload-spiffe-credentials
              readOnly: true
            {{- else }}
            - name: workload-certs
              mountPath: /var/run/secrets/workload-spiffe-credentials
            {{- end }}
            {{- if eq .Values.global.pilotCertProvider "istiod" }}
            - mountPath: /var/run/secrets/istio
              name: istiod-ca-cert
            {{- end }}
            - mountPath: /var/lib/istio/data
              name: istio-data
            {{ if (isset .ObjectMeta.Annotations `sidecar.istio.io/bootstrapOverride`) }}
            - mountPath: /etc/istio/custom-bootstrap
              name: custom-bootstrap-volume
            {{- end }}
            # SDS channel between istioagent and Envoy
            - mountPath: /etc/istio/proxy
              name: istio-envoy
            - mountPath: /var/run/secrets/tokens
              name: istio-token
            {{- if .Values.global.mountMtlsCerts }}
            # Use the key and cert mounted to /etc/certs/ for the in-cluster mTLS communications.
            - mountPath: /etc/certs/
              name: istio-certs
              readOnly: true
            {{- end }}
            - name: istio-podinfo
              mountPath: /etc/istio/pod
          volumes:
          - emptyDir:
            name: workload-socket
          - emptyDir: {}
            name: credential-socket
          {{- if eq .Values.global.caName "GkeWorkloadCertificate" }}
          - name: gke-workload-certificate
            csi:
              driver: workloadcertificates.security.cloud.google.com
          {{- else}}
          - emptyDir: {}
            name: workload-certs
          {{- end }}
          {{- if (isset .ObjectMeta.Annotations `sidecar.istio.io/bootstrapOverride`) }}
          - name: custom-bootstrap-volume
            configMap:
              name: {{ annotation .ObjectMeta `sidecar.istio.io/bootstrapOverride` "" }}
          {{- end }}
          # SDS channel between istioagent and Envoy
          - emptyDir:
              medium: Memory
            name: istio-envoy
          - name: istio-data
            emptyDir: {}
          - name: istio-podinfo
            downwardAPI:
              items:
                - path: "labels"
                  fieldRef:
                    fieldPath: metadata.labels
                - path: "annotations"
                  fieldRef:
                    fieldPath: metadata.annotations
          - name: istio-token
            projected:
              sources:
              - serviceAccountToken:
                  path: istio-token
                  expirationSeconds: 43200
                  audience: {{ .Values.global.sds.token.aud }}
          {{- if eq .Values.global.pilotCertProvider "istiod" }}
          - name: istiod-ca-cert
          {{- if eq (.Values.pilot.env).ENABLE_CLUSTER_TRUST_BUNDLE_API true }}
            projected:
              sources:
              - clusterTrustBundle:
                  name: istio.io:istiod-ca:{{ .Values.global.trustBundleName | default "root-cert" }}
                  path: root-cert.pem
          {{- else }}
            configMap:
              name: {{ .Values.global.trustBundleName | default "istio-ca-root-cert" }}
          {{- end }}
          {{- end }}
          {{- if .Values.global.mountMtlsCerts }}
          # Use the key and cert mounted to /etc/certs/ for the in-cluster mTLS communications.
          - name: istio-certs
            secret:
              optional: true
              {{ if eq .Spec.ServiceAccountName "" }}
              secretName: istio.default
              {{ else -}}
              secretName: {{  printf "istio.%s" .Spec.ServiceAccountName }}
              {{  end -}}
          {{- end }}
          {{- if .Values.global.imagePullSecrets }}
          imagePullSecrets:
            {{- range .Values.global.imagePullSecrets }}
            - name: {{ . }}
            {{- end }}
          {{- end }}
      grpc-simple: |
        metadata:
          annotations:
            sidecar.istio.io/rewriteAppHTTPProbers: "false"
        spec:
          initContainers:
            - name: grpc-bootstrap-init
              image: busybox:1.28
              volumeMounts:
                - mountPath: /var/lib/grpc/data/
                  name: grpc-io-proxyless-bootstrap
              env:
                - name: INSTANCE_IP
                  valueFrom:
                    fieldRef:
                      fieldPath: status.podIP
                - name: POD_NAME
                  valueFrom:
                    fieldRef:
                      fieldPath: metadata.name
                - name: POD_NAMESPACE
                  valueFrom:
                    fieldRef:
                      fieldPath: metadata.namespace
                - name: ISTIO_NAMESPACE
                  value: |
                     {{ .Values.global.istioNamespace }}
              command:
                - sh
                - "-c"
                - |-
                  NODE_ID="sidecar~${INSTANCE_IP}~${POD_NAME}.${POD_NAMESPACE}~cluster.local"
                  SERVER_URI="dns:///istiod.${ISTIO_NAMESPACE}.svc:15010"
                  echo '
                  {
                    "xds_servers": [
                      {
                        "server_uri": "'${SERVER_URI}'",
                        "channel_creds": [{"type": "insecure"}],
                        "server_features" : ["xds_v3"]
                      }
                    ],
                    "node": {
                      "id": "'${NODE_ID}'",
                      "metadata": {
                        "GENERATOR": "grpc"
                      }
                    }
                  }' > /var/lib/grpc/data/bootstrap.json
          containers:
          {{- range $index, $container := .Spec.Containers }}
          - name: {{ $container.Name }}
            env:
              - name: GRPC_XDS_BOOTSTRAP
                value: /var/lib/grpc/data/bootstrap.json
              - name: GRPC_GO_LOG_VERBOSITY_LEVEL
                value: "99"
              - name: GRPC_GO_LOG_SEVERITY_LEVEL
                value: info
            volumeMounts:
              - mountPath: /var/lib/grpc/data/
                name: grpc-io-proxyless-bootstrap
          {{- end }}
          volumes:
            - name: grpc-io-proxyless-bootstrap
              emptyDir: {}
      grpc-agent: |
        {{- define "resources"  }}
          {{- if or (isset .ObjectMeta.Annotations `sidecar.istio.io/proxyCPU`) (isset .ObjectMeta.Annotations `sidecar.istio.io/proxyMemory`) (isset .ObjectMeta.Annotations `sidecar.istio.io/proxyCPULimit`) (isset .ObjectMeta.Annotations `sidecar.istio.io/proxyMemoryLimit`) }}
            {{- if or (isset .ObjectMeta.Annotations `sidecar.istio.io/proxyCPU`) (isset .ObjectMeta.Annotations `sidecar.istio.io/proxyMemory`) }}
              requests:
                {{ if (isset .ObjectMeta.Annotations `sidecar.istio.io/proxyCPU`) -}}
                cpu: {{ index .ObjectMeta.Annotations `sidecar.istio.io/proxyCPU` | quote }}
                {{ end }}
                {{ if (isset .ObjectMeta.Annotations `sidecar.istio.io/proxyMemory`) -}}
                memory: {{ index .ObjectMeta.Annotations `sidecar.istio.io/proxyMemory` | quote }}
                {{ end }}
            {{- end }}
            {{- if or (isset .ObjectMeta.Annotations `sidecar.istio.io/proxyCPULimit`) (isset .ObjectMeta.Annotations `sidecar.istio.io/proxyMemoryLimit`) }}
              limits:
                {{ if (isset .ObjectMeta.Annotations `sidecar.istio.io/proxyCPULimit`) -}}
                cpu: {{ index .ObjectMeta.Annotations `sidecar.istio.io/proxyCPULimit` | quote }}
                {{ end }}
                {{ if (isset .ObjectMeta.Annotations `sidecar.istio.io/proxyMemoryLimit`) -}}
                memory: {{ index .ObjectMeta.Annotations `sidecar.istio.io/proxyMemoryLimit` | quote }}
                {{ end }}
            {{- end }}
          {{- else }}
            {{- if .Values.global.proxy.resources }}
              {{ toYaml (omitNil .Values.global.proxy.resources) | indent 6 }}
            {{- end }}
          {{- end }}
        {{- end }}
        {{- $containers := list }}
        {{- range $index, $container := .Spec.Containers }}{{ if not (eq $container.Name "istio-proxy") }}{{ $containers = append $containers $container.Name }}{{end}}{{- end}}
        metadata:
          labels:
            {{/* security.istio.io/tlsMode: istio must be set by user, if gRPC is using mTLS initialization code. We can't set it automatically. */}}
            service.istio.io/canonical-name: {{ index .ObjectMeta.Labels `service.istio.io/canonical-name` | default (index .ObjectMeta.Labels `app.kubernetes.io/name`) | default (index .ObjectMeta.Labels `app`) | default .DeploymentMeta.Name  | quote }}
            service.istio.io/canonical-revision: {{ index .ObjectMeta.Labels `service.istio.io/canonical-revision` | default (index .ObjectMeta.Labels `app.kubernetes.io/version`) | default (index .ObjectMeta.Labels `version`) | default "latest"  | quote }}
          annotations: {
            istio.io/rev: {{ .Revision | default "default" | quote }},
            {{- if ge (len $containers) 1 }}
            {{- if not (isset .ObjectMeta.Annotations `kubectl.kubernetes.io/default-logs-container`) }}
            kubectl.kubernetes.io/default-logs-container: "{{ index $containers 0 }}",
            {{- end }}
            {{- if not (isset .ObjectMeta.Annotations `kubectl.kubernetes.io/default-container`) }}
            kubectl.kubernetes.io/default-container: "{{ index $containers 0 }}",
            {{- end }}
            {{- end }}
            sidecar.istio.io/rewriteAppHTTPProbers: "false",
          }
        spec:
          containers:
          - name: istio-proxy
          {{- if contains "/" (annotation .ObjectMeta `sidecar.istio.io/proxyImage` .Values.global.proxy.image) }}
            image: "{{ annotation .ObjectMeta `sidecar.istio.io/proxyImage` .Values.global.proxy.image }}"
          {{- else }}
            image: "{{ .ProxyImage }}"
          {{- end }}
            ports:
            - containerPort: 15020
              protocol: TCP
              name: mesh-metrics
            args:
            - proxy
            - sidecar
            - --domain
            - $(POD_NAMESPACE).svc.{{ .Values.global.proxy.clusterDomain }}
            - --proxyLogLevel={{ annotation .ObjectMeta `sidecar.istio.io/logLevel` .Values.global.proxy.logLevel }}
            - --proxyComponentLogLevel={{ annotation .ObjectMeta `sidecar.istio.io/componentLogLevel` .Values.global.proxy.componentLogLevel }}
            - --log_output_level={{ annotation .ObjectMeta `sidecar.istio.io/agentLogLevel` .Values.global.logging.level }}
          {{- if .Values.global.sts.servicePort }}
            - --stsPort={{ .Values.global.sts.servicePort }}
          {{- end }}
          {{- if .Values.global.logAsJson }}
            - --log_as_json
          {{- end }}
            lifecycle:
              postStart:
                exec:
                  command:
                  - pilot-agent
                  - wait
                  - --url=http://localhost:15020/healthz/ready
            env:
            - name: ISTIO_META_GENERATOR
              value: grpc
            - name: OUTPUT_CERTS
              value: /var/lib/istio/data
            {{- if eq .InboundTrafficPolicyMode "localhost" }}
            - name: REWRITE_PROBE_LEGACY_LOCALHOST_DESTINATION
              value: "true"
            {{- end }}
            - name: PILOT_CERT_PROVIDER
              value: {{ .Values.global.pilotCertProvider }}
            - name: CA_ADDR
            {{- if .Values.global.caAddress }}
              value: {{ .Values.global.caAddress }}
            {{- else }}
              value: istiod{{- if not (eq .Values.revision "") }}-{{ .Values.revision }}{{- end }}.{{ .Values.global.istioNamespace }}.svc:15012
            {{- end }}
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: INSTANCE_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: SERVICE_ACCOUNT
              valueFrom:
                fieldRef:
                  fieldPath: spec.serviceAccountName
            - name: HOST_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.hostIP
            - name: PROXY_CONFIG
              value: |
                     {{ protoToJSON .ProxyConfig }}
            - name: ISTIO_META_POD_PORTS
              value: |-
                [
                {{- $first := true }}
                {{- range $index1, $c := .Spec.Containers }}
                  {{- range $index2, $p := $c.Ports }}
                    {{- if (structToJSON $p) }}
                    {{if not $first}},{{end}}{{ structToJSON $p }}
                    {{- $first = false }}
                    {{- end }}
                  {{- end}}
                {{- end}}
                ]
            - name: ISTIO_META_APP_CONTAINERS
              value: "{{ $containers | join "," }}"
            - name: ISTIO_META_CLUSTER_ID
              value: "{{ valueOrDefault .Values.global.multiCluster.clusterName `Kubernetes` }}"
            - name: ISTIO_META_NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            {{- if .Values.global.network }}
            - name: ISTIO_META_NETWORK
              value: "{{ .Values.global.network }}"
            {{- end }}
            {{- if .DeploymentMeta.Name }}
            - name: ISTIO_META_WORKLOAD_NAME
              value: "{{ .DeploymentMeta.Name }}"
            {{ end }}
            {{- if and .TypeMeta.APIVersion .DeploymentMeta.Name }}
            - name: ISTIO_META_OWNER
              value: kubernetes://apis/{{ .TypeMeta.APIVersion }}/namespaces/{{ valueOrDefault .DeploymentMeta.Namespace `default` }}/{{ toLower .TypeMeta.Kind}}s/{{ .DeploymentMeta.Name }}
            {{- end}}
            {{- if .Values.global.meshID }}
            - name: ISTIO_META_MESH_ID
              value: "{{ .Values.global.meshID }}"
            {{- else if (valueOrDefault .MeshConfig.TrustDomain .Values.global.trustDomain) }}
            - name: ISTIO_META_MESH_ID
              value: "{{ (valueOrDefault .MeshConfig.TrustDomain .Values.global.trustDomain) }}"
            {{- end }}
            {{- with (valueOrDefault .MeshConfig.TrustDomain .Values.global.trustDomain)  }}
            - name: TRUST_DOMAIN
              value: "{{ . }}"
            {{- end }}
            {{- range $key, $value := .ProxyConfig.ProxyMetadata }}
            - name: {{ $key }}
              value: "{{ $value }}"
            {{- end }}
            # grpc uses xds:/// to resolve – no need to resolve VIP
            - name: ISTIO_META_DNS_CAPTURE
              value: "false"
            - name: DISABLE_ENVOY
              value: "true"
            {{with .Values.global.imagePullPolicy }}imagePullPolicy: "{{.}}"{{end}}
            {{ if ne (annotation .ObjectMeta `status.sidecar.istio.io/port` .Values.global.proxy.statusPort) `0` }}
            readinessProbe:
              httpGet:
                path: /healthz/ready
                port: 15020
              initialDelaySeconds: {{ annotation .ObjectMeta `readiness.status.sidecar.istio.io/initialDelaySeconds` .Values.global.proxy.readinessInitialDelaySeconds }}
              periodSeconds: {{ annotation .ObjectMeta `readiness.status.sidecar.istio.io/periodSeconds` .Values.global.proxy.readinessPeriodSeconds }}
              timeoutSeconds: 3
              failureThreshold: {{ annotation .ObjectMeta `readiness.status.sidecar.istio.io/failureThreshold` .Values.global.proxy.readinessFailureThreshold }}
            resources:
          {{ template "resources" . }}
            volumeMounts:
            - name: workload-socket
              mountPath: /var/run/secrets/workload-spiffe-uds
            {{- if eq .Values.global.caName "GkeWorkloadCertificate" }}
            - name: gke-workload-certificate
              mountPath: /var/run/secrets/workload-spiffe-credentials
              readOnly: true
            {{- else }}
            - name: workload-certs
              mountPath: /var/run/secrets/workload-spiffe-credentials
            {{- end }}
            {{- if eq .Values.global.pilotCertProvider "istiod" }}
            - mountPath: /var/run/secrets/istio
              name: istiod-ca-cert
            {{- end }}
            - mountPath: /var/lib/istio/data
              name: istio-data
            # UDS channel between istioagent and gRPC client for XDS/SDS
            - mountPath: /etc/istio/proxy
              name: istio-xds
            - mountPath: /var/run/secrets/tokens
              name: istio-token
            {{- if .Values.global.mountMtlsCerts }}
            # Use the key and cert mounted to /etc/certs/ for the in-cluster mTLS communications.
            - mountPath: /etc/certs/
              name: istio-certs
              readOnly: true
            {{- end }}
            - name: istio-podinfo
              mountPath: /etc/istio/pod
            {{- end }}
              {{- if isset .ObjectMeta.Annotations `sidecar.istio.io/userVolumeMount` }}
              {{ range $index, $value := fromJSON (index .ObjectMeta.Annotations `sidecar.istio.io/userVolumeMount`) }}
            - name: "{{  $index }}"
              {{ toYaml $value | indent 6 }}
              {{ end }}
              {{- end }}
        {{- range $index, $container := .Spec.Containers  }}
        {{ if not (eq $container.Name "istio-proxy") }}
          - name: {{ $container.Name }}
            env:
              - name: "GRPC_XDS_EXPERIMENTAL_SECURITY_SUPPORT"
                value: "true"
              - name: "GRPC_XDS_BOOTSTRAP"
                value: "/etc/istio/proxy/grpc-bootstrap.json"
            volumeMounts:
              - mountPath: /var/lib/istio/data
                name: istio-data
              # UDS channel between istioagent and gRPC client for XDS/SDS
              - mountPath: /etc/istio/proxy
                name: istio-xds
              {{- if eq $.Values.global.caName "GkeWorkloadCertificate" }}
              - name: gke-workload-certificate
                mountPath: /var/run/secrets/workload-spiffe-credentials
                readOnly: true
              {{- else }}
              - name: workload-certs
                mountPath: /var/run/secrets/workload-spiffe-credentials
              {{- end }}
        {{- end }}
        {{- end }}
          volumes:
          - emptyDir:
            name: workload-socket
          {{- if eq .Values.global.caName "GkeWorkloadCertificate" }}
          - name: gke-workload-certificate
            csi:
              driver: workloadcertificates.security.cloud.google.com
          {{- else }}
          - emptyDir:
            name: workload-certs
          {{- end }}
          {{- if (isset .ObjectMeta.Annotations `sidecar.istio.io/bootstrapOverride`) }}
          - name: custom-bootstrap-volume
            configMap:
              name: {{ annotation .ObjectMeta `sidecar.istio.io/bootstrapOverride` "" }}
          {{- end }}
          # SDS channel between istioagent and Envoy
          - emptyDir:
              medium: Memory
            name: istio-xds
          - name: istio-data
            emptyDir: {}
          - name: istio-podinfo
            downwardAPI:
              items:
                - path: "labels"
                  fieldRef:
                    fieldPath: metadata.labels
                - path: "annotations"
                  fieldRef:
                    fieldPath: metadata.annotations
          - name: istio-token
            projected:
              sources:
              - serviceAccountToken:
                  path: istio-token
                  expirationSeconds: 43200
                  audience: {{ .Values.global.sds.token.aud }}
          {{- if eq .Values.global.pilotCertProvider "istiod" }}
          - name: istiod-ca-cert
          {{- if eq (.Values.pilot.env).ENABLE_CLUSTER_TRUST_BUNDLE_API true }}
            projected:
              sources:
              - clusterTrustBundle:
                  name: istio.io:istiod-ca:{{ .Values.global.trustBundleName | default "root-cert" }}
                  path: root-cert.pem
          {{- else }}
            configMap:
              name: {{ .Values.global.trustBundleName | default "istio-ca-root-cert" }}
          {{- end }}
          {{- end }}
          {{- if .Values.global.mountMtlsCerts }}
          # Use the key and cert mounted to /etc/certs/ for the in-cluster mTLS communications.
          - name: istio-certs
            secret:
              optional: true
              {{ if eq .Spec.ServiceAccountName "" }}
              secretName: istio.default
              {{ else -}}
              secretName: {{  printf "istio.%s" .Spec.ServiceAccountName }}
              {{  end -}}
          {{- end }}
            {{- if isset .ObjectMeta.Annotations `sidecar.istio.io/userVolume` }}
            {{range $index, $value := fromJSON (index .ObjectMeta.Annotations `sidecar.istio.io/userVolume`) }}
          - name: "{{ $index }}"
            {{ toYaml $value | indent 4 }}
            {{ end }}
            {{ end }}
          {{- if .Values.global.imagePullSecrets }}
          imagePullSecrets:
            {{- range .Values.global.imagePullSecrets }}
            - name: {{ . }}
            {{- end }}
          {{- end }}
      waypoint: |
        apiVersion: v1
        kind: ServiceAccount
        metadata:
          name: {{.ServiceAccount | quote}}
          namespace: {{.Namespace | quote}}
          annotations:
            {{- toJsonMap (omit .InfrastructureAnnotations "kubectl.kubernetes.io/last-applied-configuration" "gateway.istio.io/name-override" "gateway.istio.io/service-account" "gateway.istio.io/controller-version") | nindent 4 }}
          labels:
            {{- toJsonMap
              .InfrastructureLabels
              (strdict
                "gateway.networking.k8s.io/gateway-name" .Name
                "gateway.networking.k8s.io/gateway-class-name" .GatewayClass
              ) | nindent 4 }}
          {{- if ge .KubeVersion 128 }}
          # Safe since 1.28: https://github.com/kubernetes/kubernetes/pull/117412
          ownerReferences:
          - apiVersion: gateway.networking.k8s.io/v1
            kind: Gateway
            name: "{{.Name}}"
            uid: "{{.UID}}"
          {{- end }}
        ---
        apiVersion: apps/v1
        kind: Deployment
        metadata:
          name: {{.DeploymentName | quote}}
          namespace: {{.Namespace | quote}}
          annotations:
            {{- toJsonMap (omit .InfrastructureAnnotations "kubectl.kubernetes.io/last-applied-configuration" "gateway.istio.io/name-override" "gateway.istio.io/service-account" "gateway.istio.io/controller-version") | nindent 4 }}
          labels:
            {{- toJsonMap
              .InfrastructureLabels
              (strdict
                "gateway.networking.k8s.io/gateway-name" .Name
                "gateway.networking.k8s.io/gateway-class-name" .GatewayClass
                "gateway.istio.io/managed" .ControllerLabel
              ) | nindent 4 }}
          ownerReferences:
          - apiVersion: gateway.networking.k8s.io/v1
            kind: Gateway
            name: "{{.Name}}"
            uid: "{{.UID}}"
        spec:
          selector:
            matchLabels:
              "{{.GatewayNameLabel}}": "{{.Name}}"
          template:
            metadata:
              annotations:
                {{- toJsonMap
                  (omit .InfrastructureAnnotations "kubectl.kubernetes.io/last-applied-configuration" "gateway.istio.io/name-override" "gateway.istio.io/service-account" "gateway.istio.io/controller-version")
                  (strdict "istio.io/rev" (.Revision | default "default"))
                  (strdict
                    "prometheus.io/path" "/stats/prometheus"
                    "prometheus.io/port" "15020"
                    "prometheus.io/scrape" "true"
                  ) | nindent 8 }}
              labels:
                {{- toJsonMap
                  (strdict
                    "sidecar.istio.io/inject" "false"
                    "istio.io/dataplane-mode" "none"
                    "service.istio.io/canonical-name" .DeploymentName
                    "service.istio.io/canonical-revision" "latest"
                   )
                  .InfrastructureLabels
                  (strdict
                    "gateway.networking.k8s.io/gateway-name" .Name
                    "gateway.networking.k8s.io/gateway-class-name" .GatewayClass
                    "gateway.istio.io/managed" .ControllerLabel
                  ) | nindent 8}}
            spec:
              {{- if .Values.global.waypoint.affinity }}
              affinity:
              {{- toYaml .Values.global.waypoint.affinity | nindent 8 }}
              {{- end }}
              {{- if .Values.global.waypoint.topologySpreadConstraints }}
              topologySpreadConstraints:
              {{- toYaml .Values.global.waypoint.topologySpreadConstraints | nindent 8 }}
              {{- end }}
              {{- if .Values.global.waypoint.nodeSelector }}
              nodeSelector:
              {{- toYaml .Values.global.waypoint.nodeSelector | nindent 8 }}
              {{- end }}
              {{- if .Values.global.waypoint.tolerations }}
              tolerations:
              {{- toYaml .Values.global.waypoint.tolerations | nindent 8 }}
              {{- end }}
              serviceAccountName: {{.ServiceAccount | quote}}
              containers:
              - name: istio-proxy
                ports:
                - containerPort: 15020
                  name: metrics
                  protocol: TCP
                - containerPort: 15021
                  name: status-port
                  protocol: TCP
                - containerPort: 15090
                  protocol: TCP
                  name: http-envoy-prom
                {{- if contains "/" (annotation .ObjectMeta `sidecar.istio.io/proxyImage` .Values.global.proxy.image) }}
                image: "{{ annotation .ObjectMeta `sidecar.istio.io/proxyImage` .Values.global.proxy.image }}"
                {{- else }}
                image: "{{ .ProxyImage }}"
                {{- end }}
                {{with .Values.global.imagePullPolicy }}imagePullPolicy: "{{.}}"{{end}}
                args:
                - proxy
                - waypoint
                - --domain
                - $(POD_NAMESPACE).svc.{{ .Values.global.proxy.clusterDomain }}
                - --serviceCluster
                - {{.ServiceAccount}}.$(POD_NAMESPACE)
                - --proxyLogLevel
                - {{ annotation .ObjectMeta `sidecar.istio.io/logLevel` .Values.global.proxy.logLevel | quote}}
                - --proxyComponentLogLevel
                - {{ annotation .ObjectMeta `sidecar.istio.io/componentLogLevel` .Values.global.proxy.componentLogLevel | quote}}
                - --log_output_level
                - {{ annotation .ObjectMeta `sidecar.istio.io/agentLogLevel` .Values.global.logging.level | quote}}
                {{- if .Values.global.logAsJson }}
                - --log_as_json
                {{- end }}
                {{- if .Values.global.proxy.outlierLogPath }}
                - --outlierLogPath={{ .Values.global.proxy.outlierLogPath }}
                {{- end}}
                env:
                - name: ISTIO_META_SERVICE_ACCOUNT
                  valueFrom:
                    fieldRef:
                      fieldPath: spec.serviceAccountName
                - name: ISTIO_META_NODE_NAME
                  valueFrom:
                    fieldRef:
                      fieldPath: spec.nodeName
                - name: PILOT_CERT_PROVIDER
                  value: {{ .Values.global.pilotCertProvider }}
                - name: CA_ADDR
                {{- if .Values.global.caAddress }}
                  value: {{ .Values.global.caAddress }}
                {{- else }}
                  value: istiod{{- if not (eq .Values.revision "") }}-{{ .Values.revision }}{{- end }}.{{ .Values.global.istioNamespace }}.svc:15012
                {{- end }}
                - name: POD_NAME
                  valueFrom:
                    fieldRef:
                      fieldPath: metadata.name
                - name: POD_NAMESPACE
                  valueFrom:
                    fieldRef:
                      fieldPath: metadata.namespace
                - name: INSTANCE_IP
                  valueFrom:
                    fieldRef:
                      fieldPath: status.podIP
                - name: SERVICE_ACCOUNT
                  valueFrom:
                    fieldRef:
                      fieldPath: spec.serviceAccountName
                - name: HOST_IP
                  valueFrom:
                    fieldRef:
                      fieldPath: status.hostIP
                - name: ISTIO_CPU_LIMIT
                  valueFrom:
                    resourceFieldRef:
                      resource: limits.cpu
                      divisor: "1"
                - name: PROXY_CONFIG
                  value: |
                         {{ protoToJSON .ProxyConfig }}
                {{- if .ProxyConfig.ProxyMetadata }}
                {{- range $key, $value := .ProxyConfig.ProxyMetadata }}
                - name: {{ $key }}
                  value: "{{ $value }}"
                {{- end }}
                {{- end }}
                - name: GOMEMLIMIT
                  valueFrom:
                    resourceFieldRef:
                      resource: limits.memory
                      divisor: "1"
                - name: GOMAXPROCS
                  valueFrom:
                    resourceFieldRef:
                      resource: limits.cpu
                      divisor: "1"
                - name: ISTIO_META_CLUSTER_ID
                  value: "{{ valueOrDefault .Values.global.multiCluster.clusterName `Kubernetes` }}"
                {{- $network := valueOrDefault (index .InfrastructureLabels `topology.istio.io/network`) .Values.global.network }}
                {{- if $network }}
                - name: ISTIO_META_NETWORK
                  value: "{{ $network }}"
                {{- if eq .ControllerLabel "istio.io-eastwest-controller" }}
                - name: ISTIO_META_REQUESTED_NETWORK_VIEW
                  value: "{{ $network }}"
                {{- end }}
                {{- end }}
                - name: ISTIO_META_INTERCEPTION_MODE
                  value: REDIRECT
                - name: ISTIO_META_WORKLOAD_NAME
                  value: {{.DeploymentName}}
                - name: ISTIO_META_OWNER
                  value: kubernetes://apis/apps/v1/namespaces/{{.Namespace}}/deployments/{{.DeploymentName}}
                {{- if .Values.global.meshID }}
                - name: ISTIO_META_MESH_ID
                  value: "{{ .Values.global.meshID }}"
                {{- else if (valueOrDefault .MeshConfig.TrustDomain .Values.global.trustDomain) }}
                - name: ISTIO_META_MESH_ID
                  value: "{{ (valueOrDefault .MeshConfig.TrustDomain .Values.global.trustDomain) }}"
                {{- end }}
                {{- with (valueOrDefault .MeshConfig.TrustDomain .Values.global.trustDomain) }}
                - name: TRUST_DOMAIN
                  value: "{{ . }}"
                {{- end }}
                {{- if .Values.global.waypoint.resources }}
                resources:
                {{- toYaml (omitNil .Values.global.waypoint.resources) | nindent 10 }}
                {{- end }}
                startupProbe:
                  failureThreshold: 30
                  httpGet:
                    path: /healthz/ready
                    port: 15021
                    scheme: HTTP
                  initialDelaySeconds: 1
                  periodSeconds: 1
                  successThreshold: 1
                  timeoutSeconds: 1
                readinessProbe:
                  failureThreshold: 4
                  httpGet:
                    path: /healthz/ready
                    port: 15021
                    scheme: HTTP
                  initialDelaySeconds: 0
                  periodSeconds: 15
                  successThreshold: 1
                  timeoutSeconds: 1
                securityContext:
                  privileged: false
                {{- if not (eq .Values.global.platform "openshift") }}
                  runAsGroup: 1337
                  runAsUser: 1337
                {{- end }}
                  allowPrivilegeEscalation: false
                  readOnlyRootFilesystem: true
                  runAsNonRoot: true
                  capabilities:
                    drop:
                    - ALL
        {{- if .Values.gateways.seccompProfile }}
                  seccompProfile:
        {{- toYaml .Values.gateways.seccompProfile | nindent 12 }}
        {{- end }}
                volumeMounts:
                - mountPath: /var/run/secrets/workload-spiffe-uds
                  name: workload-socket
                - mountPath: /var/run/secrets/istio
                  name: istiod-ca-cert
                - mountPath: /var/lib/istio/data
                  name: istio-data
                - mountPath: /etc/istio/proxy
                  name: istio-envoy
                - mountPath: /var/run/secrets/tokens
                  name: istio-token
                - mountPath: /etc/istio/pod
                  name: istio-podinfo
              volumes:
              - emptyDir: {}
                name: workload-socket
              - emptyDir:
                  medium: Memory
                name: istio-envoy
              - emptyDir:
                  medium: Memory
                name: go-proxy-envoy
              - emptyDir: {}
                name: istio-data
              - emptyDir: {}
                name: go-proxy-data
              - downwardAPI:
                  items:
                  - fieldRef:
                      fieldPath: metadata.labels
                    path: labels
                  - fieldRef:
                      fieldPath: metadata.annotations
                    path: annotations
                name: istio-podinfo
              - name: istio-token
                projected:
                  sources:
                  - serviceAccountToken:
                      audience: istio-ca
                      expirationSeconds: 43200
                      path: istio-token
              - name: istiod-ca-cert
              {{- if eq (.Values.pilot.env).ENABLE_CLUSTER_TRUST_BUNDLE_API true }}
                projected:
                  sources:
                  - clusterTrustBundle:
                      name: istio.io:istiod-ca:{{ .Values.global.trustBundleName | default "root-cert" }}
                      path: root-cert.pem
              {{- else }}
                configMap:
                  name: {{ .Values.global.trustBundleName | default "istio-ca-root-cert" }}
              {{- end }}
              {{- if .Values.global.imagePullSecrets }}
              imagePullSecrets:
                {{- range .Values.global.imagePullSecrets }}
                - name: {{ . }}
                {{- end }}
              {{- end }}
        ---
        apiVersion: v1
        kind: Service
        metadata:
          annotations:
            {{ toJsonMap
              (strdict "networking.istio.io/traffic-distribution" "PreferClose")
              (omit .InfrastructureAnnotations
                "kubectl.kubernetes.io/last-applied-configuration"
                "gateway.istio.io/name-override"
                "gateway.istio.io/service-account"
                "gateway.istio.io/controller-version"
              ) | nindent 4 }}
          labels:
            {{- toJsonMap
              .InfrastructureLabels
              (strdict
                "gateway.networking.k8s.io/gateway-name" .Name
                "gateway.networking.k8s.io/gateway-class-name" .GatewayClass
              ) | nindent 4 }}
          name: {{.DeploymentName | quote}}
          namespace: {{.Namespace | quote}}
          ownerReferences:
          - apiVersion: gateway.networking.k8s.io/v1
            kind: Gateway
            name: "{{.Name}}"
            uid: "{{.UID}}"
        spec:
          ipFamilyPolicy: PreferDualStack
          ports:
          {{- range $key, $val := .Ports }}
          - name: {{ $val.Name | quote }}
            port: {{ $val.Port }}
            protocol: TCP
            appProtocol: {{ $val.AppProtocol }}
          {{- end }}
          selector:
            "{{.GatewayNameLabel}}": "{{.Name}}"
          {{- if and (.Spec.Addresses) (eq .ServiceType "LoadBalancer") }}
          loadBalancerIP: {{ (index .Spec.Addresses 0).Value | quote}}
          {{- end }}
          type: {{ .ServiceType | quote }}
        ---
        apiVersion: autoscaling/v2
        kind: HorizontalPodAutoscaler
        metadata:
          name: {{.DeploymentName | quote}}
          namespace: {{.Namespace | quote}}
          annotations:
            {{- toJsonMap (omit .InfrastructureAnnotations "kubectl.kubernetes.io/last-applied-configuration" "gateway.istio.io/name-override" "gateway.istio.io/service-account" "gateway.istio.io/controller-version") | nindent 4 }}
          labels:
            {{- toJsonMap
                  .InfrastructureLabels
                  (strdict
                  "gateway.networking.k8s.io/gateway-name" .Name
                  "gateway.networking.k8s.io/gateway-class-name" .GatewayClass
                  ) | nindent 4 }}
          ownerReferences:
            - apiVersion: gateway.networking.k8s.io/v1
              kind: Gateway
              name: {{.Name}}
              uid: "{{.UID}}"
        spec:
          scaleTargetRef:
            apiVersion: apps/v1
            kind: Deployment
            name:  {{.DeploymentName | quote}}
          maxReplicas: 1
        ---
        apiVersion: policy/v1
        kind: PodDisruptionBudget
        metadata:
          name: {{.DeploymentName | quote}}
          namespace: {{.Namespace | quote}}
          annotations:
            {{- toJsonMap (omit .InfrastructureAnnotations "kubectl.kubernetes.io/last-applied-configuration" "gateway.istio.io/name-override" "gateway.istio.io/service-account" "gateway.istio.io/controller-version") | nindent 4 }}
          labels:
            {{- toJsonMap
                  .InfrastructureLabels
                  (strdict
                  "gateway.networking.k8s.io/gateway-name" .Name
                  "gateway.networking.k8s.io/gateway-class-name" .GatewayClass
                  ) | nindent 4 }}
          ownerReferences:
            - apiVersion: gateway.networking.k8s.io/v1
              kind: Gateway
              name: {{.Name}}
              uid: "{{.UID}}"
        spec:
          selector:
            matchLabels:
              gateway.networking.k8s.io/gateway-name: {{.Name|quote}}
      kube-gateway: |
        apiVersion: v1
        kind: ServiceAccount
        metadata:
          name: {{.ServiceAccount | quote}}
          namespace: {{.Namespace | quote}}
          annotations:
            {{- toJsonMap (omit .InfrastructureAnnotations "kubectl.kubernetes.io/last-applied-configuration" "gateway.istio.io/name-override" "gateway.istio.io/service-account" "gateway.istio.io/controller-version") | nindent 4 }}
          labels:
            {{- toJsonMap
              .InfrastructureLabels
              (strdict
                "gateway.networking.k8s.io/gateway-name" .Name
                "gateway.networking.k8s.io/gateway-class-name" .GatewayClass
              ) | nindent 4 }}
          {{- if ge .KubeVersion 128 }}
          # Safe since 1.28: https://github.com/kubernetes/kubernetes/pull/117412
          ownerReferences:
          - apiVersion: gateway.networking.k8s.io/v1
            kind: Gateway
            name: "{{.Name}}"
            uid: "{{.UID}}"
          {{- end }}
        ---
        apiVersion: apps/v1
        kind: Deployment
        metadata:
          name: {{.DeploymentName | quote}}
          namespace: {{.Namespace | quote}}
          annotations:
            {{- toJsonMap (omit .InfrastructureAnnotations "kubectl.kubernetes.io/last-applied-configuration" "gateway.istio.io/name-override" "gateway.istio.io/service-account" "gateway.istio.io/controller-version") | nindent 4 }}
          labels:
            {{- toJsonMap
              .InfrastructureLabels
              (strdict
                "gateway.networking.k8s.io/gateway-name" .Name
                "gateway.networking.k8s.io/gateway-class-name" .GatewayClass
                "gateway.istio.io/managed" "istio.io-gateway-controller"
              ) | nindent 4 }}
          ownerReferences:
          - apiVersion: gateway.networking.k8s.io/v1
            kind: Gateway
            name: {{.Name}}
            uid: "{{.UID}}"
        spec:
          selector:
            matchLabels:
              "{{.GatewayNameLabel}}": {{.Name}}
          template:
            metadata:
              annotations:
                {{- toJsonMap
                  (omit .InfrastructureAnnotations "kubectl.kubernetes.io/last-applied-configuration" "gateway.istio.io/name-override" "gateway.istio.io/service-account" "gateway.istio.io/controller-version")
                  (strdict "istio.io/rev" (.Revision | default "default"))
                  (strdict
                    "prometheus.io/path" "/stats/prometheus"
                    "prometheus.io/port" "15020"
                    "prometheus.io/scrape" "true"
                  ) | nindent 8 }}
              labels:
                {{- toJsonMap
                  (strdict
                    "sidecar.istio.io/inject" "false"
                    "service.istio.io/canonical-name" .DeploymentName
                    "service.istio.io/canonical-revision" "latest"
                   )
                  .InfrastructureLabels
                  (strdict
                    "gateway.networking.k8s.io/gateway-name" .Name
                    "gateway.networking.k8s.io/gateway-class-name" .GatewayClass
                    "gateway.istio.io/managed" "istio.io-gateway-controller"
                  ) | nindent 8 }}
            spec:
              securityContext:
              {{- if .Values.gateways.securityContext }}
                {{- toYaml .Values.gateways.securityContext | nindent 8 }}
              {{- else }}
                sysctls:
                - name: net.ipv4.ip_unprivileged_port_start
                  value: "0"
              {{- if .Values.gateways.seccompProfile }}
                seccompProfile:
              {{- toYaml .Values.gateways.seccompProfile | nindent 10 }}
              {{- end }}
              {{- end }}
              serviceAccountName: {{.ServiceAccount | quote}}
              containers:
              - name: istio-proxy
              {{- if contains "/" (annotation .ObjectMeta `sidecar.istio.io/proxyImage` .Values.global.proxy.image) }}
                image: "{{ annotation .ObjectMeta `sidecar.istio.io/proxyImage` .Values.global.proxy.image }}"
              {{- else }}
                image: "{{ .ProxyImage }}"
              {{- end }}
                {{- if .Values.global.proxy.resources }}
                resources:
                  {{- toYaml (omitNil .Values.global.proxy.resources) | nindent 10 }}
                {{- end }}
                {{with .Values.global.imagePullPolicy }}imagePullPolicy: "{{.}}"{{end}}
                securityContext:
                  capabilities:
                    drop:
                    - ALL
                  allowPrivilegeEscalation: false
                  privileged: false
                  readOnlyRootFilesystem: true
                  runAsUser: {{ .ProxyUID | default "1337" }}
                  runAsGroup: {{ .ProxyGID | default "1337" }}
                  runAsNonRoot: true
                ports:
                - containerPort: 15020
                  name: metrics
                  protocol: TCP
                - containerPort: 15021
                  name: status-port
                  protocol: TCP
                - containerPort: 15090
                  protocol: TCP
                  name: http-envoy-prom
                args:
                - proxy
                - router
                - --domain
                - $(POD_NAMESPACE).svc.{{ .Values.global.proxy.clusterDomain }}
                - --proxyLogLevel
                - {{ annotation .ObjectMeta `sidecar.istio.io/logLevel` .Values.global.proxy.logLevel | quote}}
                - --proxyComponentLogLevel
                - {{ annotation .ObjectMeta `sidecar.istio.io/componentLogLevel` .Values.global.proxy.componentLogLevel | quote}}
                - --log_output_level
                - {{ annotation .ObjectMeta `sidecar.istio.io/agentLogLevel` .Values.global.logging.level | quote}}
              {{- if .Values.global.sts.servicePort }}
                - --stsPort={{ .Values.global.sts.servicePort }}
              {{- end }}
              {{- if .Values.global.logAsJson }}
                - --log_as_json
              {{- end }}
              {{- if .Values.global.proxy.lifecycle }}
                lifecycle:
                  {{- toYaml .Values.global.proxy.lifecycle | nindent 10 }}
              {{- end }}
                env:
                - name: PILOT_CERT_PROVIDER
                  value: {{ .Values.global.pilotCertProvider }}
                - name: CA_ADDR
                {{- if .Values.global.caAddress }}
                  value: {{ .Values.global.caAddress }}
                {{- else }}
                  value: istiod{{- if not (eq .Values.revision "") }}-{{ .Values.revision }}{{- end }}.{{ .Values.global.istioNamespace }}.svc:15012
                {{- end }}
                - name: POD_NAME
                  valueFrom:
                    fieldRef:
                      fieldPath: metadata.name
                - name: POD_NAMESPACE
                  valueFrom:
                    fieldRef:
                      fieldPath: metadata.namespace
                - name: INSTANCE_IP
                  valueFrom:
                    fieldRef:
                      fieldPath: status.podIP
                - name: SERVICE_ACCOUNT
                  valueFrom:
                    fieldRef:
                      fieldPath: spec.serviceAccountName
                - name: HOST_IP
                  valueFrom:
                    fieldRef:
                      fieldPath: status.hostIP
                - name: ISTIO_CPU_LIMIT
                  valueFrom:
                    resourceFieldRef:
                      resource: limits.cpu
                      divisor: "1"
                - name: PROXY_CONFIG
                  value: |
                         {{ protoToJSON .ProxyConfig }}
                - name: ISTIO_META_POD_PORTS
                  value: "[]"
                - name: ISTIO_META_APP_CONTAINERS
                  value: ""
                - name: GOMEMLIMIT
                  valueFrom:
                    resourceFieldRef:
                      resource: limits.memory
                      divisor: "1"
                - name: GOMAXPROCS
                  valueFrom:
                    resourceFieldRef:
                      resource: limits.cpu
                      divisor: "1"
                - name: ISTIO_META_CLUSTER_ID
                  value: "{{ valueOrDefault .Values.global.multiCluster.clusterName .ClusterID }}"
                - name: ISTIO_META_NODE_NAME
                  valueFrom:
                    fieldRef:
                      fieldPath: spec.nodeName
                - name: ISTIO_META_INTERCEPTION_MODE
                  value: "{{ .ProxyConfig.InterceptionMode.String }}"
                {{- with (valueOrDefault  (index .InfrastructureLabels "topology.istio.io/network") .Values.global.network) }}
                - name: ISTIO_META_NETWORK
                  value: {{.|quote}}
                {{- end }}
                - name: ISTIO_META_WORKLOAD_NAME
                  value: {{.DeploymentName|quote}}
                - name: ISTIO_META_OWNER
                  value: "kubernetes://apis/apps/v1/namespaces/{{.Namespace}}/deployments/{{.DeploymentName}}"
                {{- if .Values.global.meshID }}
                - name: ISTIO_META_MESH_ID
                  value: "{{ .Values.global.meshID }}"
                {{- else if (valueOrDefault .MeshConfig.TrustDomain .Values.global.trustDomain) }}
                - name: ISTIO_META_MESH_ID
                  value: "{{ (valueOrDefault .MeshConfig.TrustDomain .Values.global.trustDomain) }}"
                {{- end }}
                {{- with (valueOrDefault .MeshConfig.TrustDomain .Values.global.trustDomain)  }}
                - name: TRUST_DOMAIN
                  value: "{{ . }}"
                {{- end }}
                {{- range $key, $value := .ProxyConfig.ProxyMetadata }}
                - name: {{ $key }}
                  value: "{{ $value }}"
                {{- end }}
                {{- with (index .InfrastructureLabels "topology.istio.io/network") }}
                - name: ISTIO_META_REQUESTED_NETWORK_VIEW
                  value: {{.|quote}}
                {{- end }}
                startupProbe:
                  failureThreshold: 30
                  httpGet:
                    path: /healthz/ready
                    port: 15021
                    scheme: HTTP
                  initialDelaySeconds: 1
                  periodSeconds: 1
                  successThreshold: 1
                  timeoutSeconds: 1
                readinessProbe:
                  failureThreshold: 4
                  httpGet:
                    path: /healthz/ready
                    port: 15021
                    scheme: HTTP
                  initialDelaySeconds: 0
                  periodSeconds: 15
                  successThreshold: 1
                  timeoutSeconds: 1
                volumeMounts:
                - name: workload-socket
                  mountPath: /var/run/secrets/workload-spiffe-uds
                - name: credential-socket
                  mountPath: /var/run/secrets/credential-uds
                {{- if eq .Values.global.caName "GkeWorkloadCertificate" }}
                - name: gke-workload-certificate
                  mountPath: /var/run/secrets/workload-spiffe-credentials
                  readOnly: true
                {{- else }}
                - name: workload-certs
                  mountPath: /var/run/secrets/workload-spiffe-credentials
                {{- end }}
                {{- if eq .Values.global.pilotCertProvider "istiod" }}
                - mountPath: /var/run/secrets/istio
                  name: istiod-ca-cert
                {{- end }}
                - mountPath: /var/lib/istio/data
                  name: istio-data
                # SDS channel between istioagent and Envoy
                - mountPath: /etc/istio/proxy
                  name: istio-envoy
                - mountPath: /var/run/secrets/tokens
                  name: istio-token
                - name: istio-podinfo
                  mountPath: /etc/istio/pod
              volumes:
              - emptyDir: {}
                name: workload-socket
              - emptyDir: {}
                name: credential-socket
              {{- if eq .Values.global.caName "GkeWorkloadCertificate" }}
              - name: gke-workload-certificate
                csi:
                  driver: workloadcertificates.security.cloud.google.com
              {{- else}}
              - emptyDir: {}
                name: workload-certs
              {{- end }}
              # SDS channel between istioagent and Envoy
              - emptyDir:
                  medium: Memory
                name: istio-envoy
              - name: istio-data
                emptyDir: {}
              - name: istio-podinfo
                downwardAPI:
                  items:
                    - path: "labels"
                      fieldRef:
                        fieldPath: metadata.labels
                    - path: "annotations"
                      fieldRef:
                        fieldPath: metadata.annotations
              - name: istio-token
                projected:
                  sources:
                  - serviceAccountToken:
                      path: istio-token
                      expirationSeconds: 43200
                      audience: {{ .Values.global.sds.token.aud }}
              {{- if eq .Values.global.pilotCertProvider "istiod" }}
              - name: istiod-ca-cert
              {{- if eq ((.Values.pilot).env).ENABLE_CLUSTER_TRUST_BUNDLE_API true }}
                projected:
                  sources:
                  - clusterTrustBundle:
                      name: istio.io:istiod-ca:{{ .Values.global.trustBundleName | default "root-cert" }}
                      path: root-cert.pem
              {{- else }}
                configMap:
                  name: {{ .Values.global.trustBundleName | default "istio-ca-root-cert" }}
              {{- end }}
              {{- end }}
              {{- if .Values.global.imagePullSecrets }}
              imagePullSecrets:
                {{- range .Values.global.imagePullSecrets }}
                - name: {{ . }}
                {{- end }}
              {{- end }}
        ---
        apiVersion: v1
        kind: Service
        metadata:
          annotations:
            {{ toJsonMap (omit .InfrastructureAnnotations "kubectl.kubernetes.io/last-applied-configuration" "gateway.istio.io/name-override" "gateway.istio.io/service-account" "gateway.istio.io/controller-version") | nindent 4 }}
          labels:
            {{- toJsonMap
              .InfrastructureLabels
              (strdict
                "gateway.networking.k8s.io/gateway-name" .Name
                "gateway.networking.k8s.io/gateway-class-name" .GatewayClass
              ) | nindent 4 }}
          name: {{.DeploymentName | quote}}
          namespace: {{.Namespace | quote}}
          ownerReferences:
          - apiVersion: gateway.networking.k8s.io/v1
            kind: Gateway
            name: {{.Name}}
            uid: {{.UID}}
        spec:
          ipFamilyPolicy: PreferDualStack
          ports:
          {{- range $key, $val := .Ports }}
          - name: {{ $val.Name | quote }}
            port: {{ $val.Port }}
            protocol: TCP
            appProtocol: {{ $val.AppProtocol }}
          {{- end }}
          selector:
            "{{.GatewayNameLabel}}": {{.Name}}
          {{- if and (.Spec.Addresses) (eq .ServiceType "LoadBalancer") }}
          loadBalancerIP: {{ (index .Spec.Addresses 0).Value | quote}}
          {{- end }}
          type: {{ .ServiceType | quote }}
        ---
        apiVersion: autoscaling/v2
        kind: HorizontalPodAutoscaler
        metadata:
          name: {{.DeploymentName | quote}}
          namespace: {{.Namespace | quote}}
          annotations:
            {{- toJsonMap (omit .InfrastructureAnnotations "kubectl.kubernetes.io/last-applied-configuration" "gateway.istio.io/name-override" "gateway.istio.io/service-account" "gateway.istio.io/controller-version") | nindent 4 }}
          labels:
            {{- toJsonMap
                  .InfrastructureLabels
                  (strdict
                  "gateway.networking.k8s.io/gateway-name" .Name
                  "gateway.networking.k8s.io/gateway-class-name" .GatewayClass
                  ) | nindent 4 }}
          ownerReferences:
            - apiVersion: gateway.networking.k8s.io/v1
              kind: Gateway
              name: {{.Name}}
              uid: "{{.UID}}"
        spec:
          scaleTargetRef:
            apiVersion: apps/v1
            kind: Deployment
            name:  {{.DeploymentName | quote}}
          maxReplicas: 1
        ---
        apiVersion: policy/v1
        kind: PodDisruptionBudget
        metadata:
          name: {{.DeploymentName | quote}}
          namespace: {{.Namespace | quote}}
          annotations:
            {{- toJsonMap (omit .InfrastructureAnnotations "kubectl.kubernetes.io/last-applied-configuration" "gateway.istio.io/name-override" "gateway.istio.io/service-account" "gateway.istio.io/controller-version") | nindent 4 }}
          labels:
            {{- toJsonMap
                  .InfrastructureLabels
                  (strdict
                  "gateway.networking.k8s.io/gateway-name" .Name
                  "gateway.networking.k8s.io/gateway-class-name" .GatewayClass
                  ) | nindent 4 }}
          ownerReferences:
            - apiVersion: gateway.networking.k8s.io/v1
              kind: Gateway
              name: {{.Name}}
              uid: "{{.UID}}"
        spec:
          selector:
            matchLabels:
              gateway.networking.k8s.io/gateway-name: {{.Name|quote}}
      agentgateway: |
        apiVersion: v1
        kind: ServiceAccount
        metadata:
          name: {{.ServiceAccount | quote}}
          namespace: {{.Namespace | quote}}
          annotations:
            {{- toJsonMap (omit .InfrastructureAnnotations "kubectl.kubernetes.io/last-applied-configuration" "gateway.istio.io/name-override" "gateway.istio.io/service-account" "gateway.istio.io/controller-version") | nindent 4 }}
          labels:
            {{- toJsonMap
              .InfrastructureLabels
              (strdict
                "gateway.networking.k8s.io/gateway-name" .Name
                "gateway.networking.k8s.io/gateway-class-name" .GatewayClass
              ) | nindent 4 }}
          ownerReferences:
          - apiVersion: gateway.networking.k8s.io/v1
            kind: Gateway
            name: "{{.Name}}"
            uid: "{{.UID}}"
        ---
        apiVersion: apps/v1
        kind: Deployment
        metadata:
          name: {{.DeploymentName | quote}}
          namespace: {{.Namespace | quote}}
          annotations:
            {{- toJsonMap (omit .InfrastructureAnnotations "kubectl.kubernetes.io/last-applied-configuration" "gateway.istio.io/name-override" "gateway.istio.io/service-account" "gateway.istio.io/controller-version") | nindent 4 }}
          labels:
            {{- toJsonMap
              .InfrastructureLabels
              (strdict
                "gateway.networking.k8s.io/gateway-name" .Name
                "gateway.networking.k8s.io/gateway-class-name" .GatewayClass
                "gateway.istio.io/managed" "istio.io-agentgateway-controller"
              ) | nindent 4 }}
          ownerReferences:
          - apiVersion: gateway.networking.k8s.io/v1
            kind: Gateway
            name: {{.Name}}
            uid: "{{.UID}}"
        spec:
          selector:
            matchLabels:
              "{{.GatewayNameLabel}}": {{.Name}}
          template:
            metadata:
              annotations:
                {{- toJsonMap
                  (omit .InfrastructureAnnotations "kubectl.kubernetes.io/last-applied-configuration" "gateway.istio.io/name-override" "gateway.istio.io/service-account" "gateway.istio.io/controller-version")
                  (strdict "istio.io/rev" (.Revision | default "default"))
                  (strdict
                    "prometheus.io/path" "/stats/prometheus"
                    "prometheus.io/port" "15020"
                    "prometheus.io/scrape" "true"
                  ) | nindent 8 }}
              labels:
                {{- toJsonMap
                  (strdict
                    "sidecar.istio.io/inject" "false"
                    "service.istio.io/canonical-name" .DeploymentName
                    "service.istio.io/canonical-revision" "latest"
                   )
                  .InfrastructureLabels
                  (strdict
                    "gateway.networking.k8s.io/gateway-name" .Name
                    "gateway.networking.k8s.io/gateway-class-name" .GatewayClass
                    "gateway.istio.io/managed" "istio.io-agentgateway-controller"
                  ) | nindent 8 }}
            spec:
              securityContext:
              {{- if .Values.gateways.securityContext }}
                {{- toYaml .Values.gateways.securityContext | nindent 8 }}
              {{- else }}
                sysctls:
                - name: net.ipv4.ip_unprivileged_port_start # allows binding to 80 and 443 without root
                  value: "0"
              {{- if .Values.gateways.seccompProfile }}
                seccompProfile:
              {{- toYaml .Values.gateways.seccompProfile | nindent 10 }}
              {{- end }}
              {{- end }}
              serviceAccountName: {{.ServiceAccount | quote}}
              containers:
              - name: agentgateway
              {{- if contains "/" (annotation .ObjectMeta `gateway.istio.io/agentgatewayImage` .Values.global.agentgateway.image) }}
                image: "{{ annotation .ObjectMeta `gateway.istio.io/agentgatewayImage` .Values.global.agentgateway.image }}"
              {{- else }}
                image: "{{ .AgentgatewayImage }}"
              {{- end }}
                {{- if .Values.global.proxy.resources }}
                resources:
                  {{- toYaml (omitNil .Values.global.proxy.resources) | nindent 10 }}
                {{- end }}
                {{with .Values.global.imagePullPolicy }}imagePullPolicy: "{{.}}"{{end}}
                securityContext:
                  capabilities:
                    drop:
                    - ALL
                  allowPrivilegeEscalation: false
                  privileged: false
                  readOnlyRootFilesystem: true
                  runAsUser: {{ .ProxyUID | default "10101" }}
                  runAsGroup: {{ .ProxyGID | default "10101" }}
                  runAsNonRoot: true
                ports:
                - containerPort: 15020
                  name: metrics
                  protocol: TCP
                - containerPort: 15021
                  name: status-port
                  protocol: TCP
                args:
                - --config
                - '{}'
              {{- if .Values.global.proxy.lifecycle }}
                lifecycle:
                  {{- toYaml .Values.global.proxy.lifecycle | nindent 10 }}
              {{- end }}
                env:
                - name: POD_NAME
                  valueFrom:
                    fieldRef:
                      fieldPath: metadata.name
                - name: POD_NAMESPACE
                  valueFrom:
                    fieldRef:
                      fieldPath: metadata.namespace
                - name: NAMESPACE
                  valueFrom:
                    fieldRef:
                      fieldPath: metadata.namespace
                - name: INSTANCE_IP
                  valueFrom:
                    fieldRef:
                      fieldPath: status.podIP
                - name: SERVICE_ACCOUNT
                  valueFrom:
                    fieldRef:
                      fieldPath: spec.serviceAccountName
                - name: CPU_LIMIT
                  valueFrom:
                    resourceFieldRef:
                      resource: limits.cpu
                      divisor: "1"
                - name: GATEWAY
                  value: {{.Name|quote}}
                - name: RUST_BACKTRACE
                  value: "1"
                - name: CLUSTER_ID
                  value: "{{ valueOrDefault .Values.global.multiCluster.clusterName .ClusterID }}"
                {{- with (valueOrDefault  (index .InfrastructureLabels "topology.istio.io/network") .Values.global.network) }}
                - name: NETWORK
                  value: {{.|quote}}
                {{- end }}
                {{- with (valueOrDefault .MeshConfig.TrustDomain .Values.global.trustDomain)  }}
                - name: TRUST_DOMAIN
                  value: "{{ . }}"
                {{- end }}
                {{- range $key, $value := .ProxyConfig.ProxyMetadata }}
                - name: {{ $key }}
                  value: "{{ $value }}"
                {{- end }}
                - name: XDS_ADDRESS
                  value: {{ .ProxyConfig.DiscoveryAddress | quote }}
                - name: CA_ADDRESS
                {{- if .Values.global.caAddress }}
                  value: {{ .Values.global.caAddress }}
                {{- else }}
                  value: istiod{{- if not (eq .Values.revision "") }}-{{ .Values.revision }}{{- end }}.{{ .Values.global.istioNamespace }}.svc:15012
                {{- end }}
                startupProbe:
                  failureThreshold: 30
                  httpGet:
                    path: /healthz/ready
                    port: 15021
                    scheme: HTTP
                  initialDelaySeconds: 1
                  periodSeconds: 1
                  successThreshold: 1
                  timeoutSeconds: 1
                readinessProbe:
                  failureThreshold: 4
                  httpGet:
                    path: /healthz/ready
                    port: 15021
                    scheme: HTTP
                  initialDelaySeconds: 0
                  periodSeconds: 15
                  successThreshold: 1
                  timeoutSeconds: 1
                volumeMounts:
                - mountPath: /var/run/secrets/xds
                  name: istiod-ca-cert
                - mountPath: /var/run/secrets/xds-tokens
                  name: xds-token
                - mountPath: /tmp
                  name: tmp
                - mountPath: /var/run/secrets/istio
                  name: istiod-ca-cert
                - mountPath: /var/run/secrets/tokens
                  name: istio-token
              volumes:
              - emptyDir: {}
                name: tmp
              - name: xds-token
                projected:
                  sources:
                  - serviceAccountToken:
                      path: xds-token
                      expirationSeconds: 43200
                      audience: {{ .Values.global.sds.token.aud }}
              - name: istio-token
                projected:
                  sources:
                  - serviceAccountToken:
                      path: istio-token
                      expirationSeconds: 43200
                      audience: {{ .Values.global.sds.token.aud }}
              {{- if eq .Values.global.pilotCertProvider "istiod" }}
              - name: istiod-ca-cert
              {{- if eq ((.Values.pilot).env).ENABLE_CLUSTER_TRUST_BUNDLE_API true }}
                projected:
                  sources:
                  - clusterTrustBundle:
                      name: istio.io:istiod-ca:{{ .Values.global.trustBundleName | default "root-cert" }}
                      path: root-cert.pem
              {{- else }}
                configMap:
                  name: {{ .Values.global.trustBundleName | default "istio-ca-root-cert" }}
              {{- end }}
              {{- end }}
              {{- if .Values.global.imagePullSecrets }}
              imagePullSecrets:
                {{- range .Values.global.imagePullSecrets }}
                - name: {{ . }}
                {{- end }}
              {{- end }}
        ---
        apiVersion: v1
        kind: Service
        metadata:
          annotations:
            {{ toJsonMap (omit .InfrastructureAnnotations "kubectl.kubernetes.io/last-applied-configuration" "gateway.istio.io/name-override" "gateway.istio.io/service-account" "gateway.istio.io/controller-version") | nindent 4 }}
          labels:
            {{- toJsonMap
              .InfrastructureLabels
              (strdict
                "gateway.networking.k8s.io/gateway-name" .Name
                "gateway.networking.k8s.io/gateway-class-name" .GatewayClass
              ) | nindent 4 }}
          name: {{.DeploymentName | quote}}
          namespace: {{.Namespace | quote}}
          ownerReferences:
          - apiVersion: gateway.networking.k8s.io/v1
            kind: Gateway
            name: {{.Name}}
            uid: {{.UID}}
        spec:
          ipFamilyPolicy: PreferDualStack
          ports:
          {{- range $key, $val := .Ports }}
          - name: {{ $val.Name | quote }}
            port: {{ $val.Port }}
            protocol: TCP
            appProtocol: {{ $val.AppProtocol }}
          {{- end }}
          selector:
            "{{.GatewayNameLabel}}": {{.Name}}
          {{- if and (.Spec.Addresses) (eq .ServiceType "LoadBalancer") }}
          loadBalancerIP: {{ (index .Spec.Addresses 0).Value | quote}}
          {{- end }}
          type: {{ .ServiceType | quote }}
        ---
        apiVersion: autoscaling/v2
        kind: HorizontalPodAutoscaler
        metadata:
          name: {{.DeploymentName | quote}}
          namespace: {{.Namespace | quote}}
          annotations:
            {{- toJsonMap (omit .InfrastructureAnnotations "kubectl.kubernetes.io/last-applied-configuration" "gateway.istio.io/name-override" "gateway.istio.io/service-account" "gateway.istio.io/controller-version") | nindent 4 }}
          labels:
            {{- toJsonMap
                  .InfrastructureLabels
                  (strdict
                  "gateway.networking.k8s.io/gateway-name" .Name
                  "gateway.networking.k8s.io/gateway-class-name" .GatewayClass
                  ) | nindent 4 }}
          ownerReferences:
            - apiVersion: gateway.networking.k8s.io/v1
              kind: Gateway
              name: {{.Name}}
              uid: "{{.UID}}"
        spec:
          scaleTargetRef:
            apiVersion: apps/v1
            kind: Deployment
            name:  {{.DeploymentName | quote}}
          maxReplicas: 1
        ---
        apiVersion: policy/v1
        kind: PodDisruptionBudget
        metadata:
          name: {{.DeploymentName | quote}}
          namespace: {{.Namespace | quote}}
          annotations:
            {{- toJsonMap (omit .InfrastructureAnnotations "kubectl.kubernetes.io/last-applied-configuration" "gateway.istio.io/name-override" "gateway.istio.io/service-account" "gateway.istio.io/controller-version") | nindent 4 }}
          labels:
            {{- toJsonMap
                  .InfrastructureLabels
                  (strdict
                  "gateway.networking.k8s.io/gateway-name" .Name
                  "gateway.networking.k8s.io/gateway-class-name" .GatewayClass
                  ) | nindent 4 }}
          ownerReferences:
            - apiVersion: gateway.networking.k8s.io/v1
              kind: Gateway
              name: {{.Name}}
              uid: "{{.UID}}"
        spec:
          selector:
            matchLabels:
              gateway.networking.k8s.io/gateway-name: {{.Name|quote}}
---
# Source: istiod/templates/clusterrole.yaml
# Created if cluster resources are not omitted
# Created if this is not a remote istiod, OR if it is and is also a config cluster

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: istiod-clusterrole-default
  labels:
    app: istiod
    release: istiod
    app.kubernetes.io/name: "istiod"
    app.kubernetes.io/managed-by: "Helm"
    app.kubernetes.io/instance: "istiod"
    app.kubernetes.io/part-of: "istio"
    app.kubernetes.io/version: "1.30.0"
    helm.sh/chart: istiod-1.30.0
rules:
  # sidecar injection controller
  - apiGroups: ["admissionregistration.k8s.io"]
    resources: ["mutatingwebhookconfigurations"]
    verbs: ["get", "list", "watch", "update", "patch"]

  # configuration validation webhook controller
  - apiGroups: ["admissionregistration.k8s.io"]
    resources: ["validatingwebhookconfigurations"]
    verbs: ["get", "list", "watch", "update"]

  # istio configuration
  # removing CRD permissions can break older versions of Istio running alongside this control plane (https://github.com/istio/istio/issues/29382)
  # please proceed with caution
  - apiGroups: ["config.istio.io", "security.istio.io", "networking.istio.io", "authentication.istio.io", "rbac.istio.io", "telemetry.istio.io", "extensions.istio.io"]
    verbs: ["get", "watch", "list"]
    resources: ["*"]
  - apiGroups: ["networking.istio.io"]
    verbs: [ "get", "watch", "list", "update", "patch", "create", "delete" ]
    resources: [ "workloadentries" ]
  - apiGroups: ["networking.istio.io"]
    verbs: [ "get", "watch", "list", "update", "patch", "create", "delete" ]
    resources: [ "workloadentries/status",  "serviceentries/status" ]
  - apiGroups: ["security.istio.io"]
    verbs: [ "get", "watch", "list", "update", "patch", "create", "delete" ]
    resources: [ "authorizationpolicies/status" ]
  - apiGroups: [""]
    verbs: [ "get", "watch", "list", "update", "patch", "create", "delete" ]
    resources: [ "services/status" ]

  # auto-detect installed CRD definitions
  - apiGroups: ["apiextensions.k8s.io"]
    resources: ["customresourcedefinitions"]
    verbs: ["get", "list", "watch"]

  # discovery and routing
  - apiGroups: [""]
    resources: ["pods", "nodes", "services", "namespaces", "endpoints"]
    verbs: ["get", "list", "watch"]
  - apiGroups: ["discovery.k8s.io"]
    resources: ["endpointslices"]
    verbs: ["get", "list", "watch"]

  # ingress controller
  - apiGroups: ["networking.k8s.io"]
    resources: ["ingresses", "ingressclasses"]
    verbs: ["get", "list", "watch"]
  - apiGroups: ["networking.k8s.io"]
    resources: ["ingresses/status"]
    verbs: ["*"]

  # required for CA's namespace controller
  - apiGroups: [""]
    resources: ["configmaps"]
    verbs: ["create", "get", "list", "watch", "update"]

  # Istiod and bootstrap.

  # Used by Istiod to verify the JWT tokens
  - apiGroups: ["authentication.k8s.io"]
    resources: ["tokenreviews"]
    verbs: ["create"]

  # Used by Istiod to verify gateway SDS
  - apiGroups: ["authorization.k8s.io"]
    resources: ["subjectaccessreviews"]
    verbs: ["create"]

  # Use for Kubernetes Service APIs
  - apiGroups: ["gateway.networking.k8s.io", "gateway.networking.x-k8s.io"]
    resources: ["*"]
    verbs: ["get", "watch", "list"]
  - apiGroups: ["gateway.networking.x-k8s.io"]
    resources:
    - xbackendtrafficpolicies/status
    verbs: ["update", "patch"]
  - apiGroups: ["gateway.networking.k8s.io"]
    resources:
    - backendtlspolicies/status
    - gatewayclasses/status
    - gateways/status
    - grpcroutes/status
    - httproutes/status
    - referencegrants/status
    - tcproutes/status
    - tlsroutes/status
    - udproutes/status
    - listenersets/status
    verbs: ["update", "patch"]
  - apiGroups: ["gateway.networking.k8s.io"]
    resources: ["gatewayclasses"]
    verbs: ["create", "update", "patch", "delete"]
  - apiGroups: ["inference.networking.k8s.io"]
    resources: ["inferencepools"]
    verbs: ["get", "watch", "list"]
  - apiGroups: ["inference.networking.k8s.io"]
    resources: ["inferencepools/status"]
    verbs: ["update", "patch"]

  # Needed for multicluster secret reading, possibly ingress certs in the future
  - apiGroups: [""]
    resources: ["secrets"]
    verbs: ["get", "watch", "list"]

  # Used for MCS serviceexport management
  - apiGroups: ["multicluster.x-k8s.io"]
    resources: ["serviceexports"]
    verbs: [ "get", "watch", "list", "create", "delete"]

  # Used for MCS serviceimport management
  - apiGroups: ["multicluster.x-k8s.io"]
    resources: ["serviceimports"]
    verbs: ["get", "watch", "list"]
---
# Source: istiod/templates/clusterrole.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: istiod-gateway-controller-default
  labels:
    app: istiod
    release: istiod
    app.kubernetes.io/name: "istiod"
    app.kubernetes.io/managed-by: "Helm"
    app.kubernetes.io/instance: "istiod"
    app.kubernetes.io/part-of: "istio"
    app.kubernetes.io/version: "1.30.0"
    helm.sh/chart: istiod-1.30.0
rules:
  - apiGroups: ["apps"]
    verbs: [ "get", "watch", "list", "update", "patch", "create", "delete" ]
    resources: [ "deployments" ]
  - apiGroups: ["autoscaling"]
    verbs: [ "get", "watch", "list", "update", "patch", "create", "delete" ]
    resources: [ "horizontalpodautoscalers" ]
  - apiGroups: ["policy"]
    verbs: [ "get", "watch", "list", "update", "patch", "create", "delete" ]
    resources: [ "poddisruptionbudgets" ]
  - apiGroups: [""]
    verbs: [ "get", "watch", "list", "update", "patch", "create", "delete" ]
    resources: [ "services" ]
  - apiGroups: [""]
    verbs: [ "get", "watch", "list", "update", "patch", "create", "delete" ]
    resources: [ "serviceaccounts"]
---
# Source: istiod/templates/reader-clusterrole.yaml
# Created if cluster resources are not omitted. Used for multicluster remote secret workflows.

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: istio-reader-clusterrole-default
  labels:
    app: istio-reader
    release: istiod
    app.kubernetes.io/name: "istio-reader"
    app.kubernetes.io/managed-by: "Helm"
    app.kubernetes.io/instance: "istiod"
    app.kubernetes.io/part-of: "istio"
    app.kubernetes.io/version: "1.30.0"
    helm.sh/chart: istiod-1.30.0
rules:
  - apiGroups:
      - "config.istio.io"
      - "security.istio.io"
      - "networking.istio.io"
      - "authentication.istio.io"
      - "rbac.istio.io"
      - "telemetry.istio.io"
      - "extensions.istio.io"
    resources: ["*"]
    verbs: ["get", "list", "watch"]
  - apiGroups: [""]
    resources: ["endpoints", "pods", "services", "nodes", "replicationcontrollers", "namespaces", "secrets", "configmaps"]
    verbs: ["get", "list", "watch"]
  - apiGroups: ["networking.istio.io"]
    verbs: [ "get", "watch", "list" ]
    resources: [ "workloadentries" ]
  - apiGroups: ["networking.x-k8s.io", "gateway.networking.k8s.io"]
    resources: ["gateways"]
    verbs: ["get", "watch", "list"]
  - apiGroups: ["apiextensions.k8s.io"]
    resources: ["customresourcedefinitions"]
    verbs: ["get", "list", "watch"]
  - apiGroups: ["discovery.k8s.io"]
    resources: ["endpointslices"]
    verbs: ["get", "list", "watch"]
  - apiGroups: ["multicluster.x-k8s.io"]
    resources: ["serviceexports"]
    verbs: ["get", "list", "watch", "create", "delete"]
  - apiGroups: ["multicluster.x-k8s.io"]
    resources: ["serviceimports"]
    verbs: ["get", "list", "watch"]
  - apiGroups: ["apps"]
    resources: ["replicasets"]
    verbs: ["get", "list", "watch"]
  - apiGroups: ["authentication.k8s.io"]
    resources: ["tokenreviews"]
    verbs: ["create"]
  - apiGroups: ["authorization.k8s.io"]
    resources: ["subjectaccessreviews"]
    verbs: ["create"]
---
# Source: istiod/templates/clusterrolebinding.yaml
# Created if cluster resources are not omitted
# Created if this is not a remote istiod, OR if it is and is also a config cluster
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: istiod-clusterrole-default
  labels:
    app: istiod
    release: istiod
    app.kubernetes.io/name: "istiod"
    app.kubernetes.io/managed-by: "Helm"
    app.kubernetes.io/instance: "istiod"
    app.kubernetes.io/part-of: "istio"
    app.kubernetes.io/version: "1.30.0"
    helm.sh/chart: istiod-1.30.0
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: istiod-clusterrole-default
subjects:
  - kind: ServiceAccount
    name: istiod
    namespace: istio-system
---
# Source: istiod/templates/clusterrolebinding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: istiod-gateway-controller-default
  labels:
    app: istiod
    release: istiod
    app.kubernetes.io/name: "istiod"
    app.kubernetes.io/managed-by: "Helm"
    app.kubernetes.io/instance: "istiod"
    app.kubernetes.io/part-of: "istio"
    app.kubernetes.io/version: "1.30.0"
    helm.sh/chart: istiod-1.30.0
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: istiod-gateway-controller-default
subjects:
- kind: ServiceAccount
  name: istiod
  namespace: istio-system
---
# Source: istiod/templates/reader-clusterrolebinding.yaml
# Created if cluster resources are not omitted. Used for multicluster remote secret workflows.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: istio-reader-clusterrole-default
  labels:
    app: istio-reader
    release: istiod
    app.kubernetes.io/name: "istio-reader"
    app.kubernetes.io/managed-by: "Helm"
    app.kubernetes.io/instance: "istiod"
    app.kubernetes.io/part-of: "istio"
    app.kubernetes.io/version: "1.30.0"
    helm.sh/chart: istiod-1.30.0
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: istio-reader-clusterrole-default
subjects:
  - kind: ServiceAccount
    name: istio-reader-service-account
    namespace: istio-system
---
# Source: istiod/templates/role.yaml
# Created if this is not a remote istiod, OR if it is and is also a config cluster
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: istiod
  namespace: istio-system
  labels:
    app: istiod
    release: istiod
    app.kubernetes.io/name: "istiod"
    app.kubernetes.io/managed-by: "Helm"
    app.kubernetes.io/instance: "istiod"
    app.kubernetes.io/part-of: "istio"
    app.kubernetes.io/version: "1.30.0"
    helm.sh/chart: istiod-1.30.0
rules:
# permissions to verify the webhook is ready and rejecting
# invalid config. We use --server-dry-run so no config is persisted.
- apiGroups: ["networking.istio.io"]
  verbs: ["create"]
  resources: ["gateways"]

# For storing CA secret
- apiGroups: [""]
  resources: ["secrets"]
  # TODO lock this down to istio-ca-cert if not using the DNS cert mesh config
  verbs: ["create", "get", "watch", "list", "update", "delete"]

# For status controller, so it can delete the distribution report configmap
- apiGroups: [""]
  resources: ["configmaps"]
  verbs: ["delete"]

# For gateway deployment controller
- apiGroups: ["coordination.k8s.io"]
  resources: ["leases"]
  verbs: ["get", "update", "patch", "create"]
---
# Source: istiod/templates/rolebinding.yaml
# Created if this is not a remote istiod, OR if it is and is also a config cluster
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: istiod
  namespace: istio-system
  labels:
    app: istiod
    release: istiod
    app.kubernetes.io/name: "istiod"
    app.kubernetes.io/managed-by: "Helm"
    app.kubernetes.io/instance: "istiod"
    app.kubernetes.io/part-of: "istio"
    app.kubernetes.io/version: "1.30.0"
    helm.sh/chart: istiod-1.30.0
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: istiod
subjects:
  - kind: ServiceAccount
    name: istiod
    namespace: istio-system
---
# Source: istiod/templates/service.yaml
# Not created if istiod is running remotely
apiVersion: v1
kind: Service
metadata:
  name: istiod
  namespace: default
  labels:
    istio.io/rev: "default"
    install.operator.istio.io/owning-resource: unknown
    operator.istio.io/component: "Pilot"
    app: istiod
    istio: pilot
    release: istiod
    app.kubernetes.io/name: "istiod"
    app.kubernetes.io/managed-by: "Helm"
    app.kubernetes.io/instance: "istiod"
    app.kubernetes.io/part-of: "istio"
    app.kubernetes.io/version: "1.30.0"
    helm.sh/chart: istiod-1.30.0
spec:
  ports:
    - port: 15010
      name: grpc-xds # plaintext
      protocol: TCP
    - port: 15012
      name: https-dns # mTLS with k8s-signed cert
      protocol: TCP
    - port: 443
      name: https-webhook # validation and injection
      targetPort: 15017
      protocol: TCP
    - port: 15014
      name: http-monitoring # prometheus stats
      protocol: TCP
  selector:
    app: istiod
    # Label used by the 'default' service. For versioned deployments we match with app and version.
    # This avoids default deployment picking the canary
    istio: pilot
---
# Source: istiod/templates/deployment.yaml
# Not created if istiod is running remotely
apiVersion: apps/v1
kind: Deployment
metadata:
  name: istiod
  namespace: default
  labels:
    app: istiod
    istio.io/rev: "default"
    install.operator.istio.io/owning-resource: unknown
    operator.istio.io/component: "Pilot"
    istio: pilot
    release: istiod
    app.kubernetes.io/name: "istiod"
    app.kubernetes.io/managed-by: "Helm"
    app.kubernetes.io/instance: "istiod"
    app.kubernetes.io/part-of: "istio"
    app.kubernetes.io/version: "1.30.0"
    helm.sh/chart: istiod-1.30.0
spec:
  strategy:
    rollingUpdate:
      maxSurge: 100%
      maxUnavailable: 25%
  selector:
    matchLabels:
      istio: pilot
  template:
    metadata:
      labels:
        app: istiod
        istio.io/rev: "default"
        install.operator.istio.io/owning-resource: unknown
        sidecar.istio.io/inject: "false"
        operator.istio.io/component: "Pilot"
        istio: pilot
        istio.io/dataplane-mode: none
        app.kubernetes.io/name: "istiod"
        app.kubernetes.io/managed-by: "Helm"
        app.kubernetes.io/instance: "istiod"
        app.kubernetes.io/part-of: "istio"
        app.kubernetes.io/version: "1.30.0"
        helm.sh/chart: istiod-1.30.0
      annotations:
        prometheus.io/port: "15014"
        prometheus.io/scrape: "true"
        sidecar.istio.io/inject: "false"
    spec:
      tolerations:
        - key: cni.istio.io/not-ready
          operator: "Exists"
      serviceAccountName: istiod
      containers:
        - name: discovery
          image: "registry.istio.io/release/pilot:1.30.0"
          args:
          - "discovery"
          - --monitoringAddr=:15014
          - --log_output_level=default:info
          - --domain
          - cluster.local
          - --keepaliveMaxServerConnectionAge
          - "30m"
          ports:
          - containerPort: 8080
            protocol: TCP
            name: http-debug
          - containerPort: 15010
            protocol: TCP
            name: grpc-xds
          - containerPort: 15012
            protocol: TCP
            name: tls-xds
          - containerPort: 15017
            protocol: TCP
            name: https-webhooks
          - containerPort: 15014
            protocol: TCP
            name: http-monitoring
          readinessProbe:
            httpGet:
              path: /ready
              port: 8080
            initialDelaySeconds: 1
            periodSeconds: 3
            timeoutSeconds: 5
          env:
          - name: REVISION
            value: "default"
          - name: PILOT_CERT_PROVIDER
            value: istiod
          - name: POD_NAME
            valueFrom:
              fieldRef:
                apiVersion: v1
                fieldPath: metadata.name
          - name: POD_NAMESPACE
            valueFrom:
              fieldRef:
                apiVersion: v1
                fieldPath: metadata.namespace
          - name: SERVICE_ACCOUNT
            valueFrom:
              fieldRef:
                apiVersion: v1
                fieldPath: spec.serviceAccountName
          - name: KUBECONFIG
            value: /var/run/secrets/remote/config
          # If you explicitly told us where ztunnel lives, use that.
          # Otherwise, assume it lives in our namespace
          # Also, check for an explicit ENV override (legacy approach) and prefer that
          # if present


          - name: CA_TRUSTED_NODE_ACCOUNTS
            value: "default/ztunnel"
          - name: PILOT_TRACE_SAMPLING
            value: "1"
# If externalIstiod is set via Values.Global, then enable the pilot env variable. However, if it's set via Values.pilot.env, then
# don't set it here to avoid duplication.
# TODO (nshankar13): Move from Helm chart to code: https://github.com/istio/istio/issues/52449
          - name: PILOT_ENABLE_ANALYSIS
            value: "false"
          - name: CLUSTER_ID
            value: "Kubernetes"
          - name: GOMAXPROCS
            valueFrom:
              resourceFieldRef:
                resource: limits.cpu
                divisor: "1"
          - name: PLATFORM
            value: ""
          resources:
            requests:
              cpu: 500m
              memory: 2048Mi
          securityContext:
            allowPrivilegeEscalation: false
            readOnlyRootFilesystem: true
            runAsNonRoot: true
            capabilities:
              drop:
              - ALL
          volumeMounts:
          - name: istio-token
            mountPath: /var/run/secrets/tokens
            readOnly: true
          - name: local-certs
            mountPath: /var/run/secrets/istio-dns
          - name: cacerts
            mountPath: /etc/cacerts
            readOnly: true
          - name: istio-kubeconfig
            mountPath: /var/run/secrets/remote
            readOnly: true
          - name: istio-csr-dns-cert
            mountPath: /var/run/secrets/istiod/tls
            readOnly: true
          - name: istio-csr-ca-configmap
            mountPath: /var/run/secrets/istiod/ca
            readOnly: true
      volumes:
      # Technically not needed on this pod - but it helps debugging/testing SDS
      # Should be removed after everything works.
      - emptyDir:
          medium: Memory
        name: local-certs
      - name: istio-token
        projected:
          sources:
            - serviceAccountToken:
                audience: istio-ca
                expirationSeconds: 43200
                path: istio-token
      # Optional: user-generated root
      - name: cacerts
        secret:
          secretName: cacerts
          optional: true
      - name: istio-kubeconfig
        secret:
          secretName: istio-kubeconfig
          optional: true
      # Optional: istio-csr dns pilot certs
      - name: istio-csr-dns-cert
        secret:
          secretName: istiod-tls
          optional: true
      - name: istio-csr-ca-configmap
        configMap:
          name: istio-ca-root-cert
          defaultMode: 420
          optional: true
---
# Source: istiod/templates/autoscale.yaml
# Not created if istiod is running remotely
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: istiod
  namespace: default
  labels:
    app: istiod
    release: istiod
    istio.io/rev: "default"
    install.operator.istio.io/owning-resource: unknown
    operator.istio.io/component: "Pilot"
    app.kubernetes.io/name: "istiod"
    app.kubernetes.io/managed-by: "Helm"
    app.kubernetes.io/instance: "istiod"
    app.kubernetes.io/part-of: "istio"
    app.kubernetes.io/version: "1.30.0"
    helm.sh/chart: istiod-1.30.0
spec:
  maxReplicas: 5
  minReplicas: 1
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: istiod
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 80
---
# Source: istiod/templates/mutatingwebhook.yaml
# TODO BML istiodRemote.injectionURL is invalid to set if `istiodRemote.enabled` is false, we should express that.

apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
  name: istio-sidecar-injector-default
  labels:
    istio.io/rev: "default"
    install.operator.istio.io/owning-resource: unknown
    operator.istio.io/component: "Pilot"
    app: sidecar-injector
    release: istiod
    app.kubernetes.io/name: "istiod"
    app.kubernetes.io/managed-by: "Helm"
    app.kubernetes.io/instance: "istiod"
    app.kubernetes.io/part-of: "istio"
    app.kubernetes.io/version: "1.30.0"
    helm.sh/chart: istiod-1.30.0
webhooks:
- name: rev.namespace.sidecar-injector.istio.io
  clientConfig:
    service:
      name: istiod
      namespace: default
      path: "/inject"
      port: 443
  sideEffects: None
  rules:
  - operations: [ "CREATE" ]
    apiGroups: [""]
    apiVersions: ["v1"]
    resources: ["pods"]
  failurePolicy: Fail
  reinvocationPolicy: "Never"
  admissionReviewVersions: ["v1"]
  namespaceSelector:
    matchExpressions:
    - key: istio.io/rev
      operator: In
      values:
      - "default"
    - key: istio-injection
      operator: DoesNotExist
  objectSelector:
    matchExpressions:
    - key: sidecar.istio.io/inject
      operator: NotIn
      values:
      - "false"
- name: rev.object.sidecar-injector.istio.io
  clientConfig:
    service:
      name: istiod
      namespace: default
      path: "/inject"
      port: 443
  sideEffects: None
  rules:
  - operations: [ "CREATE" ]
    apiGroups: [""]
    apiVersions: ["v1"]
    resources: ["pods"]
  failurePolicy: Fail
  reinvocationPolicy: "Never"
  admissionReviewVersions: ["v1"]
  namespaceSelector:
    matchExpressions:
    - key: istio.io/rev
      operator: DoesNotExist
    - key: istio-injection
      operator: DoesNotExist
  objectSelector:
    matchExpressions:
    - key: sidecar.istio.io/inject
      operator: NotIn
      values:
      - "false"
    - key: istio.io/rev
      operator: In
      values:
      - "default"
- name: namespace.sidecar-injector.istio.io
  clientConfig:
    service:
      name: istiod
      namespace: default
      path: "/inject"
      port: 443
  sideEffects: None
  rules:
  - operations: [ "CREATE" ]
    apiGroups: [""]
    apiVersions: ["v1"]
    resources: ["pods"]
  failurePolicy: Fail
  reinvocationPolicy: "Never"
  admissionReviewVersions: ["v1"]
  namespaceSelector:
    matchExpressions:
    - key: istio-injection
      operator: In
      values:
      - enabled
  objectSelector:
    matchExpressions:
    - key: sidecar.istio.io/inject
      operator: NotIn
      values:
      - "false"
- name: object.sidecar-injector.istio.io
  clientConfig:
    service:
      name: istiod
      namespace: default
      path: "/inject"
      port: 443
  sideEffects: None
  rules:
  - operations: [ "CREATE" ]
    apiGroups: [""]
    apiVersions: ["v1"]
    resources: ["pods"]
  failurePolicy: Fail
  reinvocationPolicy: "Never"
  admissionReviewVersions: ["v1"]
  namespaceSelector:
    matchExpressions:
    - key: istio-injection
      operator: DoesNotExist
    - key: istio.io/rev
      operator: DoesNotExist
  objectSelector:
    matchExpressions:
    - key: sidecar.istio.io/inject
      operator: In
      values:
      - "true"
    - key: istio.io/rev
      operator: DoesNotExist
---
# Source: istiod/templates/validatingwebhookconfiguration.yaml
# Created if this is not a remote istiod, OR if it is and is also a config cluster
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
  name: istio-validator-istio-system
  labels:
    app: istiod
    release: istiod
    istio: istiod
    istio.io/rev: "default"
    app.kubernetes.io/name: "istiod"
    app.kubernetes.io/managed-by: "Helm"
    app.kubernetes.io/instance: "istiod"
    app.kubernetes.io/part-of: "istio"
    app.kubernetes.io/version: "1.30.0"
    helm.sh/chart: istiod-1.30.0
webhooks:
  # Webhook handling per-revision validation. Mostly here so we can determine whether webhooks
  # are rejecting invalid configs on a per-revision basis.
  - name: rev.validation.istio.io
    clientConfig:
      # Should change from base but cannot for API compat
      service:
        name: istiod
        namespace: istio-system
        path: "/validate"
    rules:
      - operations:
          - CREATE
          - UPDATE
        apiGroups:
          - security.istio.io
          - networking.istio.io
          - telemetry.istio.io
          - extensions.istio.io
        apiVersions:
          - "*"
        resources:
          - "*"
    # Fail open until the validation webhook is ready. The webhook controller
    # will update this to `Fail` and patch in the `caBundle` when the webhook
    # endpoint is ready.
    failurePolicy: Ignore
    sideEffects: None
    admissionReviewVersions: ["v1"]
    objectSelector:
      matchExpressions:
        - key: istio.io/rev
          operator: In
          values:
          - "default"
---
# Source: istiod/templates/configmap-jwks.yaml
# Not created if istiod is running remotely
---
# Source: istiod/templates/poddisruptionbudget.yaml
# Not created if istiod is running remotely
# a workaround for https://github.com/kubernetes/kubernetes/issues/93476
---
# Source: istiod/templates/remote-istiod-service.yaml
# This file is only used for remote
---
# Source: istiod/templates/revision-tags-mwc.yaml
# Adapted from istio-discovery/templates/mutatingwebhook.yaml
# Removed paths for legacy and default selectors since a revision tag
# is inherently created from a specific revision
# TODO BML istiodRemote.injectionURL is invalid to set if `istiodRemote.enabled` is false, we should express that.
---
# Source: istiod/templates/revision-tags-svc.yaml
# Adapted from istio-discovery/templates/service.yaml
---
# Source: istiod/templates/validatingadmissionpolicy.yaml
# Created if this is not a remote istiod, OR if it is and is also a config cluster
---
# Source: istiod/templates/zzz_profile.yaml
#  Flatten globals, if defined on a per-chart basis
