将发布时间戳附加到 helm 模板名称
Append release timestamp to helm template name
我正在努力寻找一种方法将 Release.Time 内置函数作为 helm 名称的一部分。
如果我将它包括为:
name: {{ template "myapp.name" . }}-{{ .Release.Time }}
Dry 运行 显示:
name: myapp-seconds:1534946206 nanos:143228281
这似乎是一个 *timestamp.Timestamp 对象或其他东西,因为 {{ .Release.Time | trimPrefix "seconds:" | trunc 10 }}
输出 wrong type for value; expected string; got *timestamp.Timestamp
我可以通过以下方式破解字符串解析:{{ .Release.Time | toString | trimPrefix "seconds:" | trunc 10 }}
,但似乎我应该能够调用 Timestamp 对象上的某些内容来获取秒数。有人知道文档在哪里吗?我在 https://godoc.org/github.com/Masterminds/sprig.
找不到任何参考资料
要格式化时间戳,您可以使用 Sprig 文档中的 date FORMAT TIME
。因为 .Release.Time
在 Helm 3 中被移除了,所以你必须使用 now
来代替:
{{ now | date "20060102150405" }}
参考格式选项:https://golang.org/pkg/time/#Time.Format
但是由于升级,名称中包含时间戳并不是个好主意。
在我的例子中,通过添加以下注释我能够实现这一点,我还使用 helmfile 作为我的 helm 模板的包装器。
annotations:
deploymentTime: {{ now | date "2006-01-02T15:04:05" }}
我正在努力寻找一种方法将 Release.Time 内置函数作为 helm 名称的一部分。
如果我将它包括为:
name: {{ template "myapp.name" . }}-{{ .Release.Time }}
Dry 运行 显示:
name: myapp-seconds:1534946206 nanos:143228281
这似乎是一个 *timestamp.Timestamp 对象或其他东西,因为 {{ .Release.Time | trimPrefix "seconds:" | trunc 10 }}
输出 wrong type for value; expected string; got *timestamp.Timestamp
我可以通过以下方式破解字符串解析:{{ .Release.Time | toString | trimPrefix "seconds:" | trunc 10 }}
,但似乎我应该能够调用 Timestamp 对象上的某些内容来获取秒数。有人知道文档在哪里吗?我在 https://godoc.org/github.com/Masterminds/sprig.
要格式化时间戳,您可以使用 Sprig 文档中的 date FORMAT TIME
。因为 .Release.Time
在 Helm 3 中被移除了,所以你必须使用 now
来代替:
{{ now | date "20060102150405" }}
参考格式选项:https://golang.org/pkg/time/#Time.Format
但是由于升级,名称中包含时间戳并不是个好主意。
在我的例子中,通过添加以下注释我能够实现这一点,我还使用 helmfile 作为我的 helm 模板的包装器。
annotations:
deploymentTime: {{ now | date "2006-01-02T15:04:05" }}