1
00:00:00,000 --> 00:00:07,100
Hi, Let us understand about

2
00:00:07,100 --> 00:00:14,000
Flow control, the important building block of the template is this flow control and it will be achieved

3
00:00:14,000 --> 00:00:17,533
using if else statement. This is very similar to the

4
00:00:17,533 --> 00:00:21,566
If else statements we have in any other languages where

5
00:00:21,566 --> 00:00:28,432
The condition will be evaluated using the pipeline and it will be used along with the if or elseif

6
00:00:28,433 --> 00:00:33,333
conditions. If the condition gets to true, it will be getting into that particular block

7
00:00:33,333 --> 00:00:37,699
And the statements within the block will get executed, if the condition fails

8
00:00:37,700 --> 00:00:41,400
It's going to move on to the next condition that is else if

9
00:00:41,400 --> 00:00:46,166
Again, there is going to be another pipeline or condition evaluation that will be evaluated.

10
00:00:46,166 --> 00:00:53,632
If that evaluated to true, then the blocks within that will get evaluated and we will be having a else condition

11
00:00:53,633 --> 00:01:00,266
where if all the above conditions failed, then the statements within the else conditions will be executed.

12
00:01:00,266 --> 00:01:03,066
That's like a default keys and elseif,

13
00:01:03,066 --> 00:01:09,332
else conditions are optional and only if statement is sufficient enough, most of the places we

14
00:01:09,333 --> 00:01:15,099
will be using that to verify the conditions and execute a few set of statements.

15
00:01:15,100 --> 00:01:18,200
Let's have a quick check on what all situations

16
00:01:18,200 --> 00:01:21,066
The condition would be evaluated as false.

17
00:01:21,066 --> 00:01:28,332
If the pipeline is evaluated, as the following values, it will be considered as false, like boolean

18
00:01:28,333 --> 00:01:33,966
false or a numerical value of zero, empty string or nil value.

19
00:01:33,966 --> 00:01:41,666
That is like null and any empty collection of map, slice, tuple, dictionary or an array

20
00:01:41,666 --> 00:01:45,366
Now let us see a small example. Here I do have the template.

21
00:01:45,366 --> 00:01:49,499
Let me get into the sample template that we had created. Here

22
00:01:49,500 --> 00:01:53,866
I am going to update the values, within the values file

23
00:01:53,866 --> 00:01:56,932
Already we do have a key called infra, within that

24
00:01:56,933 --> 00:01:59,999
I do have a collection of key and value.

25
00:02:00,000 --> 00:02:02,800
I do have the keys like Zone and region.

26
00:02:02,800 --> 00:02:09,066
I'm going to evaluate this specific key region, whether it is equal to a specific value or not.

27
00:02:09,066 --> 00:02:13,232
If it is evaluated as true, I will be taking some decision.

28
00:02:13,233 --> 00:02:16,633
Let me go ahead and change the templates, within the template

29
00:02:16,633 --> 00:02:18,933
Let me go ahead and edit it.

30
00:02:18,933 --> 00:02:23,866
I'm going to remove the other values that we added for the test purpose.

31
00:02:23,866 --> 00:02:32,432
Here I'm going to add a condition if, and I can have the logical conditions like equal, not equal, all possible conditions available.

32
00:02:32,433 --> 00:02:43,466
I'm going to evaluate for values.infra.region and that should be equal to us-e

33
00:02:43,466 --> 00:02:48,532
If this condition succeeded, then I'm going to add another key value pair true

34
00:02:48,533 --> 00:02:50,299
Then I need to end the condition.

35
00:02:50,300 --> 00:02:52,133
I don't want any if else condition.

36
00:02:52,133 --> 00:02:56,766
So I'm going to end it with double open bracket and close bracket.

37
00:02:56,766 --> 00:03:01,366
Observe very carefully the indentation should start at this specific location.

38
00:03:01,366 --> 00:03:03,832
or else its going to give error messages.

39
00:03:03,833 --> 00:03:05,199
We will try out those scenarios

40
00:03:05,200 --> 00:03:11,833
as well. I returned the changes let me go ahead and do a dry run using helm install

41
00:03:11,833 --> 00:03:13,866
dry run and in the debug mode

42
00:03:13,866 --> 00:03:19,666
I'm going to give a name to this particular release and execute the mychart resources.

43
00:03:19,666 --> 00:03:22,232
So the value it evaluated to be true.

44
00:03:22,233 --> 00:03:25,166
So what happened it printed it as true.

45
00:03:25,166 --> 00:03:29,266
Now, let me go ahead and change the value.

46
00:03:29,266 --> 00:03:34,766
I'm changing it to us-w

47
00:03:34,766 --> 00:03:39,599
Now, let me go ahead and do a dry run

48
00:03:39,600 --> 00:03:45,200
It should not print the value ha:true, because the condition did not get evaluated, the same

49
00:03:45,200 --> 00:03:50,566
way I can have if else conditions as well, the very important thing to be noted in this specific

50
00:03:50,566 --> 00:03:54,532
condition is how to align this particular statement.

51
00:03:54,533 --> 00:03:56,899
Let's try out a few scenarios.

52
00:03:56,900 --> 00:04:02,200
And before that, I need to change the values so that the condition will get evaluated to be true.

53
00:04:02,200 --> 00:04:06,033
So I am changing it back to us-e

54
00:04:06,033 --> 00:04:10,766
Now, let me go ahead and execute the dry run.

55
00:04:10,766 --> 00:04:12,766
If you observe the result very carefully

56
00:04:12,766 --> 00:04:17,499
We do have an empty line over here and within YAML file empty lines

57
00:04:17,500 --> 00:04:18,866
It's not going to create a problem.

58
00:04:18,866 --> 00:04:24,499
But that is not advised to have, only the important thing that we need to take over here is the

59
00:04:24,500 --> 00:04:28,400
indentation. The indentation is done properly with two spaces.

60
00:04:28,400 --> 00:04:31,366
So it should work, but it is not recommended.

61
00:04:31,366 --> 00:04:33,299
Now, let's go ahead and test it out.

62
00:04:33,300 --> 00:04:38,000
What if we provide some indentation or some additional space in the template

63
00:04:38,000 --> 00:04:39,033
Let's check the result.

64
00:04:39,033 --> 00:04:43,433
Let me get into the templates.

65
00:04:43,433 --> 00:04:46,633
Let's try this out, how it's going to work.

66
00:04:46,633 --> 00:04:49,799
Let me go ahead and do the dry run.

67
00:04:49,800 --> 00:04:57,333
Yes. The indentation worked fine. The reason because let me get into the template.

68
00:04:57,333 --> 00:05:02,566
The condition will get evaluated and from this particular point, it's going to provide two indentation

69
00:05:02,566 --> 00:05:04,332
With this particular understanding

70
00:05:04,333 --> 00:05:07,399
Let me go ahead and do this.

71
00:05:07,400 --> 00:05:11,900
Here, the key value pair will be indented with two more additional spaces.

72
00:05:11,900 --> 00:05:17,200
And that is not a valid YAML file because it should be under another key.

73
00:05:17,200 --> 00:05:24,200
Now, let me go ahead and do a dry run on this particular case as well, and see how the error will be.

74
00:05:24,200 --> 00:05:28,700
So here I got an error because values are not allowed in this context.

75
00:05:28,700 --> 00:05:34,033
The reason why I am demonstrating various options most of the time the mistakes happen in this specific

76
00:05:34,033 --> 00:05:38,933
area of indentation while using the conditional statements.

77
00:05:38,933 --> 00:05:43,433
Now, let me go ahead and correct this.

78
00:05:43,433 --> 00:05:44,566
So this should work.

79
00:05:44,566 --> 00:05:50,666
But at the same time, let's understand how to remove the blank line that we had got, so that can be

80
00:05:50,666 --> 00:05:56,032
removed using a minus symbol over here and a minus symbol over here.

81
00:05:56,033 --> 00:06:01,166
That means the new line in that specific location should be removed.

82
00:06:01,166 --> 00:06:06,332
So there will be a new line at the starting of this particular condition evaluation and that will be removed.

83
00:06:06,333 --> 00:06:10,433
And in the end, also, there will be a new line condition and that will be removed.

84
00:06:10,433 --> 00:06:14,933
Now, let me go ahead and do a dry run.

85
00:06:14,933 --> 00:06:16,933
Now, there is no new line character.

86
00:06:16,933 --> 00:06:19,799
And everything is working fine. Now let's see

87
00:06:19,800 --> 00:06:23,166
What if I deleted the new line in the end as well

88
00:06:23,166 --> 00:06:25,199
That should also be not done.

89
00:06:25,200 --> 00:06:28,200
Anyway, let's go ahead and try it out.

90
00:06:28,200 --> 00:06:37,766
So here the end, I'm going to remove the existing new line so that can be provided by adding a dash over here.

91
00:06:37,766 --> 00:06:38,632
So what will happen

92
00:06:38,633 --> 00:06:45,633
It'll remove the starting new line as well as the end new line and this ha it will try to add over here along

93
00:06:45,633 --> 00:06:48,533
with this specific project code

94
00:06:48,533 --> 00:06:53,499
where that will fail because that's not a valid yaml file.

95
00:06:53,500 --> 00:06:57,700
Let's go ahead and do the dry run.

96
00:06:57,700 --> 00:07:01,300
yes the parsing failed because that's not a valid yaml file

97
00:07:01,300 --> 00:07:04,066
So what happened was.

98
00:07:04,066 --> 00:07:10,699
After evaluation, this ha:true will get added next to project code and the value.

99
00:07:10,700 --> 00:07:14,233
So it's going to have another colon and that will fail.

100
00:07:14,233 --> 00:07:16,833
So this is not a right option as well.

101
00:07:16,833 --> 00:07:25,533
So the right thing to do is remove the new line in the beginning of each condition as well as in the end.

102
00:07:25,533 --> 00:07:31,299
And have the indentation and the location from where the condition is getting executed the same place

103
00:07:31,300 --> 00:07:37,600
The text within that will also get aligned in case if we have this particular condition evaluation in

104
00:07:37,600 --> 00:07:40,900
the beginning, then properly the indentation should be provided.

105
00:07:40,900 --> 00:07:42,733
So this is the right way to do.

106
00:07:42,733 --> 00:07:45,166
Finally, let me go ahead and do the dry run

107
00:07:45,166 --> 00:07:51,466
And the reason why I am not installing and uninstalling, the dry run is sufficient enough to evaluate the condition

108
00:07:51,466 --> 00:07:54,866
and how that particular manifest file would look like.

109
00:07:54,866 --> 00:07:58,966
So we have seen what are the different options to use the if else conditions

110
00:07:58,966 --> 00:08:04,799
And the important thing to take care of removing the new line as well as what to do and what not to

111
00:08:04,800 --> 00:08:06,900
do while adding the conditional statements.

