【问题标题】:Read file in Helm helper chart在 Helm 帮助图表中读取文件
【发布时间】:2022-01-14 18:54:36
【问题描述】:

我正在尝试创建一个帮助图表,它将文件内容提供给其他图表。基本上,由于我的所有应用都有几乎相同的logging.xml 配置,我想在一个地方定义它并在应用图表之间共享。

到目前为止,我已经成功创建了一个模板:

{{- define "helpers.logging.xml" -}}
    logback.xml: |-
        {{ .Files.Get "resources/logback.xml" }}
{{- end }}

帮助图表中的文件结构如下所示:

helpers
  |--templates
     |--_helpers.tpl
  |-resources
     |--logback.xml
  Chart.yaml

在主图表中,我尝试传递模板的结果。但只有当我在应用图表本身中有一个resouses/logging.xml 文件时它才有效。

apiVersion: v1
kind: ConfigMap
metadata:
  name: logging.{{ .Release.Name }}
  namespace: {{ .Release.Namespace }}
data:
  {{ include "helpers.logging.xml" . }}

有人可以告诉我什么是错的吗?用 Helm 真的可以做这样的事情吗?

【问题讨论】:

    标签: kubernetes-helm helm3


    【解决方案1】:

    所以最后我找到了一个适合我需要的解决方案。我没有从资源文件中获取资源,而是使用这样的单个模板创建了一个额外的帮助程序:

    {{- define "templates.logback.xml" -}}
        logback.xml: |-
            <?xml version="1.0" encoding="UTF-8"?>
            <configuration>
              <!-- default configuration goes here -->
              <!--  ...  -->
    
              <!-- include custom config -->
              <include file="logback-custom.xml"/>
            </configuration>
    {{- end }}
    

    在图表中,我有一个这样配置的 configMap:

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: logging.{{ .Release.Name }}
      namespace: {{ .Release.Namespace }}
    data:
      {{ include "templates.logback.xml" . }}
      logback-custom.xml: |
        <included>
          <!-- custom config -->
        </included>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-24
      • 1970-01-01
      • 1970-01-01
      • 2011-09-07
      • 1970-01-01
      • 2018-11-03
      • 1970-01-01
      相关资源
      最近更新 更多