diff --git a/contrib/executor/init/pkg/runner/runner.go b/contrib/executor/init/pkg/runner/runner.go index 23b90f6e39d..64ad407cf77 100755 --- a/contrib/executor/init/pkg/runner/runner.go +++ b/contrib/executor/init/pkg/runner/runner.go @@ -83,8 +83,13 @@ func (r *InitRunner) Run(ctx context.Context, execution testkube.Execution) (res output.PrintLogf("%s Could not chmod for data dir: %s", ui.IconCross, err.Error()) } - if execution.ArtifactRequest != nil && execution.ArtifactRequest.VolumeMountPath != "" { - _, err = executor.Run(execution.ArtifactRequest.VolumeMountPath, "chmod", nil, []string{"-R", "777", "."}...) + if execution.ArtifactRequest != nil { + mountPath := filepath.Join(r.Params.DataDir, "artifacts") + if execution.ArtifactRequest.VolumeMountPath != "" { + mountPath = execution.ArtifactRequest.VolumeMountPath + } + + _, err = executor.Run(mountPath, "chmod", nil, []string{"-R", "777", "."}...) if err != nil { output.PrintLogf("%s Could not chmod for artifacts dir: %s", ui.IconCross, err.Error()) } diff --git a/contrib/executor/scraper/pkg/runner/runner.go b/contrib/executor/scraper/pkg/runner/runner.go index 31ac1736e91..4df3b5f7980 100644 --- a/contrib/executor/scraper/pkg/runner/runner.go +++ b/contrib/executor/scraper/pkg/runner/runner.go @@ -49,11 +49,16 @@ func (r *ScraperRunner) Run(ctx context.Context, execution testkube.Execution) ( return *result.Err(errors.Errorf("executor only support artifact based tests")), nil } - if execution.ArtifactRequest.VolumeMountPath == "" || execution.ArtifactRequest.StorageClassName == "" { - return *result.Err(errors.Errorf("artifact request should have not empty volume mount path and storage class name")), nil + if execution.ArtifactRequest.StorageClassName == "" { + return *result.Err(errors.Errorf("artifact request should have not empty storage class name")), nil } - _, err = os.Stat(execution.ArtifactRequest.VolumeMountPath) + mountPath := filepath.Join(r.Params.DataDir, "artifacts") + if execution.ArtifactRequest.VolumeMountPath != "" { + mountPath = execution.ArtifactRequest.VolumeMountPath + } + + _, err = os.Stat(mountPath) if errors.Is(err, os.ErrNotExist) { return result, err } @@ -65,7 +70,7 @@ func (r *ScraperRunner) Run(ctx context.Context, execution testkube.Execution) ( } for i := range directories { - directories[i] = filepath.Join(execution.ArtifactRequest.VolumeMountPath, directories[i]) + directories[i] = filepath.Join(mountPath, directories[i]) } output.PrintLog(fmt.Sprintf("Scraping directories: %v", directories)) diff --git a/docs/docs/test-types/container-executor.mdx b/docs/docs/test-types/container-executor.mdx index 811f2c2c16f..4ef8f706f89 100644 --- a/docs/docs/test-types/container-executor.mdx +++ b/docs/docs/test-types/container-executor.mdx @@ -323,6 +323,7 @@ spec: ``` You have to define the storage class name, volume mount path and directories in this volume with test artifacts. +Default volume mount path is `/data/artifacts` and directory is `.` . Make sure your container executor definition has `artifacts` feature. For example: ```yaml diff --git a/pkg/executor/client/job.go b/pkg/executor/client/job.go index a2d93f6e335..e9c6fe6046e 100644 --- a/pkg/executor/client/job.go +++ b/pkg/executor/client/job.go @@ -58,7 +58,6 @@ const ( pollTimeout = 24 * time.Hour pollInterval = 200 * time.Millisecond - volumeDir = "/data" // pollJobStatus is interval for checking if job timeout occurred pollJobStatus = 1 * time.Second // timeoutIndicator is string that is added to job logs when timeout occurs diff --git a/pkg/executor/common.go b/pkg/executor/common.go index 24afb40241b..17ac6d49d21 100644 --- a/pkg/executor/common.go +++ b/pkg/executor/common.go @@ -28,6 +28,8 @@ import ( var ErrPodInitializing = errors.New("PodInitializing") const ( + // VolumeDir is volume dir + VolumeDir = "/data" defaultLogLinesCount = 100 // GitUsernameSecretName is git username secret name GitUsernameSecretName = "git-username" @@ -74,7 +76,7 @@ var RunnerEnvVars = []corev1.EnvVar{ }, { Name: "RUNNER_DATADIR", - Value: "/data", + Value: VolumeDir, }, { Name: "RUNNER_CDEVENTS_TARGET", diff --git a/pkg/executor/containerexecutor/containerexecutor.go b/pkg/executor/containerexecutor/containerexecutor.go index 55c56c4dbe0..6534944f5bf 100644 --- a/pkg/executor/containerexecutor/containerexecutor.go +++ b/pkg/executor/containerexecutor/containerexecutor.go @@ -178,7 +178,7 @@ func (c *ContainerExecutor) Logs(ctx context.Context, id string) (out chan outpu ids := []string{id} if supportArtifacts && execution.ArtifactRequest != nil && - execution.ArtifactRequest.VolumeMountPath != "" && execution.ArtifactRequest.StorageClassName != "" { + execution.ArtifactRequest.StorageClassName != "" { ids = append(ids, id+"-scraper") } @@ -285,7 +285,7 @@ func (c *ContainerExecutor) createJob(ctx context.Context, execution testkube.Ex } if jobOptions.ArtifactRequest != nil && - jobOptions.ArtifactRequest.VolumeMountPath != "" && jobOptions.ArtifactRequest.StorageClassName != "" { + jobOptions.ArtifactRequest.StorageClassName != "" { c.log.Debug("creating persistent volume claim with options", "options", jobOptions) pvcsClient := c.clientSet.CoreV1().PersistentVolumeClaims(c.namespace) pvcSpec, err := NewPersistentVolumeClaimSpec(c.log, jobOptions) @@ -344,7 +344,7 @@ func (c *ContainerExecutor) updateResultsFromPod( var scraperLogs []byte if jobOptions.ArtifactRequest != nil && - jobOptions.ArtifactRequest.VolumeMountPath != "" && jobOptions.ArtifactRequest.StorageClassName != "" { + jobOptions.ArtifactRequest.StorageClassName != "" { c.log.Debug("creating scraper job with options", "options", jobOptions) jobsClient := c.clientSet.BatchV1().Jobs(c.namespace) scraperSpec, err := NewScraperJobSpec(c.log, jobOptions) diff --git a/pkg/scheduler/test_scheduler.go b/pkg/scheduler/test_scheduler.go index c9a828b2da3..9b5ff165e96 100644 --- a/pkg/scheduler/test_scheduler.go +++ b/pkg/scheduler/test_scheduler.go @@ -3,18 +3,17 @@ package scheduler import ( "context" "fmt" - - v1 "k8s.io/api/core/v1" - - testsourcev1 "github.com/kubeshop/testkube-operator/apis/testsource/v1" + "path/filepath" "github.com/pkg/errors" + v1 "k8s.io/api/core/v1" testsv3 "github.com/kubeshop/testkube-operator/apis/tests/v3" + testsourcev1 "github.com/kubeshop/testkube-operator/apis/testsource/v1" "github.com/kubeshop/testkube/internal/common" "github.com/kubeshop/testkube/pkg/api/v1/testkube" + "github.com/kubeshop/testkube/pkg/executor" "github.com/kubeshop/testkube/pkg/executor/client" - testsmapper "github.com/kubeshop/testkube/pkg/mapper/tests" "github.com/kubeshop/testkube/pkg/workerpool" ) @@ -322,6 +321,9 @@ func (s *Scheduler) getExecuteOptions(namespace, id string, request testkube.Exe } request.ArtifactRequest = mergeArtifacts(request.ArtifactRequest, test.ExecutionRequest.ArtifactRequest) + if request.ArtifactRequest != nil && request.ArtifactRequest.VolumeMountPath == "" { + request.ArtifactRequest.VolumeMountPath = filepath.Join(executor.VolumeDir, "artifacts") + } s.logger.Infow("checking for negative test change", "test", test.Name, "negativeTest", request.NegativeTest, "isNegativeTestChangedOnRun", request.IsNegativeTestChangedOnRun) if !request.IsNegativeTestChangedOnRun {