繁体   English   中英

是否可以将模板化的 blob 文本包含到 values.yaml 中?

[英]Is it possible to include a templated blob text into values.yaml?

出于向后兼容的动机(并减少必须更新 src 代码的负担)如下:

我有一个用户输入:

$values.yaml

output:
  endpoint: MYENDPOINT
specialFile: 
  config1: |-
    Some very nicely formated text.
    Wow, such sample. 
    Much text.
    [...]
  config2: |-
    # this is also text but i need to remove |- for interpretation
    {{- $.Files.Get "configs/include.conf" | nindent 4 }}

我想用一团文本替换:

$configs/include.conf

<match **>
  @type http
  endpoint_url    {{ .Values.output.endpoint }}
  serializer      json
</match>

这样 output 替换文本上的 var,文本替换 values.yaml 上的值。 这可能吗? 我知道这几乎是不可能的事情。 我已经看到有人用自己替换 values.yaml (我自己没试过),但这可能吗?

或者我可以覆盖 .Values.specialFile.configs2 值而不直接写入 .Values 文件并以某种方式覆盖变量,也许使用模板?

这可以通过使用tpl将包含的文件作为嵌套模板处理:

{{ $endpoint := "MYENDPOINT" }}
output:
  endpoint: {{ $endpoint }}
specialFile: 
  config1: |-
    Some very nicely formated text.
    Wow, such sample. 
    Much text.
    [...]
  config2: |-
    # this is also text but i need to remove |- for interpretation
    {{- tpl ($.Files.Get "configs/include.conf") $endpoint | nindent 4 }}

为了避免重复,我将端点放在一个变量中并将其传递给加载的模板。 因此,它将在此处以{{.}}的形式提供:

<match **>
  @type http
  endpoint_url    {{ . }}
  serializer      json
</match>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM