简体   繁体   English

在 Helm configMap 中包含文件内容后如何控制缩进?

[英]How to control indent after including file content in Helm configMap?

I'm setting up a ConfigMap for my Helm chart.我正在为我的 Helm 图表设置一个 ConfigMap。

As per good practice, I want to include non-yaml resources through separate files rather than inline.根据良好的做法,我想通过单独的文件而不是内联来包含非 yaml 资源。 Currently I am trying to include both an xml file and a tpl helper in my ConfigMap under "data".目前,我试图在“数据”下的 ConfigMap 中同时包含一个 xml 文件和一个 tpl 帮助程序。 Both are read without issue in the below code.在下面的代码中读取两者都没有问题。 But I cannot seem to make the indentation for the keys work properly.但我似乎无法使键的缩进正常工作。

My ConfigMap:我的配置映射:

apiVersion: v1
kind: ConfigMap
metadata:
    name: {{ template "name" . }}
    labels:
        app: {{ template "name" . }}
        chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
        release: {{ quote .Release.Name }}
        heritage: {{ quote .Release.Service }}
        name: {{ template "name" . }}
data:
    logback.xml: |-
        {{- .Files.Get "application-resources/logback.xml" | nindent 8 -}}
    application.yml: |-
        {{- include "application.yml" . | nindent 8 -}}

This produces the following indentation (actual values are removed for readability):这会产生以下缩进(为了便于阅读,删除了实际值):

apiVersion: v1
kind: ConfigMap
metadata:
    name: erklaering-anden-lov-detektor-app
    labels:
        app: name-of-app
        chart: name-of-chart
        release: "release-name"
        heritage: "Tiller"
        name: name-of-app
data:
    logback.xml: |-
      <?xml version="1.0" encoding="UTF-8"?>
      <configuration scan="true">
          <xml-stuff>
      </configuration>
      application.yml: |-    
      application.yml.contents

Which should be:应该是:

apiVersion: v1
kind: ConfigMap
metadata:
    name: erklaering-anden-lov-detektor-app
    labels:
        app: name-of-app
        chart: name-of-chart
        release: "release-name"
        heritage: "Tiller"
        name: name-of-app
data:
    logback.xml: |-
      <?xml version="1.0" encoding="UTF-8"?>
      <configuration scan="true">
          <xml-stuff>
      </configuration>
    application.yml: |-    
      application.yml.contents

I'm at my wit's end.我已经无计可施了。 What am I doing wrong?我究竟做错了什么? How do I make yaml snap back to recognizing configMap's own indentation and/or explicitly control it?如何让 yaml 快速恢复以识别 configMap 自己的缩进和/或明确控制它?

Try this:尝试这个:

data:
    logback.xml: |-
        {{- .Files.Get "application-resources/logback.xml" | nindent 8 }}
    application.yml: |-
        {{- include "application.yml" . | nindent 8 -}}

I've removed the "-" from the 3rd line as it removes following whitespace.我已经从第三行中删除了“-”,因为它删除了后面的空格。

You can also have a look at this GitHub Issue #3470 .您还可以查看此 GitHub 问题#3470

If you need more help, you can check the documentation for Chart Development Tips and Tricks如果需要更多帮助,可以查看Chart Development Tips and Tricks的文档

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

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