Skip to content

Commit

Permalink
fix: append pvcs
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Sukhin <[email protected]>
  • Loading branch information
vsukhin committed Dec 12, 2024
1 parent 551f1b2 commit 6faffdb
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 20 deletions.
13 changes: 8 additions & 5 deletions pkg/testworkflows/testworkflowprocessor/intermediate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

testworkflowsv1 "github.com/kubeshop/testkube-operator/api/testworkflows/v1"
"github.com/kubeshop/testkube/pkg/testworkflows/testworkflowprocessor/stage"
Expand All @@ -25,11 +26,11 @@ type Intermediate interface {

AppendJobConfig(cfg *testworkflowsv1.JobConfig) Intermediate
AppendPodConfig(cfg *testworkflowsv1.PodConfig) Intermediate
AppendPvc(cfg map[string]corev1.PersistentVolumeClaimSpec) Intermediate

AddConfigMap(configMap corev1.ConfigMap) Intermediate
AddSecret(secret corev1.Secret) Intermediate
AddVolume(volume corev1.Volume) Intermediate
AddPvc(pvc corev1.PersistentVolumeClaim) Intermediate

AddEmptyDirVolume(source *corev1.EmptyDirVolumeSource, mountPath string) corev1.VolumeMount

Expand Down Expand Up @@ -104,13 +105,15 @@ func (s *intermediate) AppendPodConfig(cfg *testworkflowsv1.PodConfig) Intermedi
return s
}

func (s *intermediate) AddVolume(volume corev1.Volume) Intermediate {
s.Pod.Volumes = append(s.Pod.Volumes, volume)
func (s *intermediate) AppendPvc(cfg map[string]corev1.PersistentVolumeClaimSpec) Intermediate {
for name, spec := range cfg {
s.Ps = append(s.Ps, corev1.PersistentVolumeClaim{ObjectMeta: metav1.ObjectMeta{Name: name}, Spec: spec})
}
return s
}

func (s *intermediate) AddPvc(pvc corev1.PersistentVolumeClaim) Intermediate {
s.Ps = append(s.Ps, pvc)
func (s *intermediate) AddVolume(volume corev1.Volume) Intermediate {
s.Pod.Volumes = append(s.Pod.Volumes, volume)
return s
}

Expand Down
28 changes: 14 additions & 14 deletions pkg/testworkflows/testworkflowprocessor/mock_intermediate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pkg/testworkflows/testworkflowprocessor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/kubeshop/testkube/pkg/testworkflows/testworkflowprocessor/action/actiontypes/lite"
"github.com/kubeshop/testkube/pkg/testworkflows/testworkflowprocessor/constants"
"github.com/kubeshop/testkube/pkg/testworkflows/testworkflowprocessor/stage"
"github.com/kubeshop/testkube/pkg/testworkflows/testworkflowresolver"
)

//go:generate mockgen -destination=./mock_processor.go -package=testworkflowprocessor "github.com/kubeshop/testkube/pkg/testworkflows/testworkflowprocessor" Processor
Expand Down Expand Up @@ -106,7 +107,8 @@ func (p *processor) Bundle(ctx context.Context, workflow *testworkflowsv1.TestWo
// Initialize intermediate layer
layer := NewIntermediate().
AppendPodConfig(workflow.Spec.Pod).
AppendJobConfig(workflow.Spec.Job)
AppendJobConfig(workflow.Spec.Job).
AppendPvc(common.MapMap(workflow.Spec.Pvcs, testworkflowresolver.ConvertTestWorkflowPvcConfigToPersistentVolumeClaimSpec))
layer.ContainerDefaults().
ApplyCR(constants.DefaultContainerConfig.DeepCopy()).
AppendVolumeMounts(layer.AddEmptyDirVolume(nil, constants.DefaultInternalPath)).
Expand Down
1 change: 1 addition & 0 deletions pkg/testworkflows/testworkflowresolver/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func InjectServiceTemplate(svc *testworkflowsv1.ServiceSpec, template testworkfl
svc.Pod = MergePodConfig(template.Spec.Pod, svc.Pod)
svc.Content = MergeContent(template.Spec.Content, svc.Content)
svc.ContainerConfig = *MergeContainerConfig(template.Spec.Container, &svc.ContainerConfig)
svc.Pvcs = MergeMap(template.Spec.Pvcs, svc.Pvcs)
return nil
}

Expand Down
13 changes: 13 additions & 0 deletions pkg/testworkflows/testworkflowresolver/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ func ConvertIndependentStepParallelToStepParallel(step testworkflowsv1.Independe
Setup: common.MapSlice(step.TestWorkflowTemplateSpec.Setup, ConvertIndependentStepToStep),
Steps: common.MapSlice(step.TestWorkflowTemplateSpec.Steps, ConvertIndependentStepToStep),
After: common.MapSlice(step.TestWorkflowTemplateSpec.After, ConvertIndependentStepToStep),
Pvcs: step.TestWorkflowTemplateSpec.Pvcs,
},
StepControl: step.StepControl,
StepOperations: step.StepOperations,
Expand Down Expand Up @@ -414,3 +415,15 @@ func MergeTags(dst, src map[string]string) map[string]string {

return dst
}

func ConvertTestWorkflowPvcConfigToPersistentVolumeClaimSpec(pvc testworkflowsv1.TestWorkflowPvcConfig) corev1.PersistentVolumeClaimSpec {
return corev1.PersistentVolumeClaimSpec{
AccessModes: common.MapSlice(pvc.AccessModes, func(s string) corev1.PersistentVolumeAccessMode {
return corev1.PersistentVolumeAccessMode(s)
}),
Selector: pvc.Selector,
// Resources: pvc.Resources.Limits,
StorageClassName: &pvc.StorageClassName,
VolumeMode: (*corev1.PersistentVolumeMode)(&pvc.VolumeMode),
}
}

0 comments on commit 6faffdb

Please sign in to comment.