diff --git a/api/v1/testkube.yaml b/api/v1/testkube.yaml index 065638042c..76f45fb906 100644 --- a/api/v1/testkube.yaml +++ b/api/v1/testkube.yaml @@ -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 diff --git a/go.mod b/go.mod index d83e255cfb..5b564cbcdc 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 35bbe8851a..7de5a55a89 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/pkg/api/v1/testkube/model_test_workflow_pvc_config.go b/pkg/api/v1/testkube/model_test_workflow_pvc_config.go index 02b3f00cdb..a7a03cd126 100644 --- a/pkg/api/v1/testkube/model_test_workflow_pvc_config.go +++ b/pkg/api/v1/testkube/model_test_workflow_pvc_config.go @@ -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"` } diff --git a/pkg/api/v1/testkube/model_typed_local_object_reference.go b/pkg/api/v1/testkube/model_typed_local_object_reference.go new file mode 100644 index 0000000000..4701fd64b4 --- /dev/null +++ b/pkg/api/v1/testkube/model_typed_local_object_reference.go @@ -0,0 +1,19 @@ +/* + * Testkube API + * + * Testkube provides a Kubernetes-native framework for test definition, execution and results + * + * API version: 1.0.0 + * Contact: testkube@kubeshop.io + * 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"` +} diff --git a/pkg/api/v1/testkube/model_typed_object_reference.go b/pkg/api/v1/testkube/model_typed_object_reference.go new file mode 100644 index 0000000000..18617f8d0b --- /dev/null +++ b/pkg/api/v1/testkube/model_typed_object_reference.go @@ -0,0 +1,20 @@ +/* + * Testkube API + * + * Testkube provides a Kubernetes-native framework for test definition, execution and results + * + * API version: 1.0.0 + * Contact: testkube@kubeshop.io + * 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"` +} diff --git a/pkg/mapper/testworkflows/kube_openapi.go b/pkg/mapper/testworkflows/kube_openapi.go index 333a2c4d12..81dc81d1e5 100644 --- a/pkg/mapper/testworkflows/kube_openapi.go +++ b/pkg/mapper/testworkflows/kube_openapi.go @@ -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), diff --git a/pkg/mapper/testworkflows/openapi_kube.go b/pkg/mapper/testworkflows/openapi_kube.go index fa5a76abc0..9841a1b5d5 100644 --- a/pkg/mapper/testworkflows/openapi_kube.go +++ b/pkg/mapper/testworkflows/openapi_kube.go @@ -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), diff --git a/pkg/testworkflows/testworkflowprocessor/processor.go b/pkg/testworkflows/testworkflowprocessor/processor.go index 870eed6df6..3f3b6e948d 100644 --- a/pkg/testworkflows/testworkflowprocessor/processor.go +++ b/pkg/testworkflows/testworkflowprocessor/processor.go @@ -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 @@ -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)). diff --git a/pkg/testworkflows/testworkflowresolver/merge.go b/pkg/testworkflows/testworkflowresolver/merge.go index 3ebf623ab0..cdf602ca43 100644 --- a/pkg/testworkflows/testworkflowresolver/merge.go +++ b/pkg/testworkflows/testworkflowresolver/merge.go @@ -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" @@ -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, - } -}