Templates
Templates allow you to store templates for other resources used in Testkube. We support a list of templates job | container | cronjob | scraper | pvc | webhook | pod. To define templates in Testkube, you'll need to provide a template body (in Golang template format) and a type of the template.
Testkube provides access to the Sprig functions library in templates.
Creating a Template
The template can be created using the API, CLI, or a Custom Resource.
- API
- CLI
- Custom Resource
If you prefer to use the API for creating a template, please visit the Core OSS API spec for templates in the doc below.
Templates can be created with the Testkube CLI using the create template command.
kubectl testkube create template --name job-template --template-type job --body job-template.yaml
--name - Your template name (in this case job-template).
--template-type - Your template type (in this case job for prebuilt executors).
--body - A path to the file with job template content
apiVersion: tests.testkube.io/v1
kind: Template
metadata:
  name: job-template
  namespace: testkube
spec:
  type: job
  body: <YOUR_TEMPLATE_BODY>
Where <YOUR_TEMPLATE_BODY> should be replaced with the Kubernetes job definition in Golang template format.
And then apply with:
kubectl apply -f template.yaml
Using Templates
You will need to refer to a template in the corresponding reference field of the resource.
- API
- CLI
- Custom Resource
Check templateReference fields in the Core OSS API spec. For example, Test -> executionRequest -> jobTemplateReference field. OpenAPI spec
Templates can be created with the Testkube CLI using the create template command.
kubectl testkube create test --name template-test --type k6/script --job-template-reference=job-template --test-content-type git --git-uri  "https://github.com/kubeshop/testkube.git" --git-branch main --git-path test/k6/k6-smoke-test.js
--name - Your test name (in this case template-test).
--type - Your test type (in this case k6/script).
--job-template-reference - Job template reference (in this case job-template).
--test-content-type - Test content type (in this case git).
--git-uri - Git URI to repository (in this case https://github.com/kubeshop/testkube.git).
--git-branch - Git branch to use (in this case main).
--git-path - Git path to the test (in this case test/k6/k6-smoke-test.js).
apiVersion: tests.testkube.io/v3
kind: Test
metadata:
  name: template-test
  namespace: testkube
spec:
  type: k6/script
  content:
    type: git
    repository:
      type: git
      uri: https://github.com/kubeshop/testkube.git
      branch: main
      path: test/k6/k6-smoke-test.js
      authType: basic
  executionRequest:
    jobTemplateReference: job-template