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: default artifacts dir #3905

Merged
merged 4 commits into from
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 7 additions & 2 deletions contrib/executor/init/pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
13 changes: 9 additions & 4 deletions contrib/executor/scraper/pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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))
Expand Down
1 change: 1 addition & 0 deletions docs/docs/test-types/container-executor.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion pkg/executor/client/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion pkg/executor/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -74,7 +76,7 @@ var RunnerEnvVars = []corev1.EnvVar{
},
{
Name: "RUNNER_DATADIR",
Value: "/data",
Value: VolumeDir,
},
{
Name: "RUNNER_CDEVENTS_TARGET",
Expand Down
6 changes: 3 additions & 3 deletions pkg/executor/containerexecutor/containerexecutor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions pkg/scheduler/test_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down