Skip to content

Commit

Permalink
feat: execution namespace model
Browse files Browse the repository at this point in the history
  • Loading branch information
vsukhin committed Feb 22, 2024
1 parent 8d1bec2 commit 5d70876
Show file tree
Hide file tree
Showing 21 changed files with 188 additions and 12 deletions.
6 changes: 6 additions & 0 deletions api/v1/testkube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4905,6 +4905,9 @@ components:
slavePodRequest:
$ref: "#/components/schemas/PodRequest"
description: configuration parameters for executed slave pods
executionNamespace:
type: string
description: namespace for test execution (Pro edition only)

Artifact:
type: object
Expand Down Expand Up @@ -5550,6 +5553,9 @@ components:
slavePodRequest:
$ref: "#/components/schemas/PodRequest"
description: configuration parameters for executed slave pods
executionNamespace:
type: string
description: namespace for test execution (Pro edition only)

ExecutionUpdateRequest:
description: test execution request update body
Expand Down
6 changes: 6 additions & 0 deletions cmd/kubectl-testkube/commands/tests/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ func newExecutionRequestFromFlags(cmd *cobra.Command) (request *testkube.Executi
cronJobTemplateReference := cmd.Flag("cronjob-template-reference").Value.String()
scraperTemplateReference := cmd.Flag("scraper-template-reference").Value.String()
pvcTemplateReference := cmd.Flag("pvc-template-reference").Value.String()
executionNamespace := cmd.Flag("execution-namespace").Value.String()
executePostRunScriptBeforeScraping, err := cmd.Flags().GetBool("execute-postrun-script-before-scraping")
if err != nil {
return nil, err
Expand All @@ -514,6 +515,7 @@ func newExecutionRequestFromFlags(cmd *cobra.Command) (request *testkube.Executi
PvcTemplateReference: pvcTemplateReference,
NegativeTest: negativeTest,
ExecutePostRunScriptBeforeScraping: executePostRunScriptBeforeScraping,
ExecutionNamespace: executionNamespace,
}

var fields = []struct {
Expand Down Expand Up @@ -909,6 +911,10 @@ func newExecutionUpdateRequestFromFlags(cmd *cobra.Command) (request *testkube.E
"pvc-template-reference",
&request.PvcTemplateReference,
},
{
"execution-namespace",
&request.ExecutionNamespace,
},
}

var nonEmpty bool
Expand Down
2 changes: 2 additions & 0 deletions cmd/kubectl-testkube/commands/tests/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type CreateCommonFlags struct {
SlavePodLimitsMemory string
SlavePodTemplate string
SlavePodTemplateReference string
ExecutionNamespace string
}

// NewCreateTestsCmd is a command tp create new Test Custom Resource
Expand Down Expand Up @@ -276,6 +277,7 @@ func AddCreateFlags(cmd *cobra.Command, flags *CreateCommonFlags) {
cmd.Flags().StringVar(&flags.SlavePodLimitsMemory, "slave-pod-limits-memory", "", "slave pod resource limits memory")
cmd.Flags().StringVar(&flags.SlavePodTemplate, "slave-pod-template", "", "slave pod template file path for extensions to slave pod template")
cmd.Flags().StringVar(&flags.SlavePodTemplateReference, "slave-pod-template-reference", "", "reference to slave pod template to use for the test")
cmd.Flags().StringVar(&flags.ExecutionNamespace, "execution-namespace", "", "namespace for test execution (Pro edition only)")
}

func validateExecutorTypeAndContent(executorType, contentType string, executors testkube.ExecutorsDetails) error {
Expand Down
4 changes: 4 additions & 0 deletions cmd/kubectl-testkube/commands/tests/renderer/test_obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ func TestRenderer(client client.Client, ui *ui.UI, obj interface{}) error {
ui.Warn(" PVC template reference: ", test.ExecutionRequest.PvcTemplateReference)
}

if test.ExecutionRequest.ExecutionNamespace != "" {
ui.Warn(" Execution namespace: ", test.ExecutionRequest.ExecutionNamespace)
}

if test.ExecutionRequest.SlavePodRequest != nil {
ui.Warn(" Slave pod request: ")
if test.ExecutionRequest.SlavePodRequest.Resources != nil {
Expand Down
3 changes: 3 additions & 0 deletions cmd/kubectl-testkube/commands/tests/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func NewRunTestCmd() *cobra.Command {
slavePodLimitsMemory string
slavePodTemplate string
slavePodTemplateReference string
executionNamespace string
)

cmd := &cobra.Command{
Expand Down Expand Up @@ -123,6 +124,7 @@ func NewRunTestCmd() *cobra.Command {
Context: runningContext,
},
ExecutePostRunScriptBeforeScraping: executePostRunScriptBeforeScraping,
ExecutionNamespace: executionNamespace,
}

var fields = []struct {
Expand Down Expand Up @@ -400,6 +402,7 @@ func NewRunTestCmd() *cobra.Command {
cmd.Flags().StringVar(&slavePodLimitsMemory, "slave-pod-limits-memory", "", "slave pod resource limits memory")
cmd.Flags().StringVar(&slavePodTemplate, "slave-pod-template", "", "slave pod template file path for extensions to slave pod template")
cmd.Flags().StringVar(&slavePodTemplateReference, "slave-pod-template-reference", "", "reference to slave pod template to use for the test")
cmd.Flags().StringVar(&executionNamespace, "execution-namespace", "", "namespace for test execution (Pro edition only)")

return cmd
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/joshdk/go-junit v1.0.0
github.com/kelseyhightower/envconfig v1.4.0
github.com/kubepug/kubepug v1.7.1
github.com/kubeshop/testkube-operator v1.15.2-beta1.0.20240221134011-c1770f0bea80
github.com/kubeshop/testkube-operator v1.15.2-beta1.0.20240222133855-3548c867ee93
github.com/minio/minio-go/v7 v7.0.47
github.com/montanaflynn/stats v0.6.6
github.com/moogar0880/problems v0.1.1
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,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.15.2-beta1.0.20240118132107-2c37729871a3 h1:R6xdH//ctWpE18U1GYwzNvq1HLiT9LUJogXkfyKDDGo=
github.com/kubeshop/testkube-operator v1.15.2-beta1.0.20240118132107-2c37729871a3/go.mod h1:P47tw1nKQFufdsZndyq2HG2MSa0zK/lU0XpRfZtEmIk=
github.com/kubeshop/testkube-operator v1.15.2-beta1.0.20240221134011-c1770f0bea80 h1:4hnZi3dMBmpz4SxE9PrsJTG2JA/P5h+4PMrSXjUEEbA=
github.com/kubeshop/testkube-operator v1.15.2-beta1.0.20240221134011-c1770f0bea80/go.mod h1:P47tw1nKQFufdsZndyq2HG2MSa0zK/lU0XpRfZtEmIk=
github.com/kubeshop/testkube-operator v1.15.2-beta1.0.20240222133855-3548c867ee93 h1:Acq/Cnk4gFocS7ZzsvlS+pyHv1fplxqREfskWaUD7Pk=
github.com/kubeshop/testkube-operator v1.15.2-beta1.0.20240222133855-3548c867ee93/go.mod h1:P47tw1nKQFufdsZndyq2HG2MSa0zK/lU0XpRfZtEmIk=
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
github.com/lithammer/fuzzysearch v1.1.8 h1:/HIuJnjHuXS8bKaiTMeeDlW2/AyIWk2brx1V8LFgLN4=
Expand Down Expand Up @@ -960,8 +958,6 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
1 change: 1 addition & 0 deletions pkg/api/v1/client/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ type ExecuteTestOptions struct {
EnvSecrets []testkube.EnvReference
RunningContext *testkube.RunningContext
SlavePodRequest *testkube.PodRequest
ExecutionNamespace string
}

// ExecuteTestSuiteOptions contains test suite run options
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/v1/client/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ func (c TestClient) ExecuteTest(id, executionName string, options ExecuteTestOpt
EnvSecrets: options.EnvSecrets,
RunningContext: options.RunningContext,
SlavePodRequest: options.SlavePodRequest,
ExecutionNamespace: options.ExecutionNamespace,
}

body, err := json.Marshal(request)
Expand Down Expand Up @@ -211,6 +212,7 @@ func (c TestClient) ExecuteTests(selector string, concurrencyLevel int, options
IsNegativeTestChangedOnRun: options.IsNegativeTestChangedOnRun,
RunningContext: options.RunningContext,
SlavePodRequest: options.SlavePodRequest,
ExecutionNamespace: options.ExecutionNamespace,
}

body, err := json.Marshal(request)
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/v1/testkube/model_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,6 @@ type Execution struct {
// test names for artifacts to download from latest executions
DownloadArtifactTestNames []string `json:"downloadArtifactTestNames,omitempty"`
SlavePodRequest *PodRequest `json:"slavePodRequest,omitempty"`
// namespace for test execution (Pro edition only)
ExecutionNamespace string `json:"executionNamespace,omitempty"`
}
2 changes: 2 additions & 0 deletions pkg/api/v1/testkube/model_execution_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,6 @@ type ExecutionRequest struct {
// test names for artifacts to download from latest executions
DownloadArtifactTestNames []string `json:"downloadArtifactTestNames,omitempty"`
SlavePodRequest *PodRequest `json:"slavePodRequest,omitempty"`
// namespace for test execution (Pro edition only)
ExecutionNamespace string `json:"executionNamespace,omitempty"`
}
2 changes: 2 additions & 0 deletions pkg/api/v1/testkube/model_execution_update_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,6 @@ type ExecutionUpdateRequest struct {
// test names for artifacts to download from latest executions
DownloadArtifactTestNames *[]string `json:"downloadArtifactTestNames,omitempty"`
SlavePodRequest **PodUpdateRequest `json:"slavePodRequest,omitempty"`
// namespace for test execution (Pro edition only)
ExecutionNamespace *string `json:"executionNamespace,omitempty"`
}
5 changes: 4 additions & 1 deletion pkg/crd/templates/test.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ spec:
schedule: {{ .Schedule }}
{{- end }}
{{- if .ExecutionRequest }}
{{- if or (.ExecutionRequest.Name) (.ExecutionRequest.NegativeTest) (.ExecutionRequest.VariablesFile) (.ExecutionRequest.HttpProxy) (.ExecutionRequest.HttpsProxy) (ne (len .ExecutionRequest.Variables) 0) (ne (len .ExecutionRequest.Args) 0) (ne (len .ExecutionRequest.Envs) 0) (ne (len .ExecutionRequest.SecretEnvs) 0) (.ExecutionRequest.Image) (ne (len .ExecutionRequest.Command) 0) (.ExecutionRequest.ArgsMode) (ne (len .ExecutionRequest.ImagePullSecrets) 0) (ne .ExecutionRequest.ActiveDeadlineSeconds 0) (.ExecutionRequest.ArtifactRequest) (.ExecutionRequest.JobTemplate) (.ExecutionRequest.JobTemplateReference) (.ExecutionRequest.CronJobTemplate) (.ExecutionRequest.CronJobTemplateReference) (.ExecutionRequest.PreRunScript) (.ExecutionRequest.PostRunScript) (.ExecutionRequest.ExecutePostRunScriptBeforeScraping) (.ExecutionRequest.ScraperTemplate) (.ExecutionRequest.ScraperTemplateReference) (.ExecutionRequest.PvcTemplate) (.ExecutionRequest.PvcTemplateReference) (ne (len .ExecutionRequest.EnvConfigMaps) 0) (ne (len .ExecutionRequest.EnvSecrets) 0) (.ExecutionRequest.SlavePodRequest)}}
{{- if or (.ExecutionRequest.Name) (.ExecutionRequest.NegativeTest) (.ExecutionRequest.VariablesFile) (.ExecutionRequest.HttpProxy) (.ExecutionRequest.HttpsProxy) (ne (len .ExecutionRequest.Variables) 0) (ne (len .ExecutionRequest.Args) 0) (ne (len .ExecutionRequest.Envs) 0) (ne (len .ExecutionRequest.SecretEnvs) 0) (.ExecutionRequest.Image) (ne (len .ExecutionRequest.Command) 0) (.ExecutionRequest.ArgsMode) (ne (len .ExecutionRequest.ImagePullSecrets) 0) (ne .ExecutionRequest.ActiveDeadlineSeconds 0) (.ExecutionRequest.ArtifactRequest) (.ExecutionRequest.JobTemplate) (.ExecutionRequest.JobTemplateReference) (.ExecutionRequest.CronJobTemplate) (.ExecutionRequest.CronJobTemplateReference) (.ExecutionRequest.PreRunScript) (.ExecutionRequest.PostRunScript) (.ExecutionRequest.ExecutePostRunScriptBeforeScraping) (.ExecutionRequest.ScraperTemplate) (.ExecutionRequest.ScraperTemplateReference) (.ExecutionRequest.PvcTemplate) (.ExecutionRequest.PvcTemplateReference) (ne (len .ExecutionRequest.EnvConfigMaps) 0) (ne (len .ExecutionRequest.EnvSecrets) 0) (.ExecutionRequest.SlavePodRequest) (.ExecutionRequest.ExecutionNamespace)}}
executionRequest:
{{- if .ExecutionRequest.Name }}
name: {{ .ExecutionRequest.Name }}
Expand Down Expand Up @@ -235,6 +235,9 @@ spec:
{{- if .ExecutionRequest.PvcTemplateReference }}
pvcTemplateReference: {{ .ExecutionRequest.PvcTemplateReference }}
{{- end }}
{{- if .ExecutionRequest.ExecutionNamespace }}
executionNamespace: {{ .ExecutionRequest.ExecutionNamespace }}
{{- end }}
{{- if .ExecutionRequest.SlavePodRequest }}
slavePodRequest:
{{- if .ExecutionRequest.SlavePodRequest.Resources }}
Expand Down
5 changes: 4 additions & 1 deletion pkg/mapper/testexecutions/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

testexecutionv1 "github.com/kubeshop/testkube-operator/api/testexecution/v1"
"github.com/kubeshop/testkube/pkg/api/v1/testkube"
mappertcl "github.com/kubeshop/testkube/pkg/tcl/mappertcl/testexecutions"
)

// MapCRDVariables maps variables between API and operator CRDs
Expand Down Expand Up @@ -216,5 +217,7 @@ func MapAPIToCRD(request *testkube.Execution, generation int64) testexecutionv1.

result.LatestExecution.StartTime.Time = request.StartTime
result.LatestExecution.EndTime.Time = request.EndTime
return result

// Pro edition only (tcl protected code)
return *mappertcl.MapAPIToCRD(request, &result)
}
9 changes: 8 additions & 1 deletion pkg/mapper/tests/kube_openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
commonv1 "github.com/kubeshop/testkube-operator/api/common/v1"
testsv3 "github.com/kubeshop/testkube-operator/api/tests/v3"
"github.com/kubeshop/testkube/pkg/api/v1/testkube"
mappertcl "github.com/kubeshop/testkube/pkg/tcl/mappertcl/tests"
)

// MapTestListKubeToAPI maps CRD list data to OpenAPI spec tests list
Expand Down Expand Up @@ -153,7 +154,7 @@ func MapExecutionRequestFromSpec(specExecutionRequest *testsv3.ExecutionRequest)
podRequest.PodTemplateReference = specExecutionRequest.SlavePodRequest.PodTemplateReference
}

return &testkube.ExecutionRequest{
result := &testkube.ExecutionRequest{
Name: specExecutionRequest.Name,
TestSuiteName: specExecutionRequest.TestSuiteName,
Number: specExecutionRequest.Number,
Expand Down Expand Up @@ -192,6 +193,9 @@ func MapExecutionRequestFromSpec(specExecutionRequest *testsv3.ExecutionRequest)
EnvSecrets: MapEnvReferences(specExecutionRequest.EnvSecrets),
SlavePodRequest: podRequest,
}

// Pro edition only (tcl protected code)
return mappertcl.MapExecutionRequestFromSpec(specExecutionRequest, result)
}

// MapImagePullSecrets maps Kubernetes spec to testkube model
Expand Down Expand Up @@ -519,6 +523,9 @@ func MapSpecExecutionRequestToExecutionUpdateRequest(
executionRequest.EnvSecrets = &envSecrets
executionRequest.ExecutePostRunScriptBeforeScraping = &request.ExecutePostRunScriptBeforeScraping

// Pro edition only (tcl protected code)
mappertcl.MapSpecExecutionRequestToExecutionUpdateRequest(request, executionRequest)

if request.ArtifactRequest != nil {
artifactRequest := &testkube.ArtifactUpdateRequest{
StorageClassName: &request.ArtifactRequest.StorageClassName,
Expand Down
11 changes: 10 additions & 1 deletion pkg/mapper/tests/openapi_kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

testsv3 "github.com/kubeshop/testkube-operator/api/tests/v3"
"github.com/kubeshop/testkube/pkg/api/v1/testkube"
mappertcl "github.com/kubeshop/testkube/pkg/tcl/mappertcl/tests"
)

// MapUpsertToSpec maps TestUpsertRequest to Test CRD spec
Expand Down Expand Up @@ -165,7 +166,7 @@ func MapExecutionRequestToSpecExecutionRequest(executionRequest *testkube.Execut
podRequest.PodTemplateReference = executionRequest.SlavePodRequest.PodTemplateReference
}

return &testsv3.ExecutionRequest{
result := &testsv3.ExecutionRequest{
Name: executionRequest.Name,
TestSuiteName: executionRequest.TestSuiteName,
Number: executionRequest.Number,
Expand Down Expand Up @@ -204,6 +205,9 @@ func MapExecutionRequestToSpecExecutionRequest(executionRequest *testkube.Execut
EnvSecrets: mapEnvReferences(executionRequest.EnvSecrets),
SlavePodRequest: podRequest,
}

// Pro edition only (tcl protected code)
return mappertcl.MapExecutionRequestToSpecExecutionRequest(executionRequest, result)
}

func mapImagePullSecrets(secrets []testkube.LocalObjectReference) (res []v1.LocalObjectReference) {
Expand Down Expand Up @@ -627,6 +631,11 @@ func MapExecutionUpdateRequestToSpecExecutionRequest(executionRequest *testkube.
emptyExecution = false
}

// Pro edition only (tcl protected code)
if !mappertcl.MapExecutionUpdateRequestToSpecExecutionRequest(executionRequest, request) {
emptyExecution = false
}

if executionRequest.ArtifactRequest != nil {
emptyArtifact := true
if !(*executionRequest.ArtifactRequest == nil || (*executionRequest.ArtifactRequest).IsEmpty()) {
Expand Down
5 changes: 4 additions & 1 deletion pkg/mapper/testsuiteexecutions/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

testsuiteexecutionv1 "github.com/kubeshop/testkube-operator/api/testsuiteexecution/v1"
"github.com/kubeshop/testkube/pkg/api/v1/testkube"
mappertcl "github.com/kubeshop/testkube/pkg/tcl/mappertcl/testsuiteexecutions"
)

// MapCRDVariables maps variables between API and operator CRDs
Expand Down Expand Up @@ -218,7 +219,9 @@ func MapExecutionCRD(request *testkube.Execution) *testsuiteexecutionv1.Executio

result.StartTime.Time = request.StartTime
result.EndTime.Time = request.EndTime
return result

// Pro edition only (tcl protected code)
return mappertcl.MapExecutionCRD(request, result)
}

func MapTestSuiteStepV2ToCRD(request *testkube.TestSuiteStepV2) *testsuiteexecutionv1.TestSuiteStepV2 {
Expand Down
25 changes: 25 additions & 0 deletions pkg/tcl/mappertcl/testexecutions/mapper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2024 Testkube.
//
// Licensed as a Testkube Pro file under the Testkube Community
// License (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// https://github.com/kubeshop/testkube/blob/main/licenses/TCL.txt

package testexecutions

import (
testexecutionv1 "github.com/kubeshop/testkube-operator/api/testexecution/v1"
"github.com/kubeshop/testkube/pkg/api/v1/testkube"
)

// MapAPIToCRD maps OpenAPI spec Execution to CRD TestExecutionStatus
func MapAPIToCRD(sourceRequest *testkube.Execution,
destinationRequest *testexecutionv1.TestExecutionStatus) *testexecutionv1.TestExecutionStatus {
if sourceRequest == nil || destinationRequest == nil {
return destinationRequest
}

destinationRequest.LatestExecution.ExecutionNamespace = sourceRequest.ExecutionNamespace
return destinationRequest
}
35 changes: 35 additions & 0 deletions pkg/tcl/mappertcl/tests/kube_openapi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2024 Testkube.
//
// Licensed as a Testkube Pro file under the Testkube Community
// License (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// https://github.com/kubeshop/testkube/blob/main/licenses/TCL.txt

package tests

import (
testsv3 "github.com/kubeshop/testkube-operator/api/tests/v3"
"github.com/kubeshop/testkube/pkg/api/v1/testkube"
)

// MapExecutionRequestFromSpec maps CRD to OpenAPI spec ExecutionREquest
func MapExecutionRequestFromSpec(sourceRequest *testsv3.ExecutionRequest,
destinationRequest *testkube.ExecutionRequest) *testkube.ExecutionRequest {
if sourceRequest == nil || destinationRequest == nil {
return destinationRequest
}

destinationRequest.ExecutionNamespace = sourceRequest.ExecutionNamespace
return destinationRequest
}

// MapSpecExecutionRequestToExecutionUpdateRequest maps ExecutionRequest CRD spec to ExecutionUpdateRequest OpenAPI spec to
func MapSpecExecutionRequestToExecutionUpdateRequest(
sourceRequest *testsv3.ExecutionRequest, destinationRequest *testkube.ExecutionUpdateRequest) {
if sourceRequest == nil || destinationRequest == nil {
return
}

destinationRequest.ExecutionNamespace = &sourceRequest.ExecutionNamespace
}
Loading

0 comments on commit 5d70876

Please sign in to comment.