From 029d13be3b59040bb58335e19f2c1036eb512aea Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Mon, 4 May 2026 22:53:37 -0400 Subject: [PATCH] provider/tekton: add workspace config to tangled config This allows you to create a workspace PVC for cloning a git repo so you can run go test in it. Signed-off-by: Xe Iaso --- provider_tekton.go | 55 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/provider_tekton.go b/provider_tekton.go index 1476e10..889b83d 100644 --- a/provider_tekton.go +++ b/provider_tekton.go @@ -57,9 +57,17 @@ var ( // runner and pass a small amount of routing data, not mirror Tekton's // entire PipelineRun API. type tektonWorkflowConfig struct { - Pipeline string `yaml:"pipeline"` - ServiceAccount string `yaml:"service_account"` - Params map[string]string `yaml:"params"` + Pipeline string `yaml:"pipeline"` + ServiceAccount string `yaml:"service_account"` + Params map[string]string `yaml:"params"` + Workspaces []tektonWorkspaceConfig `yaml:"workspaces"` +} + +type tektonWorkspaceConfig struct { + Name string `yaml:"name"` + AccessModes []string `yaml:"access_modes"` + Storage *string `yaml:"storage"` + PVC *string `yaml:"pvc"` } type tektonWorkflowDoc struct { @@ -261,7 +269,48 @@ func buildTektonPipelineRun( }, }, } + spec := obj["spec"].(map[string]any) + + if len(cfg.Workspaces) != 0 { + spec["podTemplate"] = map[string]any{ + "securityContext": map[string]any{ + "fsGroup": 65532, + }, + } + + workspaces := []any{} + + for _, ws := range cfg.Workspaces { + switch { + case ws.Storage != nil: + workspaces = append(workspaces, map[string]any{ + "name": ws.Name, + "volumeClaimTemplate": map[string]any{ + "spec": map[string]any{ + "accessModes": ws.AccessModes, + "resources": map[string]any{ + "requests": map[string]any{ + "storage": *ws.Storage, + }, + }, + }, + }, + }) + + case ws.PVC != nil: + workspaces = append(workspaces, map[string]any{ + "name": ws.Name, + "persistentVolumeClaim": map[string]any{ + "claimName": *ws.PVC, + }, + }) + } + } + + spec["workspaces"] = workspaces + } + if cfg.ServiceAccount != "" { spec["serviceAccountName"] = cfg.ServiceAccount } -- 2.51.2