Skip to content

Commit

Permalink
Revert "feat: add job template field for executor (#1023)" (#1030)
Browse files Browse the repository at this point in the history
This reverts commit 08010f4.

Co-authored-by: Vladislav Sukhin <vladislav@kubeshop.io>
  • Loading branch information
vsukhin and vsukhin authored Feb 28, 2022
1 parent 08010f4 commit 8d5890c
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 138 deletions.
3 changes: 0 additions & 3 deletions api/v1/testkube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1505,9 +1505,6 @@ components:
uri:
description: URI for rest based executors
type: string
jobTemplate:
description: Job template to launch executor
type: string

ExecutorDetails:
description: Executor details with Executor data and additional information like list of executions
Expand Down
17 changes: 3 additions & 14 deletions cmd/kubectl-testkube/commands/executors/create.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package executors

import (
"io/ioutil"

"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common"
apiClient "github.com/kubeshop/testkube/pkg/api/v1/client"
"github.com/kubeshop/testkube/pkg/ui"
Expand All @@ -11,8 +9,8 @@ import (

func NewCreateExecutorCmd() *cobra.Command {
var (
types []string
name, executorType, image, uri, jobTemplate string
types []string
name, executorType, image, uri string
)

cmd := &cobra.Command{
Expand All @@ -32,21 +30,13 @@ func NewCreateExecutorCmd() *cobra.Command {
ui.Failf("Executor with name '%s' already exists in namespace %s", name, namespace)
}

jobTemplateContent := ""
if jobTemplate != "" {
b, err := ioutil.ReadFile(jobTemplate)
ui.ExitOnError("reading job template", err)
jobTemplateContent = string(b)
}

options := apiClient.CreateExecutorOptions{
Name: name,
Namespace: namespace,
Types: types,
ExecutorType: executorType,
Image: image,
Uri: uri,
JobTemplate: jobTemplateContent,
}

_, err = client.CreateExecutor(options)
Expand All @@ -57,12 +47,11 @@ func NewCreateExecutorCmd() *cobra.Command {
}

cmd.Flags().StringVarP(&name, "name", "n", "", "unique test name - mandatory")
cmd.Flags().StringArrayVarP(&types, "types", "t", []string{}, "types handled by executor")
cmd.Flags().StringArrayVarP(&types, "types", "t", []string{}, "types handled by exeutor")
cmd.Flags().StringVar(&executorType, "executor-type", "job", "executor type (defaults to job)")

cmd.Flags().StringVarP(&uri, "uri", "u", "", "if resource need to be loaded from URI")
cmd.Flags().StringVarP(&image, "image", "i", "", "if uri is git repository we can set additional branch parameter")
cmd.Flags().StringVarP(&jobTemplate, "job-template", "j", "", "if executor needs to be launched using custom job specification")

return cmd
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/gofiber/fiber/v2 v2.22.0
github.com/gookit/color v1.5.0
github.com/kelseyhightower/envconfig v1.4.0
github.com/kubeshop/testkube-operator v0.9.8
github.com/kubeshop/testkube-operator v0.9.7
github.com/minio/minio-go/v7 v7.0.14
github.com/moogar0880/problems v0.1.1
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kubeshop/testkube-operator v0.9.8 h1:V3euDIIL5VTclbIR6Mz4YltTBd5CIsmWfxNR1ZWh0L4=
github.com/kubeshop/testkube-operator v0.9.8/go.mod h1:P1LXcaJEt1eVVrdRlDZip9mNHEP7cN64USQ6u/aCOeo=
github.com/kubeshop/testkube-operator v0.9.7 h1:+mnG+aEUy3dUxzHY9hBsaTi1ueYd2SzSex8WUZajUsE=
github.com/kubeshop/testkube-operator v0.9.7/go.mod h1:P1LXcaJEt1eVVrdRlDZip9mNHEP7cN64USQ6u/aCOeo=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
Expand Down
6 changes: 0 additions & 6 deletions internal/app/api/v1/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ func (s TestkubeAPI) CreateExecutorHandler() fiber.Handler {
}

executor := mapExecutorCreateRequestToExecutorCRD(request)
if executor.Spec.JobTemplate == "" {
executor.Spec.JobTemplate = s.jobTemplate
}

created, err := s.ExecutorsClient.Create(&executor)
if err != nil {
return s.Error(c, http.StatusBadRequest, err)
Expand Down Expand Up @@ -87,7 +83,6 @@ func mapExecutorCRDToExecutorDetails(item executorv1.Executor) testkube.Executor
Image: item.Spec.Image,
Types: item.Spec.Types,
Uri: item.Spec.URI,
JobTemplate: item.Spec.JobTemplate,
},
}
}
Expand All @@ -103,7 +98,6 @@ func mapExecutorCreateRequestToExecutorCRD(request testkube.ExecutorCreateReques
Types: request.Types,
URI: request.Uri,
Image: request.Image,
JobTemplate: request.JobTemplate,
},
}
}
14 changes: 1 addition & 13 deletions internal/app/api/v1/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,7 @@ func NewServer(
s.Log.Warnf("load default executors %w", err)
}

jobTemplate := os.Getenv("TESTKUBE_JOB_TEMPLATE")
if jobTemplate != "" {
dataDecoded, err := base64.StdEncoding.DecodeString(jobTemplate)
if err != nil {
s.Log.Warnf("decode job template %w", err)
}

jobTemplate = string(dataDecoded)
}

s.jobTemplate = jobTemplate
s.Executor, err = client.NewJobExecutor(executionsResults, initImage, s.jobTemplate)
s.Executor, err = client.NewJobExecutor(executionsResults, initImage)
if err != nil {
panic(err)
}
Expand All @@ -91,7 +80,6 @@ type TestkubeAPI struct {
Metrics Metrics
Storage storage.Client
storageParams storageParams
jobTemplate string
}

type storageParams struct {
Expand Down
2 changes: 0 additions & 2 deletions pkg/api/v1/testkube/model_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@ type Executor struct {
Types []string `json:"types,omitempty"`
// URI for rest based executors
Uri string `json:"uri,omitempty"`
// Job template to launch executor
JobTemplate string `json:"jobTemplate,omitempty"`
}
2 changes: 0 additions & 2 deletions pkg/api/v1/testkube/model_executor_create_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,4 @@ type ExecutorCreateRequest struct {
Types []string `json:"types"`
// URI for rest based executors
Uri string `json:"uri,omitempty"`
// Job template to launch executor
JobTemplate string `json:"jobTemplate,omitempty"`
}
16 changes: 4 additions & 12 deletions pkg/executor/client/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"go.uber.org/zap"
)

func NewJobExecutor(repo result.Repository, initImage, jobTemplate string) (client JobExecutor, err error) {
jobClient, err := jobs.NewJobClient(initImage, jobTemplate)
func NewJobExecutor(repo result.Repository, initImage string) (client JobExecutor, err error) {
jobClient, err := jobs.NewJobClient(initImage)
if err != nil {
return client, fmt.Errorf("can't get k8s jobs client: %w", err)
}
Expand Down Expand Up @@ -98,24 +98,16 @@ func (c JobExecutor) Logs(id string) (out chan output.Output, err error) {
// Execute starts new external test execution, reads data and returns ID
// Execution is started asynchronously client can check later for results
func (c JobExecutor) Execute(execution testkube.Execution, options ExecuteOptions) (result testkube.ExecutionResult, err error) {
return c.Client.LaunchK8sJob(c.Repository, execution, getJobOptions(options))
return c.Client.LaunchK8sJob(options.ExecutorSpec.Image, c.Repository, execution, options.HasSecrets)
}

// Execute starts new external test execution, reads data and returns ID
// Execution is started synchronously client will be blocked
func (c JobExecutor) ExecuteSync(execution testkube.Execution, options ExecuteOptions) (result testkube.ExecutionResult, err error) {
return c.Client.LaunchK8sJobSync(c.Repository, execution, getJobOptions(options))
return c.Client.LaunchK8sJobSync(options.ExecutorSpec.Image, c.Repository, execution, options.HasSecrets)
}

func (c JobExecutor) Abort(id string) error {
c.Client.AbortK8sJob(id)
return nil
}

func getJobOptions(options ExecuteOptions) jobs.JobOptions {
return jobs.JobOptions{
Image: options.ExecutorSpec.Image,
HasSecrets: options.HasSecrets,
JobTemplate: options.ExecutorSpec.JobTemplate,
}
}
Loading

0 comments on commit 8d5890c

Please sign in to comment.