Skip to content

Commit

Permalink
feat: [TKC-2895] pvc config (#6074)
Browse files Browse the repository at this point in the history
* feat: pvc config

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: rename var

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: dep update

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: map pvc to api

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: map to kube

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: add pvc to control plane

Signed-off-by: Vladislav Sukhin <[email protected]>

* cleanup pvcs

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: merge pvcs map

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: add pvcs to service spec

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: remove duplication

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: dep update

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: setvice pvcs

Signed-off-by: Vladislav Sukhin <[email protected]>

* fi: dep update

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: append pvcs

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: copy service pvcs

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: pvc name for execution

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: register pvc names

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: convert pvc

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: move fields to boxed strings

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix:  dep update

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: pass pvc names

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: renname cobfig field

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: remove var

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: add new pvc config fields

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: pvc mapping

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: json tag

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: use proper pvc name

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: merge maps

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: api spec format

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: typo

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: format methods

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: use map instead of slice

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: rename method

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: unique ref

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: use root id

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: dep update

Signed-off-by: Vladislav Sukhin <[email protected]>

---------

Signed-off-by: Vladislav Sukhin <[email protected]>
  • Loading branch information
vsukhin authored Dec 19, 2024
1 parent b0b3f6e commit a0e4eef
Show file tree
Hide file tree
Showing 25 changed files with 415 additions and 11 deletions.
73 changes: 73 additions & 0 deletions api/v1/testkube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8680,6 +8680,10 @@ components:
type: string
readinessProbe:
$ref: "#/components/schemas/Probe"
pvcs:
type: object
additionalProperties:
$ref: "#/components/schemas/TestWorkflowPvcConfig"

TestWorkflowServiceSpec:
type: object
Expand Down Expand Up @@ -8799,6 +8803,10 @@ components:
$ref: "#/components/schemas/TestWorkflowEvent"
execution:
$ref: "#/components/schemas/TestWorkflowTagSchema"
pvcs:
type: object
additionalProperties:
$ref: "#/components/schemas/TestWorkflowPvcConfig"

TestWorkflowTemplateSpec:
type: object
Expand Down Expand Up @@ -8837,6 +8845,10 @@ components:
$ref: "#/components/schemas/TestWorkflowEvent"
execution:
$ref: "#/components/schemas/TestWorkflowTagSchema"
pvcs:
type: object
additionalProperties:
$ref: "#/components/schemas/TestWorkflowPvcConfig"

TestWorkflowStepControl:
type: object
Expand Down Expand Up @@ -10611,6 +10623,67 @@ components:
must be defined
type: boolean

TestWorkflowPvcConfig:
type: object
properties:
accessModes:
description: 'Access mode for claim storage. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes'
type: array
items:
type: string
volumeMode:
description: 'Volume mode indicates the consumption of the volume as either a filesystem or block device.
More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes/#volume-mode'
$ref: "#/components/schemas/BoxedString"
resources:
description: 'Resources required for pvc'
$ref: "#/components/schemas/TestWorkflowResources"
storageClassName:
description: 'Storage class name specifies the name of a StorageClass. More info: https://kubernetes.io/docs/concepts/storage/storage-classes/'
$ref: "#/components/schemas/BoxedString"
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"
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
1 change: 1 addition & 0 deletions cmd/tcl/testworkflow-toolkit/commands/parallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ func NewParallelCmd() *cobra.Command {
testworkflowconfig.CreateResourceMachine(&cfg.Resource),
testworkflowconfig.CreateWorkerMachine(&cfg.Worker),
baseMachine,
testworkflowconfig.CreatePvcMachine(cfg.Execution.PvcNames),
params.MachineAt(index),
)

Expand Down
2 changes: 2 additions & 0 deletions cmd/tcl/testworkflow-toolkit/commands/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func NewServicesCmd() *cobra.Command {
Steps: []testworkflowsv1.Step{
{StepOperations: testworkflowsv1.StepOperations{Run: common.Ptr(svcSpec.StepRun)}},
},
Pvcs: svcSpec.Pvcs,
}
spec.Steps[0].Run.ContainerConfig = testworkflowsv1.ContainerConfig{}

Expand Down Expand Up @@ -260,6 +261,7 @@ func NewServicesCmd() *cobra.Command {
testworkflowconfig.CreateResourceMachine(&cfg.Resource),
testworkflowconfig.CreateWorkerMachine(&cfg.Worker),
baseMachine,
testworkflowconfig.CreatePvcMachine(cfg.Execution.PvcNames),
params.MachineAt(index),
)

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.20241118133003-70462ac10f4a
github.com/kubeshop/testkube-operator v1.17.55-0.20241219071935-0330347ee160
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.20241118133003-70462ac10f4a h1:xget2cwwqOL+K2Op9FPbMgfzj9lSVJAzZ9p48yxuFrE=
github.com/kubeshop/testkube-operator v1.17.55-0.20241118133003-70462ac10f4a/go.mod h1:P47tw1nKQFufdsZndyq2HG2MSa0zK/lU0XpRfZtEmIk=
github.com/kubeshop/testkube-operator v1.17.55-0.20241219071935-0330347ee160 h1:Bocn/Cgx/XLEsqvU3IdK5U/cFDJDFD3tES/1KS2wLkY=
github.com/kubeshop/testkube-operator v1.17.55-0.20241219071935-0330347ee160/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
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ type TestWorkflowIndependentServiceSpec struct {
// matrix of parameters to spawn instances
Matrix map[string]interface{} `json:"matrix,omitempty"`
// parameters that should be distributed across sharded instances
Shards map[string]interface{} `json:"shards,omitempty"`
Shards map[string]interface{} `json:"shards,omitempty"`
Pvcs map[string]TestWorkflowPvcConfig `json:"pvcs,omitempty"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ type TestWorkflowIndependentStepParallel struct {
After []TestWorkflowIndependentStep `json:"after,omitempty"`
Events []TestWorkflowEvent `json:"events,omitempty"`
Execution *TestWorkflowTagSchema `json:"execution,omitempty"`
Pvcs map[string]TestWorkflowPvcConfig `json:"pvcs,omitempty"`
}
24 changes: 24 additions & 0 deletions pkg/api/v1/testkube/model_test_workflow_pvc_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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

type TestWorkflowPvcConfig struct {
// Access mode for claim storage. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes
AccessModes []string `json:"accessModes,omitempty"`
VolumeMode *BoxedString `json:"volumeMode,omitempty"`
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"`
DataSource *TypedLocalObjectReference `json:"dataSource,omitempty"`
DataSourceRef *TypedObjectReference `json:"dataSourceRef,omitempty"`
VolumeAttributesClassName *BoxedString `json:"volumeAttributesClassName,omitempty"`
}
3 changes: 2 additions & 1 deletion pkg/api/v1/testkube/model_test_workflow_service_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ type TestWorkflowServiceSpec struct {
// matrix of parameters to spawn instances
Matrix map[string]interface{} `json:"matrix,omitempty"`
// parameters that should be distributed across sharded instances
Shards map[string]interface{} `json:"shards,omitempty"`
Shards map[string]interface{} `json:"shards,omitempty"`
Pvcs map[string]TestWorkflowPvcConfig `json:"pvcs,omitempty"`
}
1 change: 1 addition & 0 deletions pkg/api/v1/testkube/model_test_workflow_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ type TestWorkflowSpec struct {
After []TestWorkflowStep `json:"after,omitempty"`
Events []TestWorkflowEvent `json:"events,omitempty"`
Execution *TestWorkflowTagSchema `json:"execution,omitempty"`
Pvcs map[string]TestWorkflowPvcConfig `json:"pvcs,omitempty"`
}
1 change: 1 addition & 0 deletions pkg/api/v1/testkube/model_test_workflow_step_parallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ type TestWorkflowStepParallel struct {
After []TestWorkflowStep `json:"after,omitempty"`
Events []TestWorkflowEvent `json:"events,omitempty"`
Execution *TestWorkflowTagSchema `json:"execution,omitempty"`
Pvcs map[string]TestWorkflowPvcConfig `json:"pvcs,omitempty"`
}
1 change: 1 addition & 0 deletions pkg/api/v1/testkube/model_test_workflow_template_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ type TestWorkflowTemplateSpec struct {
After []TestWorkflowIndependentStep `json:"after,omitempty"`
Events []TestWorkflowEvent `json:"events,omitempty"`
Execution *TestWorkflowTagSchema `json:"execution,omitempty"`
Pvcs map[string]TestWorkflowPvcConfig `json:"pvcs,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"`
}
70 changes: 70 additions & 0 deletions pkg/mapper/testworkflows/kube_openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,7 @@ func MapStepParallelKubeToAPI(v testworkflowsv1.StepParallel) testkube.TestWorkf
Run: common.MapPtr(v.Run, MapStepRunKubeToAPI),
Execute: common.MapPtr(v.Execute, MapStepExecuteKubeToAPI),
Artifacts: common.MapPtr(v.Artifacts, MapStepArtifactsKubeToAPI),
Pvcs: common.MapMap(v.Pvcs, MapPvcConfigKubeToAPI),
}
}

Expand Down Expand Up @@ -948,6 +949,7 @@ func MapIndependentStepParallelKubeToAPI(v testworkflowsv1.IndependentStepParall
Run: common.MapPtr(v.Run, MapStepRunKubeToAPI),
Execute: common.MapPtr(v.Execute, MapStepExecuteKubeToAPI),
Artifacts: common.MapPtr(v.Artifacts, MapStepArtifactsKubeToAPI),
Pvcs: common.MapMap(v.Pvcs, MapPvcConfigKubeToAPI),
}
}

Expand Down Expand Up @@ -1028,6 +1030,7 @@ func MapIndependentServiceSpecKubeToAPI(v testworkflowsv1.IndependentServiceSpec
Logs: MapStringToBoxedString(v.Logs),
RestartPolicy: string(v.RestartPolicy),
ReadinessProbe: common.MapPtr(v.ReadinessProbe, MapProbeKubeToAPI),
Pvcs: common.MapMap(v.Pvcs, MapPvcConfigKubeToAPI),
}
}

Expand Down Expand Up @@ -1057,6 +1060,7 @@ func MapServiceSpecKubeToAPI(v testworkflowsv1.ServiceSpec) testkube.TestWorkflo
Logs: MapStringToBoxedString(v.Logs),
RestartPolicy: string(v.RestartPolicy),
ReadinessProbe: common.MapPtr(v.ReadinessProbe, MapProbeKubeToAPI),
Pvcs: common.MapMap(v.Pvcs, MapPvcConfigKubeToAPI),
}
}

Expand Down Expand Up @@ -1134,6 +1138,7 @@ func MapSpecKubeToAPI(v testworkflowsv1.TestWorkflowSpec) testkube.TestWorkflowS
After: common.MapSlice(v.After, MapStepKubeToAPI),
Events: common.MapSlice(v.Events, MapEventKubeToAPI),
Execution: common.MapPtr(v.Execution, MapTestWorkflowTagSchemaKubeToAPI),
Pvcs: common.MapMap(v.Pvcs, MapPvcConfigKubeToAPI),
}
}

Expand All @@ -1150,6 +1155,7 @@ func MapTemplateSpecKubeToAPI(v testworkflowsv1.TestWorkflowTemplateSpec) testku
After: common.MapSlice(v.After, MapIndependentStepKubeToAPI),
Events: common.MapSlice(v.Events, MapEventKubeToAPI),
Execution: common.MapPtr(v.Execution, MapTestWorkflowTagSchemaKubeToAPI),
Pvcs: common.MapMap(v.Pvcs, MapPvcConfigKubeToAPI),
}
}

Expand Down Expand Up @@ -1206,3 +1212,67 @@ func MapTestWorkflowTagSchemaKubeToAPI(v testworkflowsv1.TestWorkflowTagSchema)
Tags: v.Tags,
}
}

func MapTypeLocalObjectReferenceKubeToAPI(v corev1.TypedLocalObjectReference) testkube.TypedLocalObjectReference {
return testkube.TypedLocalObjectReference{
ApiGroup: MapStringToBoxedString(v.APIGroup),
Kind: v.Kind,
Name: v.Name,
}
}

func MapTypeObjectReferenceKubeToAPI(v corev1.TypedObjectReference) testkube.TypedObjectReference {
return testkube.TypedObjectReference{
ApiGroup: MapStringToBoxedString(v.APIGroup),
Kind: v.Kind,
Name: v.Name,
Namespace: MapStringToBoxedString(v.Namespace),
}
}

func MapVolumeResourceRequirementsKubeToAPI(v corev1.VolumeResourceRequirements) *testkube.TestWorkflowResources {
return &testkube.TestWorkflowResources{
Limits: MapResourcesListKubeCoreToAPI(v.Limits),
Requests: MapResourcesListKubeCoreToAPI(v.Requests),
}
}

func MapResourcesListKubeCoreToAPI(v corev1.ResourceList) *testkube.TestWorkflowResourcesList {
if len(v) == 0 {
return nil
}

res := &testkube.TestWorkflowResourcesList{}
if q, ok := v[corev1.ResourceCPU]; ok {
res.Cpu = q.String()
}

if q, ok := v[corev1.ResourceMemory]; ok {
res.Memory = q.String()
}

if q, ok := v[corev1.ResourceStorage]; ok {
res.Storage = q.String()
}

if q, ok := v[corev1.ResourceEphemeralStorage]; ok {
res.EphemeralStorage = q.String()
}

return res
}

func MapPvcConfigKubeToAPI(v corev1.PersistentVolumeClaimSpec) testkube.TestWorkflowPvcConfig {
return testkube.TestWorkflowPvcConfig{
AccessModes: common.MapSlice(v.AccessModes,
func(v corev1.PersistentVolumeAccessMode) string { return (string)(v) }),
VolumeMode: MapStringToBoxedString((*string)(v.VolumeMode)),
Resources: MapVolumeResourceRequirementsKubeToAPI(v.Resources),
StorageClassName: MapStringToBoxedString(v.StorageClassName),
VolumeName: v.VolumeName,
Selector: common.MapPtr(v.Selector, MapSelectorToAPI),
DataSource: common.MapPtr(v.DataSource, MapTypeLocalObjectReferenceKubeToAPI),
DataSourceRef: common.MapPtr(v.DataSourceRef, MapTypeObjectReferenceKubeToAPI),
VolumeAttributesClassName: MapStringToBoxedString(v.VolumeAttributesClassName),
}
}
Loading

0 comments on commit a0e4eef

Please sign in to comment.