Adverbly
Adverbly

Reputation: 2159

Append release timestamp to helm template name

I'm struggling with finding a way to include the Release.Time builtin as part of a helm name.

If I just include it as: name: {{ template "myapp.name" . }}-{{ .Release.Time }}

Dry run shows this: name: myapp-seconds:1534946206 nanos:143228281

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

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.

Upvotes: 17

Views: 20148

Answers (2)

Andres Zepeda
Andres Zepeda

Reputation: 19

In my case, by adding the following annotation I was able to achieve this, I am also using helmfile as the wrapper of my helm templates.

annotations:
   deploymentTime: {{ now | date "2006-01-02T15:04:05" }}

Upvotes: 1

abinet
abinet

Reputation: 2798

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" }}

Refer the format options: https://golang.org/pkg/time/#Time.Format

But having timestamp in the name is not good idea because of upgrades.

Upvotes: 22

Related Questions