将发布时间戳附加到头盔模板名称 [英] Append release timestamp to helm template name
问题描述
我正在努力寻找一种方法来包含 Release.Time 内置为头盔名称的一部分.
I'm struggling with finding a way to include the Release.Time builtin as part of a helm name.
如果我仅将其包括为:
name: {{ template "myapp.name" . }}-{{ .Release.Time }}
If I just include it as:
name: {{ template "myapp.name" . }}-{{ .Release.Time }}
空运行显示以下内容:
name: myapp-seconds:1534946206 nanos:143228281
Dry run shows this:
name: myapp-seconds:1534946206 nanos:143228281
这似乎是* timestamp.Timestamp对象或其他东西,因为{{ .Release.Time | trimPrefix "seconds:" | trunc 10 }}
输出wrong type for value; expected string; got *timestamp.Timestamp
It seems like this is a *timestamp.Timestamp object or something because {{ .Release.Time | trimPrefix "seconds:" | trunc 10 }}
outputs wrong type for value; expected string; got *timestamp.Timestamp
我可以执行以下操作来破解字符串解析:{{ .Release.Time | toString | trimPrefix "seconds:" | trunc 10 }}
,但是看来我应该能够在Timestamp对象上调用某些东西来获取秒数.有人知道这个文档在哪里吗?我在 https://godoc.org/github.com/Masterminds上找不到任何引用/sprig .
I can hack the string parsing by doing: {{ .Release.Time | toString | trimPrefix "seconds:" | trunc 10 }}
, but it seems like I should be able to call something on the Timestamp object to get the seconds. Is anyone aware of where the docs are for this? I can't find any reference to it at https://godoc.org/github.com/Masterminds/sprig.
推荐答案
要格式化时间戳记,可以使用Sprig文档中的date FORMAT TIME
.并且由于.Release.Time
在Helm 3中已被删除,因此您必须使用now
代替:
To format timestamp, you can use date FORMAT TIME
from Sprig doc. And because .Release.Time
got removed in Helm 3, you have to use now
instead:
{{ now | date "20060102150405" }}
请参阅格式选项: https://golang.org/pkg/time/#时间格式
但是由于升级,在名称中添加时间戳并不是一个好主意.
But having timestamp in the name is not good idea because of upgrades.
这篇关于将发布时间戳附加到头盔模板名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!