if-1.4.0
2 minute read
KOSI Plugin if Version 1.4.0
Changelog Plugin if 1.4.0
Update
- updateing dependencies
Summary
The ‘if’ Plugin allowes you to introduce controll flows into your KOSI packages. It implements the classic ‘if’ ( + optional ’else’) construct.
Keys
Key | Description | |
---|---|---|
condition | Mandatory | set to a string that will be evaluated as an expression. Condition is based on net5.0 DataColumn expressions and follows almost the same syntax. The only difference are plugin variables can also be used in the condition |
then | Mandatory | expects the key “tasks” to be child. If the"condition" is true, then it will execute “tasks” under “then”. |
else | Optional | expects the key “tasks” to be child.If “condition” is false, then it will execute “tasks” under “else”. |
tasks | – | tasks key works the exact same way as the global list of tasks in your package. |
Syntax to access plugin variables inside condition :
condition= "$variableName$"
Syntax to access KOSI templating of values.yaml inside condition :
condition= '{{values.variable}}'
Example
languageversion = "0.1.0";
apiversion = "kubernative/kubeops/sina/user/v3";
name = "kosi-example-packagev3";
description = "kosi-example-package";
version = "0.1.0";
docs = "docs.tgz";
logo = "logo.png";
files =
{
guestbook= "guestbook.tgz";
gbValues= "gbValues.yaml";
values2= "values2.yaml";
}
containers =
{
example=["docker.io", "nginx", "latest"];
}
install
{
cmd(command='"echo Using the if plugin."');
if(condition='"$myVar$ < 0"')
then{
print(message='"myVar is less then 0."');
}
else{
print(a='"myVar is equal or greater then 0."');
}
print(message='"This will always print."');
}
Result
[ 06/22/2021 16:56:54 Info default ] myVar is equal or more then 0
[ 06/22/2021 16:56:54 Info default ] this will always print
or
[ 06/22/2021 16:57:37 Info default ] myVar is less then 0
[ 06/22/2021 16:57:37 Info default ] this will always print
All expressions are expected to evaluate to either ‘True’ or ‘False’ otherwise the ‘if’ plugin will exit with an error.