1
00:00:00,000 --> 00:00:12,733
Hi, let us understand more about functions. As a part of values yaml file or the templates yaml file

2
00:00:12,733 --> 00:00:16,166
We can put in functions to compute the values.

3
00:00:16,166 --> 00:00:21,166
Let us see some example that's going to give us more clarity.

4
00:00:21,166 --> 00:00:25,899
Let me get into the values file and add some values.

5
00:00:25,900 --> 00:00:29,000
I'm going to edit the value file.

6
00:00:29,000 --> 00:00:30,933
Here we were adding key value pair

7
00:00:30,933 --> 00:00:37,933
Now I'm going to add a type of collection within the yaml file where I'm going to have key as infra

8
00:00:37,933 --> 00:00:42,066
And it's going to have a couple of key value pairs, zone and region.

9
00:00:42,066 --> 00:00:47,799
Let me go ahead and add it. Dont worry about the content that I am adding over here.

10
00:00:47,800 --> 00:00:51,500
I will be adding it as a resources within the lecture.

11
00:00:51,500 --> 00:00:56,600
So I'm adding a key project code and it's having some value, then I'm adding another key.

12
00:00:56,600 --> 00:01:01,066
That's going to have collection of key value pairs.

13
00:01:01,066 --> 00:01:05,832
So this is another example to demonstrate how to access the collection as well.

14
00:01:05,833 --> 00:01:07,766
Let me get into the templates.

15
00:01:07,766 --> 00:01:12,032
Let me edit the template file

16
00:01:12,033 --> 00:01:14,833
Here I'm going to add and access the values.

17
00:01:14,833 --> 00:01:19,799
Say, for example Zone, Region and Project code.

18
00:01:19,800 --> 00:01:27,300
I'm adding zone as key, and I'm adding template derivative within that I am adding a function called quote.

19
00:01:27,300 --> 00:01:34,266
So the function quote will be getting one argument and it's going to quote that specific value that's

20
00:01:34,266 --> 00:01:35,966
being read from the value file.

21
00:01:35,966 --> 00:01:39,399
So within the value file it's going to read zone, within infra.

22
00:01:39,400 --> 00:01:44,800
And it's going to surround it with double quotes, the same way it's going to read the project code from

23
00:01:44,800 --> 00:01:48,433
the values file and it is going to convert it into uppercase.

24
00:01:48,433 --> 00:01:54,299
There are n number of predefined functions available as a part of the go template that can be accessed

25
00:01:54,300 --> 00:02:01,166
from this particular location or helm supports the functions defined within sprig library as well.

26
00:02:01,166 --> 00:02:07,232
So within sprig librrary there are n number of useful template functions for go templates.

27
00:02:07,233 --> 00:02:10,066
Here we can use any of these functions.

28
00:02:10,066 --> 00:02:13,332
We do have lots of simple to complex function within it.

29
00:02:13,333 --> 00:02:19,099
Say for example, within string function we do have upper which is going to take an argument and convert

30
00:02:19,100 --> 00:02:21,300
that into uppercase.

31
00:02:21,300 --> 00:02:28,933
The same way we do have quote which is going to convert or enclose the string using a double quote.

32
00:02:28,933 --> 00:02:34,233
So I'm going to call the function within the template directive and pass the value reqired for that particular

33
00:02:34,233 --> 00:02:39,699
function as an argument and pass the required argument to those functions.

34
00:02:39,700 --> 00:02:46,300
Let me save this particular template and I'm going to do a dry run. Let me get into the parent directory

35
00:02:46,300 --> 00:02:49,500
where I do have the chart resources.

36
00:02:49,500 --> 00:02:52,900
My chart resources are available as a part of mychart.

37
00:02:52,900 --> 00:02:58,833
So I'll be calling the mychart and do a dry run and I will provide the release name as well

38
00:02:58,833 --> 00:03:05,699
So it's going to read the values file, do all the computation and that will be replaced within the

39
00:03:05,700 --> 00:03:07,500
config map yaml file. Here

40
00:03:07,500 --> 00:03:11,966
We can see it read the zones and it enclosed within the double quotes.

41
00:03:11,966 --> 00:03:13,632
The same way region is read.

42
00:03:13,633 --> 00:03:16,299
And it is enclosed within the double quote.

43
00:03:16,300 --> 00:03:22,000
And the project code, it is read as a small case and we passed it to convert it into uppercase

44
00:03:22,000 --> 00:03:26,266
And that is getting passed to this particular YAML file.

45
00:03:26,266 --> 00:03:29,266
And functions play a very significant role where

46
00:03:29,266 --> 00:03:36,299
I can convert whatever the data that I wanted and dynamically it'll help me to compute the required values.

47
00:03:36,300 --> 00:03:42,200
And along with functions, we will be using another useful feature called pipeline that we will be seeing

48
00:03:42,200 --> 00:03:44,900
it in the next lecture. So in a quick summary

49
00:03:44,900 --> 00:03:50,666
We have seen how to use functions as a part of the template directive and the introduction to another

50
00:03:50,666 --> 00:03:52,699
useful library called Sprig.

