loop-1.7.0
2 minute read
KOSI Plugin loop Version 1.7.0
Summary
The loop plugin enables repeated execution of specific parts of your KOSI package YAML while iterating over a list. It functions similarly to a “for each” loop in other programming languages. During each iteration, an iterator variable holds the current element from the list, allowing dynamic access within the looped section.
Keys
Key | Description | |
---|---|---|
iterator | Mandatory | Specifies the variable name that will hold the current item in the list during each loop iteration. Must be a valid string representing a variable name. |
list | Mandatory when listVar is not set | Defines an inline list in YAML format that will be iterated over. Cannot be used together with listVar. |
listVar | Mandatory when list is not set | Specifies a pre-defined variable (set by another plugin) that contains a list. Allows looping over dynamic lists instead of hardcoded values. |
Example 1 - Iterating Over a List
In this example, the loop iterates over a predefined list [1,2,3], and the number iterator variable holds the current item in each iteration.
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 =
{
input = "template.yaml";
}
containers =
{
example = ["docker.io", "nginx", "latest"];
}
install
{
loop
(
iterator = "number";
list = "[1,2,3]";
)
{
fprint
(
message = "Hello {0}";
variables ="[number]";
);
}
}
[ 06/18/2021 13:04:29 Info default ] Hello 1
[ 06/18/2021 13:04:29 Info default ] Hello 2
[ 06/18/2021 13:04:29 Info default ] Hello 3