Skip to content

Commit

Permalink
feat: use command parameters and deprecate args (#3694)
Browse files Browse the repository at this point in the history
* feat: use command parameters and deprecate args

* fix: go fmt

* fix: command mode field

* feat:command mode field

* fix: agrs mode field

* fix: use args mode

* fix: rmove deprecated

* fix: golint

* fix: unit test

* fix: unit test

* fix: support command and args in curl

* fix: args mode parameter

* fix: remove log

* fix: go lint

* fix: remove unused const

* feat: artillery command and args

* fix: update model for artifcts

* feat: change artifact support

* fix: refresh docs

* fix: scrape curl dirs

* fix: unit test

* feat: postman command and args

* fix: unit test

* feat: kubepug args and command

* fix: unit  test

* fix: int test

* fix: postman int

* feat: soapui command and args

* fix: unit test

* feat: add gradle command and arguments

* fix: unit test

* fix: unit test

* fix: int test

* feat: maven args and command

* feat: jmeter command and args

* fix: unit test

* fix: unit test

* feat: cypress command and args

* feat: command and args for ginkgo

* fix: golint

* fix: report file for ginkgo

* fix: ginkgo vars arg

* feat: k6 args and command

* feat: playwright command and args

* fix: ci flow

* doc: executor default args and command

* fix: escape <> for docs

* fix: dep update

* doc: explain parameters

* doc: executor command and args example
  • Loading branch information
vsukhin committed May 4, 2023
1 parent e1d2438 commit 9ff44ab
Show file tree
Hide file tree
Showing 99 changed files with 1,354 additions and 531 deletions.
39 changes: 27 additions & 12 deletions api/v1/testkube.yaml
Expand Up @@ -3608,12 +3608,24 @@ components:
example:
record: "true"
prefix: "some-"
command:
type: array
description: "executor image command"
example: ["curl"]
items:
type: string
args:
type: array
description: "additional arguments/flags passed to executor binary"
example: ["--concurrency", "2", "--remote", "--some", "blabla"]
items:
type: string
args_mode:
type: string
description: usage mode for arguments
enum:
- append
- override
variables:
$ref: "#/components/schemas/Variables"
variablesFile:
Expand Down Expand Up @@ -3671,7 +3683,7 @@ components:
example: execution-c01d7cf6-ec3f-47f0-9556-a5d6e9009a43
artifactRequest:
$ref: "#/components/schemas/ArtifactRequest"
description: configuration parameters for storing container executor test artifacts
description: configuration parameters for storing test artifacts
preRunScript:
type: string
description: script to run before test execution
Expand Down Expand Up @@ -3989,24 +4001,21 @@ components:
- $ref: "#/components/schemas/RepositoryParameters"

ArtifactRequest:
description: artifact request body for container executors with test artifacts
description: artifact request body with test artifacts
type: object
required:
- storageClassName
- volumeMountPath
properties:
storageClassName:
type: string
description: artifact storage class name
description: artifact storage class name for container executor
example: artifact-volume-local
volumeMountPath:
type: string
description: artifact volume mount path
description: artifact volume mount path for container executor
dirs:
type: array
items:
type: string
description: artifact directories
description: artifact directories for scraping

ArtifactUpdateRequest:
description: artifact request update body
Expand Down Expand Up @@ -4059,7 +4068,7 @@ components:
example: "7934600f-b367-48dd-b981-4353304362fb"
command:
type: array
description: "container executor image command"
description: "executor image command"
items:
type: string
example:
Expand All @@ -4073,6 +4082,12 @@ components:
- "--repeats"
- "5"
- "--insecure"
args_mode:
type: string
description: usage mode for arguments
enum:
- append
- override
image:
type: string
description: container image, executor will run inside this image
Expand Down Expand Up @@ -4137,7 +4152,7 @@ components:
example: execution-c01d7cf6-ec3f-47f0-9556-a5d6e9009a43
artifactRequest:
$ref: "#/components/schemas/ArtifactRequest"
description: configuration parameters for storing container executor test artifacts
description: configuration parameters for storing test artifacts
jobTemplate:
type: string
description: job template extensions
Expand Down Expand Up @@ -4339,14 +4354,14 @@ components:
$ref: "#/components/schemas/LocalObjectReference"
command:
type: array
description: "container executor image command"
description: "executor image command"
items:
type: string
example:
- "curl"
args:
type: array
description: "additional executor binary arguments"
description: "additional executor binary argument"
items:
type: string
example:
Expand Down
9 changes: 8 additions & 1 deletion cmd/kubectl-testkube/commands/crds/tests_crds.go
Expand Up @@ -166,7 +166,14 @@ func processPostmanFiles(cmd *cobra.Command, args []string) error {
}
}

test.ExecutionRequest = &testkube.ExecutionRequest{Args: flags.ExecutorArgs, Envs: flags.Envs, Variables: vars, PreRunScript: scriptBody}
test.ExecutionRequest = &testkube.ExecutionRequest{
Command: flags.Command,
Args: flags.ExecutorArgs,
ArgsMode: flags.ArgsMode,
Envs: flags.Envs,
Variables: vars,
PreRunScript: scriptBody,
}
detectedTests[testName] = test
return nil
})
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubectl-testkube/commands/executors/create.go
Expand Up @@ -68,8 +68,8 @@ func NewCreateExecutorCmd() *cobra.Command {
cmd.Flags().StringVarP(&uri, "uri", "u", "", "if resource need to be loaded from URI")
cmd.Flags().StringVar(&image, "image", "", "image used for executor")
cmd.Flags().StringArrayVar(&imagePullSecretNames, "image-pull-secrets", []string{}, "secret name used to pull the image in executor")
cmd.Flags().StringArrayVar(&command, "command", []string{}, "command passed to image in container executor")
cmd.Flags().StringArrayVar(&executorArgs, "args", []string{}, "args passed to image in container executor")
cmd.Flags().StringArrayVar(&command, "command", []string{}, "command passed to image in executor")
cmd.Flags().StringArrayVar(&executorArgs, "args", []string{}, "args passed to image in executor")
cmd.Flags().StringVarP(&jobTemplate, "job-template", "j", "", "if executor needs to be launched using custom job specification, then a path to template file should be provided")
cmd.Flags().StringToStringVarP(&labels, "label", "l", nil, "label key value pair: --label key1=value1")
cmd.Flags().StringArrayVar(&features, "feature", []string{}, "feature provided by executor")
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubectl-testkube/commands/executors/update.go
Expand Up @@ -47,8 +47,8 @@ func UpdateExecutorCmd() *cobra.Command {
cmd.Flags().StringVarP(&uri, "uri", "u", "", "if resource need to be loaded from URI")
cmd.Flags().StringVar(&image, "image", "", "image used for executor")
cmd.Flags().StringArrayVar(&imagePullSecretNames, "image-pull-secrets", []string{}, "secret name used to pull the image in executor")
cmd.Flags().StringArrayVar(&command, "command", []string{}, "command passed to image in container executor")
cmd.Flags().StringArrayVar(&executorArgs, "args", []string{}, "args passed to image in container executor")
cmd.Flags().StringArrayVar(&command, "command", []string{}, "command passed to image in executor")
cmd.Flags().StringArrayVar(&executorArgs, "args", []string{}, "args passed to image in executor")
cmd.Flags().StringVarP(&jobTemplate, "job-template", "j", "", "if executor needs to be launched using custom job specification, then a path to template file should be provided")
cmd.Flags().StringToStringVarP(&labels, "label", "l", nil, "label key value pair: --label key1=value1")
cmd.Flags().StringArrayVar(&features, "feature", []string{}, "feature provided by executor")
Expand Down
8 changes: 7 additions & 1 deletion cmd/kubectl-testkube/commands/tests/common.go
Expand Up @@ -226,7 +226,7 @@ func newArtifactRequestFromFlags(cmd *cobra.Command) (request *testkube.Artifact
return nil, err
}

if artifactStorageClassName != "" && artifactVolumeMountPath != "" {
if artifactStorageClassName != "" || artifactVolumeMountPath != "" || len(dirs) != 0 {
request = &testkube.ArtifactRequest{
StorageClassName: artifactStorageClassName,
VolumeMountPath: artifactVolumeMountPath,
Expand Down Expand Up @@ -335,6 +335,7 @@ func newExecutionRequestFromFlags(cmd *cobra.Command) (request *testkube.Executi
return nil, err
}

argsMode := cmd.Flag("args-mode").Value.String()
executionName := cmd.Flag("execution-name").Value.String()
envs, err := cmd.Flags().GetStringToString("env")
if err != nil {
Expand Down Expand Up @@ -441,6 +442,7 @@ func newExecutionRequestFromFlags(cmd *cobra.Command) (request *testkube.Executi
Image: image,
Command: command,
Args: executorArgs,
ArgsMode: argsMode,
ImagePullSecrets: imageSecrets,
Envs: envs,
SecretEnvs: secretEnvs,
Expand Down Expand Up @@ -772,6 +774,10 @@ func newExecutionUpdateRequestFromFlags(cmd *cobra.Command) (request *testkube.E
"https-proxy",
&request.HttpsProxy,
},
{
"args-mode",
&request.ArgsMode,
},
}

var nonEmpty bool
Expand Down
19 changes: 4 additions & 15 deletions cmd/kubectl-testkube/commands/tests/create.go
Expand Up @@ -23,6 +23,7 @@ type CreateCommonFlags struct {
SecretVariables map[string]string
Schedule string
ExecutorArgs []string
ArgsMode string
ExecutionName string
VariablesFile string
Envs map[string]string
Expand Down Expand Up @@ -101,9 +102,6 @@ func NewCreateTestsCmd() *cobra.Command {
ui.ExitOnError("validating passed flags", err)
}

err = validateArtifactRequest(flags.ArtifactStorageClassName, flags.ArtifactVolumeMountPath, flags.ArtifactDirs)
ui.ExitOnError("validating artifact flags", err)

options, err := NewUpsertTestOptionsFromFlags(cmd)
ui.ExitOnError("getting test options", err)

Expand Down Expand Up @@ -180,7 +178,9 @@ func AddCreateFlags(cmd *cobra.Command, flags *CreateCommonFlags) {
cmd.Flags().StringToStringVarP(&flags.Variables, "variable", "v", nil, "variable key value pair: --variable key1=value1")
cmd.Flags().StringToStringVarP(&flags.SecretVariables, "secret-variable", "s", nil, "secret variable key value pair: --secret-variable key1=value1")
cmd.Flags().StringVarP(&flags.Schedule, "schedule", "", "", "test schedule in a cron job form: * * * * *")
cmd.Flags().StringArrayVar(&flags.Command, "command", []string{}, "command passed to image in executor")
cmd.Flags().StringArrayVarP(&flags.ExecutorArgs, "executor-args", "", []string{}, "executor binary additional arguments")
cmd.Flags().StringVarP(&flags.ArgsMode, "args-mode", "", "append", "usage mode for arguments. one of append|override")
cmd.Flags().StringVarP(&flags.ExecutionName, "execution-name", "", "", "execution name, if empty will be autogenerated")
cmd.Flags().StringVarP(&flags.VariablesFile, "variables-file", "", "", "variables file path, e.g. postman env file - will be passed to executor if supported")
cmd.Flags().StringToStringVarP(&flags.Envs, "env", "", map[string]string{}, "envs in a form of name1=val1 passed to executor")
Expand All @@ -191,11 +191,10 @@ func AddCreateFlags(cmd *cobra.Command, flags *CreateCommonFlags) {
cmd.Flags().StringArrayVarP(&flags.CopyFiles, "copy-files", "", []string{}, "file path mappings from host to pod of form source:destination")
cmd.Flags().StringVar(&flags.Image, "image", "", "image for container executor")
cmd.Flags().StringArrayVar(&flags.ImagePullSecretNames, "image-pull-secrets", []string{}, "secret name used to pull the image in container executor")
cmd.Flags().StringArrayVar(&flags.Command, "command", []string{}, "command passed to image in container executor")
cmd.Flags().Int64Var(&flags.Timeout, "timeout", 0, "duration in seconds for test to timeout. 0 disables timeout.")
cmd.Flags().StringVar(&flags.ArtifactStorageClassName, "artifact-storage-class-name", "", "artifact storage class name for container executor")
cmd.Flags().StringVar(&flags.ArtifactVolumeMountPath, "artifact-volume-mount-path", "", "artifact volume mount path for container executor")
cmd.Flags().StringArrayVarP(&flags.ArtifactDirs, "artifact-dir", "", []string{}, "artifact dirs for container executor")
cmd.Flags().StringArrayVarP(&flags.ArtifactDirs, "artifact-dir", "", []string{}, "artifact dirs for scraping")
cmd.Flags().StringVar(&flags.JobTemplate, "job-template", "", "job template file path for extensions to job template")
cmd.Flags().StringVar(&flags.CronJobTemplate, "cronjob-template", "", "cron job template file path for extensions to cron job template")
cmd.Flags().StringVarP(&flags.PreRunScript, "prerun-script", "", "", "path to script to be run before test execution")
Expand Down Expand Up @@ -244,13 +243,3 @@ func validateExecutorTypeAndContent(executorType, contentType string, executors

return nil
}

func validateArtifactRequest(artifactStorageClassName, artifactVolumeMountPath string, artifactDirs []string) error {
if artifactStorageClassName != "" || artifactVolumeMountPath != "" || len(artifactDirs) != 0 {
if artifactStorageClassName == "" || artifactVolumeMountPath == "" {
return fmt.Errorf("both artifact storage class name and mount path should be provided")
}
}

return nil
}
Expand Up @@ -38,8 +38,12 @@ func ExecutionRenderer(ui *ui.UI, obj interface{}) error {

renderer.RenderVariables(execution.Variables)

if len(execution.Command) > 0 {
ui.Warn("Command: ", execution.Command...)
}

if len(execution.Args) > 0 {
ui.Warn("Args: ", execution.Args...)
ui.Warn("Args: ", execution.Args...)
}

if execution.Content != nil && execution.Content.Repository != nil {
Expand Down
5 changes: 5 additions & 0 deletions cmd/kubectl-testkube/commands/tests/renderer/test_obj.go
Expand Up @@ -84,9 +84,14 @@ func TestRenderer(ui *ui.UI, obj interface{}) error {
renderer.RenderVariables(test.ExecutionRequest.Variables)
}

if len(test.ExecutionRequest.Command) > 0 {
ui.Warn(" Command: ", test.ExecutionRequest.Command...)
}

if len(test.ExecutionRequest.Args) > 0 {
ui.Warn(" Args: ", test.ExecutionRequest.Args...)
}
ui.Warn(" Args mode: ", test.ExecutionRequest.ArgsMode)

if len(test.ExecutionRequest.Envs) > 0 {
ui.NL()
Expand Down
18 changes: 13 additions & 5 deletions cmd/kubectl-testkube/commands/tests/run.go
Expand Up @@ -57,6 +57,8 @@ func NewRunTestCmd() *cobra.Command {
format string
masks []string
runningContext string
command []string
argsMode string
)

cmd := &cobra.Command{
Expand All @@ -81,9 +83,6 @@ func NewRunTestCmd() *cobra.Command {
executorArgs, err := testkube.PrepareExecutorArgs(binaryArgs)
ui.ExitOnError("getting args", err)

err = validateArtifactRequest(artifactStorageClassName, artifactVolumeMountPath, artifactDirs)
ui.ExitOnError("validating artifact flags", err)

envConfigMaps, envSecrets, err := newEnvReferencesFromFlags(cmd)
ui.WarnOnError("getting env config maps and secrets", err)

Expand All @@ -108,13 +107,20 @@ func NewRunTestCmd() *cobra.Command {
scraperTemplateContent = string(b)
}

mode := ""
if cmd.Flag("args-mode").Changed {
mode = argsMode
}

var executions []testkube.Execution
client, namespace := common.GetClient(cmd)
options := apiv1.ExecuteTestOptions{
ExecutionVariables: variables,
ExecutionVariablesFileContent: paramsFileContent,
ExecutionLabels: executionLabels,
Command: command,
Args: executorArgs,
ArgsMode: mode,
SecretEnvs: secretEnvs,
HTTPProxy: httpProxy,
HTTPSProxy: httpsProxy,
Expand All @@ -132,7 +138,7 @@ func NewRunTestCmd() *cobra.Command {
},
}

if artifactStorageClassName != "" && artifactVolumeMountPath != "" {
if artifactStorageClassName != "" || artifactVolumeMountPath != "" || len(artifactDirs) != 0 {
options.ArtifactRequest = &testkube.ArtifactRequest{
StorageClassName: artifactStorageClassName,
VolumeMountPath: artifactVolumeMountPath,
Expand Down Expand Up @@ -243,7 +249,9 @@ func NewRunTestCmd() *cobra.Command {
cmd.Flags().StringVarP(&variablesFile, "variables-file", "", "", "variables file path, e.g. postman env file - will be passed to executor if supported")
cmd.Flags().StringToStringVarP(&variables, "variable", "v", map[string]string{}, "execution variable passed to executor")
cmd.Flags().StringToStringVarP(&secretVariables, "secret-variable", "s", map[string]string{}, "execution secret variable passed to executor")
cmd.Flags().StringArrayVar(&command, "command", []string{}, "command passed to image in executor")
cmd.Flags().StringArrayVarP(&binaryArgs, "args", "", []string{}, "executor binary additional arguments")
cmd.Flags().StringVarP(&argsMode, "args-mode", "", "append", "usage mode for argumnets. one of append|override")
cmd.Flags().BoolVarP(&watchEnabled, "watch", "f", false, "watch for changes after start")
cmd.Flags().StringVar(&downloadDir, "download-dir", "artifacts", "download dir")
cmd.Flags().BoolVarP(&downloadArtifactsEnabled, "download-artifacts", "d", false, "downlaod artifacts automatically")
Expand All @@ -259,7 +267,7 @@ func NewRunTestCmd() *cobra.Command {
cmd.Flags().StringArrayVarP(&copyFiles, "copy-files", "", []string{}, "file path mappings from host to pod of form source:destination")
cmd.Flags().StringVar(&artifactStorageClassName, "artifact-storage-class-name", "", "artifact storage class name for container executor")
cmd.Flags().StringVar(&artifactVolumeMountPath, "artifact-volume-mount-path", "", "artifact volume mount path for container executor")
cmd.Flags().StringArrayVarP(&artifactDirs, "artifact-dir", "", []string{}, "artifact dirs for container executor")
cmd.Flags().StringArrayVarP(&artifactDirs, "artifact-dir", "", []string{}, "artifact dirs for scraping")
cmd.Flags().StringVar(&jobTemplate, "job-template", "", "job template file path for extensions to job template")
cmd.Flags().StringVarP(&gitBranch, "git-branch", "", "", "if uri is git repository we can set additional branch parameter")
cmd.Flags().StringVarP(&gitCommit, "git-commit", "", "", "if uri is git repository we can use commit id (sha) parameter")
Expand Down

0 comments on commit 9ff44ab

Please sign in to comment.