Skip to content

Commit

Permalink
fix: use proper pvc name
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Sukhin <[email protected]>
  • Loading branch information
vsukhin committed Dec 18, 2024
1 parent a6f70f4 commit bc49ed2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pkg/testworkflows/testworkflowconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type ExecutionConfig struct {
OrganizationId string `json:"o,omitempty"`
EnvironmentId string `json:"e,omitempty"`
ParentIds string `json:"p,omitempty"`
PvcNames []string `json:"c,omitempty"`
PvcNames map[string]string `json:"c,omitempty"`
}

type WorkflowConfig struct {
Expand Down
11 changes: 2 additions & 9 deletions pkg/testworkflows/testworkflowconfig/expressions.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package testworkflowconfig

import (
"strings"

"github.com/kubeshop/testkube/pkg/expressions"
)

Expand Down Expand Up @@ -82,14 +80,9 @@ func CreateWorkerMachine(cfg *WorkerConfig) expressions.Machine {
return expressions.CombinedMachines(machine)
}

func CreatePvcMachine(pvcNames []string) expressions.Machine {
func CreatePvcMachine(pvcNames map[string]string) expressions.Machine {
pvcMap := make(map[string]string)
for _, pvcName := range pvcNames {
name := pvcName
if index := strings.LastIndex(name, "-"); index != -1 {
name = name[:index]
}

for name, pvcName := range pvcNames {
pvcMap[name+".name"] = pvcName
}

Expand Down
19 changes: 16 additions & 3 deletions pkg/testworkflows/testworkflowprocessor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"maps"
"path/filepath"
"strings"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -115,12 +116,18 @@ func (p *processor) Bundle(ctx context.Context, workflow *testworkflowsv1.TestWo
AppendVolumeMounts(layer.AddEmptyDirVolume(nil, constants.DefaultDataPath))

mapEnv := make(map[string]corev1.EnvVarSource)
mapPvc := make(map[string]string)
for _, pvc := range layer.Pvcs() {
if index := strings.LastIndex(pvc.Name, "-"); index != -1 {
mapPvc[pvc.Name[:index]] = pvc.Name[index+1:]
}
}

machines = append(machines,
createSecretMachine(mapEnv),
testworkflowconfig.CreateWorkerMachine(&options.Config.Worker),
testworkflowconfig.CreateResourceMachine(&options.Config.Resource),
testworkflowconfig.CreatePvcMachine(
common.MapSlice(layer.Pvcs(), func(p corev1.PersistentVolumeClaim) string { return p.Name })),
testworkflowconfig.CreatePvcMachine(mapPvc),
)

// Fetch resource root and resource ID
Expand Down Expand Up @@ -168,14 +175,20 @@ func (p *processor) Bundle(ctx context.Context, workflow *testworkflowsv1.TestWo

// Finalize Pvcs
pvcs := layer.Pvcs()
mapPvc = make(map[string]string)
for i := range pvcs {
AnnotateControlledBy(&pvcs[i], options.Config.Resource.RootId, options.Config.Resource.Id)
err = expressions.FinalizeForce(&pvcs[i], machines...)
if err != nil {
return nil, errors.Wrap(err, "finalizing Pvc")
}

if index := strings.LastIndex(pvcs[i].Name, "-"); index != -1 {
mapPvc[pvcs[i].Name[:index]] = pvcs[i].Name[index+1:]
pvcs[i].Name = pvcs[i].Name[index+1:]
}
}
options.Config.Execution.PvcNames = common.MapSlice(pvcs, func(p corev1.PersistentVolumeClaim) string { return p.Name })
options.Config.Execution.PvcNames = mapPvc

// Finalize Secrets
secrets := append(layer.Secrets(), options.Secrets...)
Expand Down

0 comments on commit bc49ed2

Please sign in to comment.