1
00:00:00,000 --> 00:00:10,933
Hi, Let us understand how to use variables, as we discussed in the earlier lecture, whenever I wanted

2
00:00:10,933 --> 00:00:15,533
to inject a value within a with block, which is out of its scope

3
00:00:15,533 --> 00:00:23,199
I need to use the variable. The same way within the range looping if I wanted to assign or process any

4
00:00:23,200 --> 00:00:28,900
specific element then I need to assign it to variable and process it within the block.

5
00:00:28,900 --> 00:00:33,800
For that, I need to assign a value into a variable.

6
00:00:33,800 --> 00:00:40,833
The syntax for that is the name of the variable with a dollar sign and the special assignment operator

7
00:00:40,833 --> 00:00:43,799
that we will be using is :=

8
00:00:43,800 --> 00:00:49,266
And then the value that we are reading from the template or a literal value.

9
00:00:49,266 --> 00:00:52,932
Let's go ahead and do a small demo and get better understanding.

10
00:00:52,933 --> 00:00:59,066
Let me modify the template.

11
00:00:59,066 --> 00:01:03,432
Within the template, I'm going to add few lines.

12
00:01:03,433 --> 00:01:08,399
So what I'm doing over here, I do have a with block and outside the block

13
00:01:08,400 --> 00:01:15,266
I'm reading the release name and assigning in to a variable called relname.

14
00:01:15,266 --> 00:01:21,899
And that is starting with the dollar sign that is the syntax and the operated to assign the value is :=

15
00:01:21,900 --> 00:01:26,666
And this particular variable can be accessed across the template and within the with block

16
00:01:26,666 --> 00:01:32,999
I am going to read that specific variable that is dollar or relname and print it with the

17
00:01:33,000 --> 00:01:39,300
key release. Earlier when we are accessing this particular value release.name

18
00:01:39,300 --> 00:01:42,200
That is the builtin object I was not able to read.

19
00:01:42,200 --> 00:01:50,700
Now what I am doing, I am assigning it to a variable and that variable will have the scope across the template.

20
00:01:50,700 --> 00:01:55,966
And over here I have added a dash in the beginning as well as in the end, because it's not going to

21
00:01:55,966 --> 00:02:03,199
print anything and if I doesn't provide this particular dash, it's going to add a new line character.

22
00:02:03,200 --> 00:02:07,566
And there will be a new line or empty line within that YAML file.

23
00:02:07,566 --> 00:02:11,866
Even though that is valid, that's not recommended.

24
00:02:11,866 --> 00:02:16,799
So let me go ahead and save this particular file and execute it.

25
00:02:16,800 --> 00:02:22,766
So the execution I'm going to do using a dry run.

26
00:02:22,766 --> 00:02:24,699
It's able to print the release name.

27
00:02:24,700 --> 00:02:29,566
That's the name that I provided as a part of the dry run statement.

28
00:02:29,566 --> 00:02:34,966
And there is no new line character where we are reading or assigning the variable.

29
00:02:34,966 --> 00:02:38,832
All other lines within the with block is same as we had earlier.

30
00:02:38,833 --> 00:02:41,399
And this is a proof where

31
00:02:41,400 --> 00:02:47,266
We can assign a builtin object into a variable and read it within the with block.

32
00:02:47,266 --> 00:02:49,466
Now let us see another demo where

33
00:02:49,466 --> 00:02:55,132
I'm going to assign an element within the range into a variable and read it within the range block.

34
00:02:55,133 --> 00:03:02,133
So within the template let me go ahead and edit the template.

35
00:03:02,133 --> 00:03:13,633
I'm going to remove these lines and add a range block.

36
00:03:13,633 --> 00:03:15,399
So within the range, what I'm doing

37
00:03:15,400 --> 00:03:21,966
I'm assigning that specific element that is values.langused as a part of topping

38
00:03:21,966 --> 00:03:23,599
And I'm going to have the index

39
00:03:23,600 --> 00:03:30,566
index of the element will be getting assigned to this, and I will printing both the index and the

40
00:03:30,566 --> 00:03:34,566
individual element that is being read within the collection.

41
00:03:34,566 --> 00:03:40,366
So I I'll be having key as the index and value as the actual element within the collection.

42
00:03:40,366 --> 00:03:44,599
And this particular collection already we do have within the values file

43
00:03:44,600 --> 00:03:47,100
Anyway we can go ahead and verify once.

44
00:03:47,100 --> 00:03:49,066
So we do have langused.

45
00:03:49,066 --> 00:03:52,332
And I do have a collection of values.

46
00:03:52,333 --> 00:03:55,866
Now I'm going to do a dry run.

47
00:03:55,866 --> 00:03:59,499
So I'm getting the index and the actual value.

48
00:03:59,500 --> 00:04:03,800
This is one another way of reading the variable and as a part of the variable

49
00:04:03,800 --> 00:04:06,600
another important thing to understand is the dollar.

50
00:04:06,600 --> 00:04:08,233
That's a global variable

51
00:04:08,233 --> 00:04:11,999
And this particular variable will always point to the root context.

52
00:04:12,000 --> 00:04:16,233
So I can access the global objects using the variable dollar.

53
00:04:16,233 --> 00:04:21,599
Let us see some demo about dollar variable as well.

54
00:04:21,600 --> 00:04:24,333
I'm going to edit this particular file.

55
00:04:24,333 --> 00:04:28,433
Let me go ahead and add few labels to this.

56
00:04:28,433 --> 00:04:32,866
So as a part of the label let me delete these

57
00:04:32,866 --> 00:04:38,999
So here I am adding the value by accessing the global variable dollar.

58
00:04:39,000 --> 00:04:40,766
So that will have the root context.

59
00:04:40,766 --> 00:04:42,566
So I can access the global object.

60
00:04:42,566 --> 00:04:49,399
Here I am accessing the global object, chart.name, chart.version, release details as well as the

61
00:04:49,400 --> 00:04:58,100
chart appversion. Let me go ahead and execute this particular chart and for almost all the demo

62
00:04:58,100 --> 00:05:03,466
I'm using the dry run because there is no need to go ahead and deploy. If a dry run is good definitely

63
00:05:03,466 --> 00:05:09,799
it will get deployed into the kubernetes cluster. Once we learn each and every individual concept, we can consolidate

64
00:05:09,800 --> 00:05:14,100
everything together and release them into the kubernetes cluster.

65
00:05:14,100 --> 00:05:17,966
I'm going to do a dry run of the chart mychart.

66
00:05:17,966 --> 00:05:21,932
So I'm able to get the chart releases and release

67
00:05:21,933 --> 00:05:26,833
Name, the version of the helm that we're using and what it is managed by

68
00:05:26,833 --> 00:05:30,966
That is the release service all the information we're able to get.

69
00:05:30,966 --> 00:05:33,332
So in a quick summary we learnt three major concepts.

70
00:05:33,333 --> 00:05:40,433
That is, how to inject a variable into a with block and how to assign a individual element of a

71
00:05:40,433 --> 00:05:47,799
range and access the individual element and its index within the range looping and how to access the

72
00:05:47,800 --> 00:05:51,733
global variable dollar and use the global objects.

