Skip to content

Commit

Permalink
Random integer generation in templates
Browse files Browse the repository at this point in the history
Signed-off-by: Raul Sevilla <[email protected]>
  • Loading branch information
rsevilla87 committed Jun 21, 2021
1 parent a5475e3 commit e0ed8a6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
12 changes: 11 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ In addition, you can also inject arbitrary variables with the option **inputVars

The following code snippet shows an example of a k8s service using these variables:


```yaml
apiVersion: v1
kind: Service
Expand Down Expand Up @@ -205,6 +204,17 @@ metadata:
name: configmap-{{.Replica}}
```

- randInteger: Generates a positive random integer between two numbers.

```yaml
apiVersion: v1
data:
number: {{randInteger 0 100}}
kind: ConfigMap
metadata:
name: configmap-{{.Replica}}
```

- rand: This function can be used to generate a random string with the given length. i.e

```yaml
Expand Down
2 changes: 0 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/cloud-bulldozer/kube-burner)](https://goreportcard.com/report/github.com/cloud-bulldozer/kube-burner)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)


# What's this?

Kube-burner is a tool aimed at stressing kubernetes clusters. The main functionallity it provides can be summarized in these three steps:
Expand All @@ -15,7 +14,6 @@ Kube-burner is a tool aimed at stressing kubernetes clusters. The main functiona

[![asciicast](https://asciinema.org/a/KksoK5voK3al1FuOza89t1JAp.svg)](https://asciinema.org/a/KksoK5voK3al1FuOza89t1JAp)


# Downloading Kube-burner

In case you want to start tinkering with Kube-burner now:
Expand Down
3 changes: 3 additions & 0 deletions pkg/util/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ func RenderTemplate(original []byte, inputData interface{}, options templateOpti
}
return sequence
},
"randInteger": func(a, b interface{}) int {
return rand.Intn(cast.ToInt(b)) + cast.ToInt(a)
},
}
t, err := template.New("").Option(string(options)).Funcs(funcMap).Parse(string(original))
if err != nil {
Expand Down

0 comments on commit e0ed8a6

Please sign in to comment.