Andreas Bradahl
Andreas Bradahl

Reputation: 55

Binding a Tekton Workspace directory to a VolumeMount

We have a Tekton pipeline from which we want to run our ReadyAPI test suites. We're using the official image from SmartBear (https://hub.docker.com/r/smartbear/ready-api-soapui-testrunner).

The image requires that you bind the /project folder in the container to the host directory where the ReadyAPI test project is located. In our case, our test project is located in the Tekton Workspace directory common-workspace/application-foo/tests/application-foo-readyapi-project.xml.

When running the container image locally (with docker run), I would just add an argument -v="common-workspace/application-foo/tests/":/project. I can't figure out how to do this mapping in a Tekton Task. Here is the entire Task definition:

apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: run-readyapi-tests
spec:
  workspaces:
    - name: source
  steps:
    - name: run-test-suite
      image: image-registry.openshift-image-registry.svc:5000/cicd/ready-api-soapui-testrunner:3.20.0
      volumeMounts:
        - name: readyapi-project
          mountPath: /project
      env:
        - name: LICENSE_SERVER
          value: "a.b.c.d:1234"
        - name: COMMAND_LINE
          value: "/project/application-foo-readyapi-project.xml"
  volumes:
    - name: readyapi-project
      [some binding mechanism here]

Looking at the official docs on volume binding with hostPath (https://kubernetes.io/docs/concepts/storage/volumes/#hostpath), I was hoping I could do something like this, but this doesn't work for some reason:

  volumes:
    - name: readyapi-project
      hostPath:
        path: common-workspace/application-foo/tests

So how can I bind volumeMounts to actual directories on the host? Any clues?

Update: When looking at the pods in OpenShift, this Task has a CreateContainerError status. In the Events view, this is the error message that is displayed: "Error: failed to mkdir common-workspace/application-foo/tests: mkdir common-workspace: operation not permitted"

I don't understand why it tries to create the common-workspace folder, since it already exists. I have verified that the entire path exists when using the emptyDir volume type, and then running ls /workspace/source/common-workspace/application-foo/tests. This prints out the test project's XML file.

Upvotes: 1

Views: 3235

Answers (1)

SYN
SYN

Reputation: 5041

Try this:

apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: run-readyapi-tests
spec:
  workspaces:
    - name: source
      mountPath: /project
  steps:
    - name: run-test-suite
      image: image-registry.openshift-image-registry.svc:5000/cicd/ready-api-soapui-testrunner:3.20.0
      env:
        - name: LICENSE_SERVER
          value: "a.b.c.d:1234"
        - name: COMMAND_LINE
          value: "/project/application-foo-readyapi-project.xml"

You can set arbitrary mountPaths for your Tasks workspaces. The default being to mount them into /workspace/${name}.

You don't need the volumeMounts from your initial post. You could use it, if you had some volumes defined some place, but since you're only using workspaces here: they would be automatically mounted in all steps container from your Task.

Upvotes: 0

Related Questions