Skip to content

Commit

Permalink
fix: add new pvc config fields
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Sukhin <[email protected]>
  • Loading branch information
vsukhin committed Dec 16, 2024
1 parent f89592e commit c47ff99
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 75 deletions.
35 changes: 35 additions & 0 deletions api/v1/testkube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10624,6 +10624,41 @@ components:
selector:
description: Only the volumes whose labels match the selector can be bound to the claim
$ref: "#/components/schemas/LabelSelector"
dataSource:
description: 'Data source field can be used to specify either:
* An existing VolumeSnapshot object (snapshot.storage.k8s.io/VolumeSnapshot)
* An existing PVC (PersistentVolumeClaim)'
$ref: "#/components/schemas/TypedLocalObjectReference"
dataSourceRef:
description: 'Data source reference specifies the object from which to populate the volume with data, if a non-empty volume is desired'
$ref: "#/components/schemas/TypedObjectReference"
volumeAttributesClassName:
description: 'Volume attributes class name may be used to set the VolumeAttributesClass used by this claim. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#volumeattributesclass'
$ref: "#/components/schemas/BoxedString"

TypedLocalObjectReference:
description: TypedLocalObjectReference contains enough information to let you locate the typed referenced object inside the same namespace
type: object
properties:
apiGroup:
description: api group is the group for the resource being referenced
$ref: "#/components/schemas/BoxedString"
kind:
description: kind is the type of resource being referenced
type: string
name:
description: name is the name of resource being referenced
type: string

TypedObjectReference:
description: TypedObjectReference contains enough information to let you locate the typed referenced object inside the specified namespace
type: object
allOf:
- $ref: "#/components/schemas/TypedLocalObjectReference"
properties:
namespace:
description: Namespace is the namespace of resource being referenced
$ref: "#/components/schemas/BoxedString"

#
# Errors
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.20241213144851-e0d37fb5899a
github.com/kubeshop/testkube-operator v1.17.55-0.20241216161809-fd2aba982921
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
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
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.20241213144851-e0d37fb5899a h1:nQDxKFu67lz9BH8isLnP7ttp7cgBWYnRDMV9VxMaYH0=
github.com/kubeshop/testkube-operator v1.17.55-0.20241213144851-e0d37fb5899a/go.mod h1:P47tw1nKQFufdsZndyq2HG2MSa0zK/lU0XpRfZtEmIk=
github.com/kubeshop/testkube-operator v1.17.55-0.20241216161809-fd2aba982921 h1:vvTobFjWYu0N9wyPA89sliFQz2KYf0jhVAsTobUqZfo=
github.com/kubeshop/testkube-operator v1.17.55-0.20241216161809-fd2aba982921/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
7 changes: 5 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,9 @@ type TestWorkflowPvcConfig struct {
Resources *TestWorkflowResources `json:"resources,omitempty"`
StorageClassName *BoxedString `json:"storageClassName,omitempty"`
// Volume name is used to identify the volume
VolumeName string `json:"volumeName,omitempty"`
Selector *LabelSelector `json:"selector,omitempty"`
VolumeName string `json:"volumeName,omitempty"`
Selector *LabelSelector `json:"selector,omitempty"`
DataSource *TypedLocalObjectReference `json:"dataSource,omitempty"`
DataSourceRef *TypedObjectReference `json:"dataSourceRef,omitempty"`
VolumeAttributesClassName *BoxedString `json:"volumeAttributesClassName,omitempty"`
}
19 changes: 19 additions & 0 deletions pkg/api/v1/testkube/model_typed_local_object_reference.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Testkube API
*
* Testkube provides a Kubernetes-native framework for test definition, execution and results
*
* API version: 1.0.0
* Contact: [email protected]
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package testkube

// TypedLocalObjectReference contains enough information to let you locate the typed referenced object inside the same namespace
type TypedLocalObjectReference struct {
ApiGroup *BoxedString `json:"apiGroup,omitempty"`
// kind is the type of resource being referenced
Kind string `json:"kind,omitempty"`
// name is the name of resource being referenced
Name string `json:"name,omitempty"`
}
20 changes: 20 additions & 0 deletions pkg/api/v1/testkube/model_typed_object_reference.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Testkube API
*
* Testkube provides a Kubernetes-native framework for test definition, execution and results
*
* API version: 1.0.0
* Contact: [email protected]
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package testkube

// TypedObjectReference contains enough information to let you locate the typed referenced object inside the specified namespace
type TypedObjectReference struct {
ApiGroup *BoxedString `json:"apiGroup,omitempty"`
// kind is the type of resource being referenced
Kind string `json:"kind,omitempty"`
// name is the name of resource being referenced
Name string `json:"name,omitempty"`
Namespace *BoxedString `json:"namespace,omitempty"`
}
8 changes: 4 additions & 4 deletions pkg/mapper/testworkflows/kube_openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -1213,11 +1213,11 @@ func MapTestWorkflowTagSchemaKubeToAPI(v testworkflowsv1.TestWorkflowTagSchema)
}
}

func MapPvcConfigKubeToAPI(v testworkflowsv1.TestWorkflowPvcConfig) testkube.TestWorkflowPvcConfig {
func MapPvcConfigKubeToAPI(v corev1.PersistentVolumeClaimSpec) testkube.TestWorkflowPvcConfig {
return testkube.TestWorkflowPvcConfig{
AccessModes: v.AccessModes,
VolumeMode: MapStringToBoxedString(v.VolumeMode),
Resources: common.MapPtr(v.Resources, MapResourcesKubeToAPI),
// AccessModes: v.AccessModes,
// VolumeMode: MapStringToBoxedString(v.VolumeMode),
// Resources: common.MapPtr(v.Resources, MapResourcesKubeToAPI),
StorageClassName: MapStringToBoxedString(v.StorageClassName),
VolumeName: v.VolumeName,
Selector: common.MapPtr(v.Selector, MapSelectorToAPI),
Expand Down
10 changes: 5 additions & 5 deletions pkg/mapper/testworkflows/openapi_kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -1492,11 +1492,11 @@ func MapTestWorkflowTagSchemaAPIToKube(v testkube.TestWorkflowTagSchema) testwor
}
}

func MapPvcConfigAPIToKube(v testkube.TestWorkflowPvcConfig) testworkflowsv1.TestWorkflowPvcConfig {
return testworkflowsv1.TestWorkflowPvcConfig{
AccessModes: v.AccessModes,
VolumeMode: MapBoxedStringToString(v.VolumeMode),
Resources: common.MapPtr(v.Resources, MapResourcesAPIToKube),
func MapPvcConfigAPIToKube(v testkube.TestWorkflowPvcConfig) corev1.PersistentVolumeClaimSpec {
return corev1.PersistentVolumeClaimSpec{
// AccessModes: v.AccessModes,
// VolumeMode: MapBoxedStringToString(v.VolumeMode),
// Resources: common.MapPtr(v.Resources, MapResourcesAPIToKube),
StorageClassName: MapBoxedStringToString(v.StorageClassName),
VolumeName: v.VolumeName,
Selector: common.MapPtr(v.Selector, MapLabelSelectorAPIToKube),
Expand Down
3 changes: 1 addition & 2 deletions pkg/testworkflows/testworkflowprocessor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ 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 @@ -108,7 +107,7 @@ func (p *processor) Bundle(ctx context.Context, workflow *testworkflowsv1.TestWo
layer := NewIntermediate().
AppendPodConfig(workflow.Spec.Pod).
AppendJobConfig(workflow.Spec.Job).
AppendPvc(common.MapMap(workflow.Spec.Pvcs, testworkflowresolver.ConvertTestWorkflowPvcConfigToPersistentVolumeClaimSpec))
AppendPvc(workflow.Spec.Pvcs)
layer.ContainerDefaults().
ApplyCR(constants.DefaultContainerConfig.DeepCopy()).
AppendVolumeMounts(layer.AddEmptyDirVolume(nil, constants.DefaultInternalPath)).
Expand Down
59 changes: 0 additions & 59 deletions pkg/testworkflows/testworkflowresolver/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ 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 @@ -417,60 +415,3 @@ 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: 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 c47ff99

Please sign in to comment.