【问题标题】:What does {{ annotation .ObjectMeta `abc` `def` }} mean in helm template{{ annotation .ObjectMeta `abc` `def` }} 在掌舵模板中是什么意思
【发布时间】:2023-01-25 06:47:32
【问题描述】:

我是新掌舵人。当我使用 istio 时,我多次看到类似 {{ annotation ...}} 的内容,更多详细信息:

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 }}

以上代码可以从istio github找到。

我已经阅读了 helm 文档,所以我认为 annotation 是一个函数,而所有其他函数(即 .ObjectMeta、sidecar.istio.io/proxyImage、.Values.global.proxy.image )只是参数。我对吗?

但我不知道annotation 函数是什么。如果有人能指出我正确的方向,那就更好了。

【问题讨论】:

  • 这是 Go text/template 函数调用语法,但 annotation 既不是 Helm-specific 函数也不是 Sprig 函数。你确定标准 Helm 处理这个文件,并且你显示的块没有以某种方式进一步引用吗?
  • @DavidMaze 我添加了 github 链接供您参考。而且我可以确定可以处理 helm chart。
  • 该文件不在图表的 templates 目录中,因此 Helm 不处理它。它是included directly in a ConfigMap。我不完全确定它是如何从那里使用的。

标签: kubernetes-helm istio


【解决方案1】:

我刚刚在 Istio 代码中寻找 annotation 模板函数,它是由 getAnnotation 实现的。该函数的最后一个参数是要使用的默认值(假设 pod 注释不存在)。

正如 David Maze 在上面的 cmets 中所说,annotation 函数不是 Helm 的一部分。有问题的模板实际上不是 Helm 模板,而是存储为静止的Helm 图表中的文件。它的原始内容未经 Helm 渲染器处理就被推送到 ConfigMap 中(将文字字符串 ".Values.global.proxy.image" 作为数据的一部分放入 ConfigMap 中);例如,请参阅 sidecar injector configmap。然后,Istio 控制平面将从 ConfigMap 卷中读取这个 Istio 模板,并使用 Go text/template 渲染它,将其反序列化为一个具有 ObjectMeta 成员的结构,类似于:

type SidecarTemplateData struct {
    ...
    ObjectMeta     *metav1.ObjectMeta
    Spec           *corev1.PodSpec
    ...
}

^ ObjectMetaSpec 属于被注入 sidecar 的 pod。

如果您现在再次阅读粘贴的 Istio 模板,您会看到 istio-proxy 容器将运行由 pod 的 sidecar.istio.io/proxyImage 注释定义的图像,如果注释不存在,则回退到 .Values.global.proxy.image。但它只会在返回值包含斜杠 (/) 时这样做,否则它将使用 .ProxyImage 的值作为 sidecar 图像。娱乐时间。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-08
    • 1970-01-01
    • 2022-11-18
    • 2010-09-29
    • 1970-01-01
    • 2011-08-31
    • 2020-10-09
    • 1970-01-01
    相关资源
    最近更新 更多