Skip to content

Commit

Permalink
fix: convert pvc
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Sukhin <[email protected]>
  • Loading branch information
vsukhin committed Dec 13, 2024
1 parent 597a69a commit bd3aad2
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 5 deletions.
3 changes: 3 additions & 0 deletions api/v1/testkube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10618,6 +10618,9 @@ components:
storageClassName:
description: 'Storage class name specifies the name of a StorageClass. More info: https://kubernetes.io/docs/concepts/storage/storage-classes/'
type: string
volumeName:
description: 'Volume name is used to identify the volume'
type: string
selector:
description: Only the volumes whose labels match the selector can be bound to the claim
$ref: "#/components/schemas/LabelSelector"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ require (
github.com/keygen-sh/jsonapi-go v1.2.1
github.com/keygen-sh/keygen-go/v3 v3.2.0
github.com/kubepug/kubepug v1.7.1
github.com/kubeshop/testkube-operator v1.17.55-0.20241212153943-9d18068064f1
github.com/kubeshop/testkube-operator v1.17.55-0.20241213114930-df3327436207
github.com/minio/minio-go/v7 v7.0.66
github.com/montanaflynn/stats v0.7.1
github.com/moogar0880/problems v0.1.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ github.com/kubepug/kubepug v1.7.1 h1:LKhfSxS8Y5mXs50v+3Lpyec+cogErDLcV7CMUuiaisw
github.com/kubepug/kubepug v1.7.1/go.mod h1:lv+HxD0oTFL7ZWjj0u6HKhMbbTIId3eG7aWIW0gyF8g=
github.com/kubeshop/testkube-operator v1.17.55-0.20241212153943-9d18068064f1 h1:TmmGhFII/sIdEy6lMRHkRovG7Xr1pW4NkF9sPiPgtNc=
github.com/kubeshop/testkube-operator v1.17.55-0.20241212153943-9d18068064f1/go.mod h1:P47tw1nKQFufdsZndyq2HG2MSa0zK/lU0XpRfZtEmIk=
github.com/kubeshop/testkube-operator v1.17.55-0.20241213114930-df3327436207 h1:IQvoge5CpG0Z1uEjb/rcA4SN+ZiAmPrO0XSTLLlPDeg=
github.com/kubeshop/testkube-operator v1.17.55-0.20241213114930-df3327436207/go.mod h1:P47tw1nKQFufdsZndyq2HG2MSa0zK/lU0XpRfZtEmIk=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/lithammer/fuzzysearch v1.1.8 h1:/HIuJnjHuXS8bKaiTMeeDlW2/AyIWk2brx1V8LFgLN4=
Expand Down
6 changes: 4 additions & 2 deletions pkg/api/v1/testkube/model_test_workflow_pvc_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type TestWorkflowPvcConfig struct {
VolumeMode string `json:"volumeMode,omitempty"`
Resources *TestWorkflowResources `json:"resources,omitempty"`
// Storage class name specifies the name of a StorageClass. More info: https://kubernetes.io/docs/concepts/storage/storage-classes/
StorageClassName string `json:"storageClassName,omitempty"`
Selector *LabelSelector `json:"selector,omitempty"`
StorageClassName string `json:"storageClassName,omitempty"`
// Volume name is used to identify the volume
VolumeName string `json:"volumeName,omitempty"`
Selector *LabelSelector `json:"selector,omitempty"`
}
1 change: 1 addition & 0 deletions pkg/mapper/testworkflows/kube_openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,7 @@ func MapPvcConfigKubeToAPI(v testworkflowsv1.TestWorkflowPvcConfig) testkube.Tes
VolumeMode: v.VolumeMode,
Resources: common.MapPtr(v.Resources, MapResourcesKubeToAPI),
StorageClassName: v.StorageClassName,
VolumeName: v.VolumeName,
Selector: common.MapPtr(v.Selector, MapSelectorToAPI),
}
}
1 change: 1 addition & 0 deletions pkg/mapper/testworkflows/openapi_kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,7 @@ func MapPvcConfigAPIToKube(v testkube.TestWorkflowPvcConfig) testworkflowsv1.Tes
VolumeMode: v.VolumeMode,
Resources: common.MapPtr(v.Resources, MapResourcesAPIToKube),
StorageClassName: v.StorageClassName,
VolumeName: v.VolumeName,
Selector: common.MapPtr(v.Selector, MapLabelSelectorAPIToKube),
}
}
51 changes: 49 additions & 2 deletions pkg/testworkflows/testworkflowresolver/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"maps"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/util/intstr"

testworkflowsv1 "github.com/kubeshop/testkube-operator/api/testworkflows/v1"
"github.com/kubeshop/testkube/internal/common"
Expand Down Expand Up @@ -421,9 +423,54 @@ func ConvertTestWorkflowPvcConfigToPersistentVolumeClaimSpec(pvc testworkflowsv1
AccessModes: common.MapSlice(pvc.AccessModes, func(s string) corev1.PersistentVolumeAccessMode {
return corev1.PersistentVolumeAccessMode(s)
}),
Selector: pvc.Selector,
// Resources: pvc.Resources.Limits,
Selector: pvc.Selector,
Resources: ConvertResourcesToVolumeResourceRequirements(pvc.Resources),
VolumeName: pvc.VolumeName,
StorageClassName: &pvc.StorageClassName,
VolumeMode: (*corev1.PersistentVolumeMode)(&pvc.VolumeMode),
}
}

func ConvertResourcesToVolumeResourceRequirements(r *testworkflowsv1.Resources) corev1.VolumeResourceRequirements {
var limits, requests corev1.ResourceList
if r != nil {
if len(r.Limits) != 0 {
limits = make(corev1.ResourceList)
}

if len(r.Requests) != 0 {
requests = make(corev1.ResourceList)
}

for key, value := range r.Limits {
var quantity resource.Quantity
if value.Type == intstr.Int {
quantity = *resource.NewQuantity(int64(value.IntVal), resource.BinarySI)
}

if value.Type == intstr.String {
quantity, _ = resource.ParseQuantity(value.String())
}

limits[key] = quantity
}

for key, value := range r.Requests {
var quantity resource.Quantity
if value.Type == intstr.Int {
quantity = *resource.NewQuantity(int64(value.IntVal), resource.BinarySI)
}

if value.Type == intstr.String {
quantity, _ = resource.ParseQuantity(value.String())
}

requests[key] = quantity
}
}

return corev1.VolumeResourceRequirements{
Limits: limits,
Requests: requests,
}
}

0 comments on commit bd3aad2

Please sign in to comment.