istio: Sidecar injection customization fails - memory and cpu annotations ignored

Is this the right place to submit this?

  • This is not a security vulnerability or a crashing bug
  • This is not a question about how to use Istio

Bug Description

  1. As you know there are annotations to control the pods memory and cpu requests and limits. We use them
  2. For the specific purpose of optionally setting up a prestop hook for the proxy, we also embed using the methodology discussed in https://istio.io/latest/docs/setup/additional-setup/sidecar-injection/#customizing-injection
{{- define "mesh-container" }}
{{- if .Values.mesh.enabled -}}
{{- if .Values.mesh.prestop.enabled -}}
- name: istio-proxy
  image: auto
  lifecycle:
    preStop:
      exec:
        command: [ "{{ join "\",\"" .Values.mesh.prestop.commands }}" ]
{{- end }}
{{- end }}
{{- end }}
  1. That works great
  2. Except then we found effectively that memory and cpu annotations are ignored. My guess is the template takes precedence and sees no clause so just uses default values?

Version

istio 1.20.2

Additional Information

i have two concerns

  • This isn’t very clear in the docs. There’s comments on the same page like: "Additionally, certain fields are configurable by annotations on the pod, although it is recommended to use the above approach to customizing settings. Additional care must be taken for certain annotations:

If sidecar.istio.io/proxyCPU is set, make sure to explicitly set sidecar.istio.io/proxyCPULimit. Otherwise the sidecar’s cpu limit will be set as unlimited. If sidecar.istio.io/proxyMemory is set, make sure to explicitly set sidecar.istio.io/proxyMemoryLimit. Otherwise the sidecar’s memory limit will be set as unlimited."

but it doesn’t mention they won’t even WORK in this case.

  • creating a complete alternative template would be pretty hard to do and preserve function. In fact arguably it would be a deployment nightmare.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (6 by maintainers)

Commits related to this issue

Most upvoted comments

This is injected as permanent template in the injector CM I assume from what I read? That seems like that’s not terribly flexible since you’d need to have 1 million templates (exaggeration) to cover every permutation of memory and cpu 😉

No, your template would look like

containers:
- name: istio-proxy
  lifecycle:
    preStop:
      exec:
        command: [ "sleep", "{{index .ObjectMeta.Annotations `some-annotation/sleep-duration`}}" ]

then when you want to use it, annotate on your pod inject.istio.io/templates: "custom,sidecar" and some-annotation/sleep-duration: 12s