Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [TKC-2895] pvc config #6074

Merged
merged 37 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7530e05
feat: pvc config
vsukhin Dec 11, 2024
6d67658
fix: rename var
vsukhin Dec 11, 2024
76ea394
fix: dep update
vsukhin Dec 11, 2024
6b99bc4
fix: map pvc to api
vsukhin Dec 11, 2024
a7c36c0
fix: map to kube
vsukhin Dec 11, 2024
8e8d073
fix: add pvc to control plane
vsukhin Dec 11, 2024
3bbba25
cleanup pvcs
vsukhin Dec 12, 2024
d9fcff8
fix: merge pvcs map
vsukhin Dec 12, 2024
bd2cf57
fix: add pvcs to service spec
vsukhin Dec 12, 2024
0d02d16
fix: remove duplication
vsukhin Dec 12, 2024
b85e274
fix: dep update
vsukhin Dec 12, 2024
fd2dd60
fix: setvice pvcs
vsukhin Dec 12, 2024
551f1b2
fi: dep update
vsukhin Dec 12, 2024
6faffdb
fix: append pvcs
vsukhin Dec 12, 2024
da9e7f1
fix: copy service pvcs
vsukhin Dec 12, 2024
5417211
fix: pvc name for execution
vsukhin Dec 12, 2024
597a69a
fix: register pvc names
vsukhin Dec 12, 2024
bd3aad2
fix: convert pvc
vsukhin Dec 13, 2024
95c8992
fix: move fields to boxed strings
vsukhin Dec 13, 2024
54b352d
fix: dep update
vsukhin Dec 13, 2024
c83e10b
Merge branch 'main' into vsukhin/feature/test-workflow-pvcs
vsukhin Dec 13, 2024
3520a1a
fix: pass pvc names
vsukhin Dec 16, 2024
6effa79
fix: renname cobfig field
vsukhin Dec 16, 2024
f89592e
fix: remove var
vsukhin Dec 16, 2024
c47ff99
fix: add new pvc config fields
vsukhin Dec 16, 2024
f2dd57b
fix: pvc mapping
vsukhin Dec 17, 2024
a6f70f4
fix: json tag
vsukhin Dec 17, 2024
bc49ed2
fix: use proper pvc name
vsukhin Dec 18, 2024
ea3e45c
fix: merge maps
vsukhin Dec 18, 2024
691a5e9
fix: api spec format
vsukhin Dec 18, 2024
19fadbf
fix: typo
vsukhin Dec 18, 2024
f242e45
fix: format methods
vsukhin Dec 18, 2024
978e7aa
fix: use map instead of slice
vsukhin Dec 18, 2024
1ae2d0a
fix: rename method
vsukhin Dec 18, 2024
9de4313
fix: unique ref
vsukhin Dec 18, 2024
2ecd423
fix: use root id
vsukhin Dec 18, 2024
6c46caa
fix: dep update
vsukhin Dec 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions api/v1/testkube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8678,6 +8678,10 @@ components:
type: string
readinessProbe:
$ref: "#/components/schemas/Probe"
pvcs:
type: object
additionalProperties:
$ref: "#/components/schemas/TestWorkflowPvcConfig"

TestWorkflowServiceSpec:
type: object
Expand Down Expand Up @@ -8797,6 +8801,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 @@ -8835,6 +8843,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 @@ -10588,6 +10600,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.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.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.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
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
Loading