helm tpl函数在configmap中用于读取index.js

发布于 2025-02-08 05:35:37 字数 1003 浏览 2 评论 0原文

我们如何在配置中读取index.js文件,并使用TPL函数掌舵。 表示如何像index.js文件一样阅读下面的阅读。

  exports.CDN_URL = 'http://100.470.255.255/';
  exports.CDN_NAME = 'staticFilesNew';
  exports.REDIS = [
    {
      host: 'redis-{{.Release.Name}}.{{.Release.Namespace}}.svc.cluster.local',
      port: '26379',
    },
  ];

文件结构在下面

.
├── Chart.yaml
├── templates
│   ├── NOTES.txt
│   ├── _helpers.tpl
│   ├── configmap.yaml
│   ├── deployment.yaml
│   └── service.yaml
└── values
    ├──values.yaml
    ├── index.js

尝试使用以下解决方案在configmap.yaml上,但获取错误

apiVersion: v1
kind: ConfigMap
metadata:
  name: test_config
data:
    {{- tpl (.Files.Get (printf "values/index.js" .)) . | quote 12 }}

获取错误

Error: YAML parse error on app-name/templates/configmap.yaml: error converting YAML to JSON: yaml: line 6: did not find expected key
helm.go:88: [debug] error converting YAML to JSON: yaml: line 6: did not find expected key

How can we read index.js file in configmap with TPL function in Helm.
Means how to read below like index.js file.

  exports.CDN_URL = 'http://100.470.255.255/';
  exports.CDN_NAME = 'staticFilesNew';
  exports.REDIS = [
    {
      host: 'redis-{{.Release.Name}}.{{.Release.Namespace}}.svc.cluster.local',
      port: '26379',
    },
  ];

file structure is below

.
├── Chart.yaml
├── templates
│   ├── NOTES.txt
│   ├── _helpers.tpl
│   ├── configmap.yaml
│   ├── deployment.yaml
│   └── service.yaml
└── values
    ├──values.yaml
    ├── index.js

tried with below solution on configmap.yaml but getting error

apiVersion: v1
kind: ConfigMap
metadata:
  name: test_config
data:
    {{- tpl (.Files.Get (printf "values/index.js" .)) . | quote 12 }}

Getting ERROR

Error: YAML parse error on app-name/templates/configmap.yaml: error converting YAML to JSON: yaml: line 6: did not find expected key
helm.go:88: [debug] error converting YAML to JSON: yaml: line 6: did not find expected key

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软的没边 2025-02-15 05:35:37

因此,它可以使用您正在尝试的东西,但我认为您对凹陷有问题。

使用nindent确保所有行被缩进,并且不要引用该值。

kind: ConfigMap
apiVersion: v1
metadata:
  name: test
  namespace: test
data:
  index.js: | {{- tpl (.Files.Get "values/index.js") $ | nindent 4 }}

So it works what you are trying but I think you have issues with the indention.

Use nindent to ensure all lines are indented and dont quote the value.

kind: ConfigMap
apiVersion: v1
metadata:
  name: test
  namespace: test
data:
  index.js: | {{- tpl (.Files.Get "values/index.js") $ | nindent 4 }}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文