--- title: Run PipelineRuns one at a time with Kueue tags: [pac, startpaac, kueue] --- # Run PipelineRuns one at a time with Kueue Kueue puts Tekton PipelineRuns in a line. Create three at once and one runs while the other two wait their turn, in order. startpaac, a script that builds a small test cluster on your laptop, can now install it for you. ```mermaid flowchart LR Create@{ img: "/icons/pipeline.svg", label: "New PipelineRun", w: 48, h: 48, constraint: "on" } Gate@{ img: "/icons/policy.svg", label: "Marked pending", w: 48, h: 48, constraint: "on" } Q@{ img: "/icons/queue.svg", label: "Kueue line", w: 48, h: 48, constraint: "on" } Run@{ img: "/icons/play.svg", label: "Runs", w: 48, h: 48, constraint: "on" } Done@{ img: "/icons/success.svg", label: "Done", w: 48, h: 48, constraint: "on" } Create --> Gate --> Q Q go@-->|your turn| Run --> Done Done next@-->|slot free| Q %% play: Three runs, one slot %% Create -> Gate : 3 runs | Three PipelineRuns are created at once %% Gate -> Q : pending | Each one is marked pending and joins the line %% Q -> Run @go : run 1 | The first in line takes the only slot %% wait 1200 | The other two wait %% Run -> Done : run 1 %% Done -> Q @next : slot | The slot frees up %% Q -> Run @go : run 2 | The next one starts ``` ## Try it You need Docker running, plus `kind`, `kubectl`, `helm`, `jq`, `curl` and [`minica`](https://github.com/jsha/minica). [`gum`](https://github.com/charmbracelet/gum) is optional and makes the menu nicer. 1. Get startpaac: ```shell git clone https://github.com/pipelines-as-code/startpaac cd startpaac ``` 2. Create its config file. `PAC_DIR` is meant for a Pipelines-as-Code checkout, which you don't need here, but startpaac wants an existing folder there. ```shell mkdir -p ~/.config/startpaac cat > ~/.config/startpaac/config <<'EOF' TARGET_HOST=local PAC_DIR=$HOME EOF ``` 3. Run it and choose what to install: ```shell ./startpaac ``` A menu lists the optional components. Untick Pipelines-as-Code, tick Kueue, and confirm. Say yes when it offers to save your choice. The first run takes a few minutes. 4. Create three runs that each sleep for 20 seconds, and watch: ```shell export KUBECONFIG=~/.kube/config.local for i in 1 2 3; do kubectl create -n default -f - <<'EOF' apiVersion: tekton.dev/v1 kind: PipelineRun metadata: generateName: queue-demo- spec: pipelineSpec: tasks: - name: sleep taskSpec: steps: - name: sleep image: registry.access.redhat.com/ubi9/ubi-minimal script: sleep 20 EOF done kubectl get pipelineruns -n default -w ``` One run says `Running` and the other two say `PipelineRunPending`. When one finishes, the next starts. 5. Delete the cluster when you're done: ```shell ./startpaac --stop-kind ``` If you already have a startpaac cluster, `./startpaac --install-kueue` adds Kueue to it and leaves the rest alone. ## Good to know Only namespaces listed in `KUEUE_NAMESPACES` get a line. The default is `default`. To queue more, add them to your config file and run `./startpaac --install-kueue` again. A namespace you remove from the list runs its PipelineRuns right away again. ```shell KUEUE_NAMESPACES="default sample" ``` Kueue needs Tekton, so startpaac installs Tekton first. It also installs cert-manager and tekton-kueue, which connect the two. The versions are pinned: Kueue v0.16.6, tekton-kueue v0.4.3 and cert-manager v1.19.2.