3

I am now working in the migration from helm 2 to 3.

I am using the value of .Release.time.Seconds in my charts. I have seen that in helm 3 .Release.time does not exists. Trying to use now as it is explained in this stackoverflow question, I can do the instalation, but I do not get the expected value.

For example, with the following code:

 template:
    metadata:
      labels:
        dateInSeconds: "{{ .Release.Time.Seconds }}" 

The label gets the value dateInSeconds: 1611923156

If I use the now function:

 template:
    metadata:
      labels:
        dateInSeconds: {{ now | quote }}  

The label gets the value dateInSeconds: "2021-02-01 12:05:28.6116854 +0100 CET m=+2.394553701"

pcampana
  • 2,413
  • 2
  • 21
  • 39

2 Answers2

5

I have found the solution in sprig. For getting the epoch time I can use unixEpoch.

So the solution is:

template:
    metadata:
      labels:
        dateInSeconds: {{ now | unixEpoch | quote}}   
pcampana
  • 2,413
  • 2
  • 21
  • 39
  • In case you need it working at the same time for helm 2 and 3, i used the following code: `​dateInSeconds: {{ now | quote | trunc 28 | replace "\"" "" | replace ":" "-" | replace " " "_" | quote}}` – pcampana Feb 01 '21 at 11:46
1

You can use the below instead.

{{ now | unixEpoch }}
Shuo
  • 11
  • 1