Skip to content

Commit

Permalink
option to create an object only once in multi-iteration jobs (kube-bu…
Browse files Browse the repository at this point in the history
…rner#557)

* kube-burner to create an object only once
In certain cases on creating cluster wide resources like clusterroles,
operator spec CRDs, storage classes, would not have to run for every
iteration, so having this additional option let us run an object
once during the first iteration of a job and skip for the rest.
We have many of such scenarios with ICNI implementaion like
serviceaccount, SRIOV specs, ICNI CRDs are required to run only
once within the same job.

Signed-off-by: Murali Krishnasamy <[email protected]>

* updated documents and logs

Signed-off-by: Murali Krishnasamy <[email protected]>

* updated casing

Signed-off-by: Murali Krishnasamy <[email protected]>

* updated readme

Signed-off-by: Murali Krishnasamy <[email protected]>

---------

Signed-off-by: Murali Krishnasamy <[email protected]>
  • Loading branch information
mukrishn authored Jan 5, 2024
1 parent 4ace281 commit 72f1d38
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
28 changes: 28 additions & 0 deletions docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Each object element supports the following parameters:
| `inputVars` | Map of arbitrary input variables to inject to the object template | Object | - |
| `wait` | Wait for object to be ready | Boolean | true |
| `waitOptions` | Customize [how to wait](#wait-options) for object to be ready | Object | {} |
| `runOnce` | Create or delete this object only once during the entire job | Boolean | false |

!!! warning
Kube-burner is only able to wait for a subset of resources, unless `waitOptions` are specified.
Expand Down Expand Up @@ -287,3 +288,30 @@ spec:
## Template functions

In addition to the default [golang template semantics](https://golang.org/pkg/text/template/), kube-burner is compiled with the [sprig library](http://masterminds.github.io/sprig/), which adds over 70 template functions for Go’s template language.

## RunOnce

All objects within the job will iteratively run based on the JobIteration number,
but there may be a situation if an object need to be created only once (ex. clusterrole), in such cases
we can add an optional field as `runOnce` for that particular object to execute only once in the entire job.

An example scenario as below template, a job iteration of 100 but create the clusterrole only once.

```yaml
jobs:
- name: cluster-density
jobIterations: 100
namespacedIterations: true
namespace: cluster-density
objects:
- objectTemplate: clusterrole.yml
replicas: 1
runOnce: true
- objectTemplate: clusterrolebinding.yml
replicas: 1
runOnce: true
- objectTemplate: deployment.yml
replicas: 10
```
10 changes: 9 additions & 1 deletion pkg/burner/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,15 @@ func (ex *Executor) RunCreateJob(iterationStart, iterationEnd int, waitListNames
"kube-burner-runid": ex.runid,
}
ex.objects[objectIndex].labelSelector = labels
ex.replicaHandler(labels, obj, ns, i, &wg)
if obj.RunOnce {
if i == 0 {
// this executes only once during the first iteration of an object
log.Debugf("RunOnce set to %s, so creating object once", obj.ObjectTemplate)
ex.replicaHandler(labels, obj, ns, i, &wg)
}
} else {
ex.replicaHandler(labels, obj, ns, i, &wg)
}
}
if !ex.WaitWhenFinished && ex.PodWait {
if !ex.NamespacedIterations || !namespacesWaited[ns] {
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ type Object struct {
Wait bool `yaml:"wait" json:"wait"`
// WaitOptions define custom behaviors when waiting for objects creation
WaitOptions WaitOptions `yaml:"waitOptions" json:"waitOptions,omitempty"`
// Run Once to create the object only once incase of multiple iterative jobs
RunOnce bool `yaml:"runOnce" json:"runOnce,omitempty"`
}

// Job defines a kube-burner job
Expand Down

0 comments on commit 72f1d38

Please sign in to comment.