if-1.7.0
2 minute read
KOSI Plugin if Version 1.7.0
Summary
The ‘if’ Plugin for KOSI packages enables the introduction of conditional control flow into your workflow. This plugin allows you to define logic that executes specific actions based on whether a given condition is met. It functions similarly to traditional programming if-else statements, where:
- If the specified condition evaluates to true, a designated block of actions is executed.
- Else (optional): If the condition evaluates to false, an alternative set of actions can be executed instead.
This functionality provides greater flexibility and decision-making capabilities within KOSI packages, allowing workflows to dynamically adapt based on real-time conditions.
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 | defines the block of commands that execute if the ‘condition’ evaluates to true. Commands inside the then block will run sequentially when the condition holds true. |
else | Optional | defines an alternative block of commands that execute if the ‘condition’ evaluates to false. If omitted, no alternative actions will take place when the condition is false. |
Syntax to access plugin variables inside condition :
When using the set
plugin:
condition = "$vars.variableName$"
When using other plugins that set variables (for example osCheck
):
condition = "$variableName$"
Syntax to access KOSI templating of values.yaml inside condition :
condition = '{{values.variable}}'
Example
languageversion = "1.0.0";
apiversion = "kubernative/kubeops/sina/user/v4";
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 = "'{{values.myVar}}' < 0") then
{
print(message = "myVar is less than 0.");
}
else
{
print(message = "myVar is equal or greater than 0.");
}
print(message = "This will always print.");
}
Result
[ 06/22/2021 16:56:54 Info default ] myVar is equal or more than 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 than 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.