Test Workflows - Content
Often you need to provide some input data for your tests - whether it's Tests source code, or some fixtures.
All the examples here that are using content are using it directly under the spec.
Please note, that you can also use it under a specific step - this way, such files won't be available
in different steps - see Schema Reference.
Remember, that the working directory won't be affected by any of these settings.
If you want to change default working directory, i.e. to the cloned repository,
you can use workingDir:
spec:
container:
workingDir: /data/repo
Shared Directories
/data
By default, the /data directory has an empty volume mounted that can be shared across the steps.
Please note, that this directory is shared across steps of a single execution. To share data across multiple executions, see Shared Directory Between Executions.
Custom Volumes
You may create different directories that will share data across steps using Kubernetes. To do so, create and mount Empty Dir volume. This may be useful for sharing a dependencies across steps, for example.
spec:
pod:
volumes:
- name: golang-deps
emptyDir: {}
container:
env:
- name: GOCACHE
value: /go-cache
volumeMounts:
- name: golang-deps
mountPath: /go-cache
Shared Directory Between Executions
We are planning to prepare a built-in caching mechanism that will allow you to share data more easily.
If you want to cache some data between executions, i.e., to speed up execution, you may consider mounting Host's file system with hostPath.
spec:
pod:
volumes:
- name: golang-deps
hostPath:
path: "/tmp/go-cache-{{ workflow.name }}"
container:
env:
- name: GOCACHE
value: /go-cache
volumeMounts:
- name: golang-deps
mountPath: /go-cache
This way, you will have a cache for each execution of the Test Workflow on the same node.
If you want to cache data across multiple nodes, you may consider:
- using an Object Storage API like Minio, AWS S3 or GCP Cloud Storage, and save/read files using it, or
- creating a Persistent Volume and attaching it with
pod.volumesandcontainer.volumeMounts.
Static Files
To mount a static file, you can use content.files.
spec:
content:
files:
- path: /etc/nginx/nginx.conf
content: |
events {
worker_connections 1024;
}
http {
server {
listen 8888;
location / {
root /www;
}
}
}
- path: /www/index.html
content: "hello-there"
Mounting From a Secret or ConfigMap
If you need to mount the secret as a file, you can use contentFrom clause in content.files. It has the same interface as valueFrom in native EnvVar.
spec:
content:
files:
- path: /some/path/secret.key
contentFrom:
secretKeyRef: # Mount from Secret
name: secret-name
key: key-name-in-secret
- path: /some/path/nginx.conf
contentFrom:
configMapKeyRef: # Mount from ConfigMap
name: secret-name
key: key-name-in-secret
Mounting Secret or ConfigMap as a Directory
As an alternative, you may use native Kubernetes volumes for mounting Secrets or ConfigMaps.
spec:
pod:
volumes:
# Create volume from the Secret
- name: example-secret-volume
secret:
secretName: secret-name
# Create volume from the ConfigMap
- name: example-configmap-volume
configMap:
name: configmap-name
container:
volumeMounts:
# Mount files from the Secret
- name: example-secret-volume
mountPath: /some/secret
# Mount files from the ConfigMap
- name: example-configmap-volume
mountPath: /some/config
Working Directory Resolution
A few useful hints about the workingDir resolution:
- without
workingDir(or with empty) in step - it will use the parent's working dir (down the workflow specification tree) - without
workingDir(or with empty) at all in the workflow specification tree - it will use working dir from the image default - with relative
workingDirin step - it will go further from parent's working dir (down the workflow specification tree) - with relative
workingDirin step, but no other in a workflow specification tree - it will go further from the image default - the parent is whatever is found in the workflow specification tree, for example, the Global Template's
spec.container.workingDirgoes down to Test Workflowsspec.container.workingDir(unless overridden).
Git Repository
Testkube allows you to easily fetch the Git repository using content.git.
Remember, that the working directory won't be affected by any of these settings.
If you want to change default working directory, i.e. to the cloned repository,
you can use workingDir:
spec:
container:
workingDir: /data/repo