From 3520a1a760c3e44a8ed957f85490ffc7e36aa82f Mon Sep 17 00:00:00 2001 From: Vladislav Sukhin Date: Mon, 16 Dec 2024 16:29:45 +0300 Subject: [PATCH] fix: pass pvc names Signed-off-by: Vladislav Sukhin --- cmd/tcl/testworkflow-toolkit/commands/parallel.go | 1 + cmd/tcl/testworkflow-toolkit/commands/services.go | 1 + pkg/testworkflows/testworkflowconfig/config.go | 1 + pkg/testworkflows/testworkflowconfig/expressions.go | 10 ++++------ pkg/testworkflows/testworkflowprocessor/processor.go | 6 +++++- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/cmd/tcl/testworkflow-toolkit/commands/parallel.go b/cmd/tcl/testworkflow-toolkit/commands/parallel.go index 75d6f233df..3c3a192f2e 100644 --- a/cmd/tcl/testworkflow-toolkit/commands/parallel.go +++ b/cmd/tcl/testworkflow-toolkit/commands/parallel.go @@ -205,6 +205,7 @@ func NewParallelCmd() *cobra.Command { testworkflowconfig.CreateResourceMachine(&cfg.Resource), testworkflowconfig.CreateWorkerMachine(&cfg.Worker), baseMachine, + testworkflowconfig.CreatePvcMachine(cfg.Execution.Pvcs), params.MachineAt(index), ) diff --git a/cmd/tcl/testworkflow-toolkit/commands/services.go b/cmd/tcl/testworkflow-toolkit/commands/services.go index ce692cc849..c357c49363 100644 --- a/cmd/tcl/testworkflow-toolkit/commands/services.go +++ b/cmd/tcl/testworkflow-toolkit/commands/services.go @@ -261,6 +261,7 @@ func NewServicesCmd() *cobra.Command { testworkflowconfig.CreateResourceMachine(&cfg.Resource), testworkflowconfig.CreateWorkerMachine(&cfg.Worker), baseMachine, + testworkflowconfig.CreatePvcMachine(cfg.Execution.Pvcs), params.MachineAt(index), ) diff --git a/pkg/testworkflows/testworkflowconfig/config.go b/pkg/testworkflows/testworkflowconfig/config.go index 8f41f3c8cf..670b7538ae 100644 --- a/pkg/testworkflows/testworkflowconfig/config.go +++ b/pkg/testworkflows/testworkflowconfig/config.go @@ -22,6 +22,7 @@ type ExecutionConfig struct { OrganizationId string `json:"o,omitempty"` EnvironmentId string `json:"e,omitempty"` ParentIds string `json:"p,omitempty"` + PvcNames []string `json:"P,omitempty"` } type WorkflowConfig struct { diff --git a/pkg/testworkflows/testworkflowconfig/expressions.go b/pkg/testworkflows/testworkflowconfig/expressions.go index b951bddb63..b611b32a0d 100644 --- a/pkg/testworkflows/testworkflowconfig/expressions.go +++ b/pkg/testworkflows/testworkflowconfig/expressions.go @@ -3,8 +3,6 @@ package testworkflowconfig import ( "strings" - corev1 "k8s.io/api/core/v1" - "github.com/kubeshop/testkube/pkg/expressions" ) @@ -84,15 +82,15 @@ func CreateWorkerMachine(cfg *WorkerConfig) expressions.Machine { return expressions.CombinedMachines(machine) } -func CreatePvcMachine(pvcs []corev1.PersistentVolumeClaim) expressions.Machine { +func CreatePvcMachine(pvcNames []string) expressions.Machine { pvcMap := make(map[string]string) - for _, pvc := range pvcs { - name := pvc.Name + for _, pvcName := range pvcNames { + name := pvcName if index := strings.LastIndex(name, "-"); index != -1 { name = name[:index] } - pvcMap[name+".name"] = pvc.Name + pvcMap[name+".name"] = pvcName } return expressions.NewMachine().RegisterStringMap("pvcs", pvcMap) diff --git a/pkg/testworkflows/testworkflowprocessor/processor.go b/pkg/testworkflows/testworkflowprocessor/processor.go index 43e8b054a4..9b65608d5f 100644 --- a/pkg/testworkflows/testworkflowprocessor/processor.go +++ b/pkg/testworkflows/testworkflowprocessor/processor.go @@ -120,7 +120,9 @@ func (p *processor) Bundle(ctx context.Context, workflow *testworkflowsv1.TestWo createSecretMachine(mapEnv), testworkflowconfig.CreateWorkerMachine(&options.Config.Worker), testworkflowconfig.CreateResourceMachine(&options.Config.Resource), - testworkflowconfig.CreatePvcMachine(layer.Pvcs())) + testworkflowconfig.CreatePvcMachine( + common.MapSlice(layer.Pvcs(), func(p corev1.PersistentVolumeClaim) string { return p.Name })), + ) // Fetch resource root and resource ID if options.Config.Resource.Id == "" { @@ -174,6 +176,8 @@ func (p *processor) Bundle(ctx context.Context, workflow *testworkflowsv1.TestWo return nil, errors.Wrap(err, "finalizing Pvc") } } + pvcNames := common.MapSlice(pvcs, func(p corev1.PersistentVolumeClaim) string { return p.Name }) + options.Config.Execution.PvcNames = pvcNames // Finalize Secrets secrets := append(layer.Secrets(), options.Secrets...)