相关疑难解决方法(0)

golang模板引擎管道

我有一个像这样定义的golang模板

{{- define "test" -}}
{{- printf "%s" .Name | trunc 24 -}}
{{- end -}}
Run Code Online (Sandbox Code Playgroud)

然后我在我的一个文件中使用它:

{{ template "test" . }}
Run Code Online (Sandbox Code Playgroud)

"测试"后点的含义是什么?Golang模板文档说:

{{template "name" pipeline}}
The template with the specified name is executed with dot set
to the value of the pipeline.
Run Code Online (Sandbox Code Playgroud)

但我不确定管道是什么.阅读文档没有结果,任何人都可以再次解释?

另外,为什么我们必须以dot开头的值?例如{{ - printf "%s" .Name | trunc 24 -}}.它也是一种管道吗?

先感谢您!

templates go go-templates

4
推荐指数
1
解决办法
3163
查看次数

Golang模板(helm)迭代地图列表

我正在使用helm生成kubernetes yamls.

我的values.yaml看起来像这样:

...
jobs:
  - nme: job1
    command: [sh, -c, "/app/deployment/start.sh job1"]
    activeDeadlineSeconds: 600
  - name: job2
    command: [sh, -c, "/app/deployment/start.sh job2"]
    activeDeadlineSeconds: 600
...
Run Code Online (Sandbox Code Playgroud)

templates/jobs.yaml

{{ range $i, $job := .Values.jobs -}}
apiVersion: batch/v1
kind: Job
metadata:
  name: {{ template "name" . }}-{{ $job.name }}
  labels:
    chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
spec:
  activeDeadlineSeconds: {{ $job.activeDeadlineSeconds }}
  template:
    metadata:
      labels:
        app: {{ template "name" . }}-{{ $job.name }}
    spec:
      containers:
      - name: {{ .Chart.Name …
Run Code Online (Sandbox Code Playgroud)

templates yaml go kubernetes kubernetes-helm

4
推荐指数
1
解决办法
9179
查看次数

标签 统计

go ×2

templates ×2

go-templates ×1

kubernetes ×1

kubernetes-helm ×1

yaml ×1