Skip to content

Commit

Permalink
fix: user friendly oss error
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io>
  • Loading branch information
vsukhin committed Jul 3, 2024
1 parent 5f734c4 commit a1aa8b6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
13 changes: 13 additions & 0 deletions cmd/kubectl-testkube/commands/testworkflows/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/kubeshop/testkube/cmd/testworkflow-init/data"
apiclientv1 "github.com/kubeshop/testkube/pkg/api/v1/client"
"github.com/kubeshop/testkube/pkg/api/v1/testkube"
"github.com/kubeshop/testkube/pkg/testworkflows/testworkflowprocessor/constants"
"github.com/kubeshop/testkube/pkg/ui"
)

Expand Down Expand Up @@ -69,6 +70,18 @@ func NewRunTestWorkflowCmd() *cobra.Command {
Config: config,
DisableWebhooks: disableWebhooks,
})
if err != nil {
errs := []error{constants.ErrOpenSourceExecuteOperationIsNotAvailable,
constants.ErrOpenSourceParallelOperationIsNotAvailable,
constants.ErrOpenSourceServicesOperationIsNotAvailable}
for _, e := range errs {
if strings.Contains(err.Error(), e.Error()) {
err = e
break
}
}
}

ui.ExitOnError("execute test workflow "+name+" from namespace "+namespace, err)
err = renderer.PrintTestWorkflowExecution(cmd, os.Stdout, execution)
ui.ExitOnError("render test workflow execution", err)
Expand Down
27 changes: 16 additions & 11 deletions pkg/testworkflows/testworkflowprocessor/constants/constants.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package constants

import (
"errors"
"fmt"
"os"
"path/filepath"
Expand All @@ -14,15 +15,16 @@ import (
)

const (
DefaultInternalPath = "/.tktw"
DefaultDataPath = "/data"
DefaultTerminationLogPath = "/dev/termination-log"
DefaultFsGroup = int64(1001)
ResourceIdLabelName = "testworkflowid"
RootResourceIdLabelName = "testworkflowid-root"
GroupIdLabelName = "testworkflowid-group"
SignatureAnnotationName = "testworkflows.testkube.io/signature"
RFC3339Millis = "2006-01-02T15:04:05.000Z07:00"
DefaultInternalPath = "/.tktw"
DefaultDataPath = "/data"
DefaultTerminationLogPath = "/dev/termination-log"
DefaultFsGroup = int64(1001)
ResourceIdLabelName = "testworkflowid"
RootResourceIdLabelName = "testworkflowid-root"
GroupIdLabelName = "testworkflowid-group"
SignatureAnnotationName = "testworkflows.testkube.io/signature"
RFC3339Millis = "2006-01-02T15:04:05.000Z07:00"
OpenSourceOperationErrorMessage = "operation is not available when running the Testkube Agent in the standalone mode"
)

var (
Expand Down Expand Up @@ -66,8 +68,11 @@ echo -n ',0' > <terminationLog> && echo 'Done.' && exit 0
{Name: "CI", Value: "1"},
},
}
DefaultInitImage = getInitImage()
DefaultToolkitImage = getToolkitImage()
DefaultInitImage = getInitImage()
DefaultToolkitImage = getToolkitImage()
ErrOpenSourceExecuteOperationIsNotAvailable = errors.New(`"execute" ` + OpenSourceOperationErrorMessage)
ErrOpenSourceParallelOperationIsNotAvailable = errors.New(`"parallel" ` + OpenSourceOperationErrorMessage)
ErrOpenSourceServicesOperationIsNotAvailable = errors.New(`"services" ` + OpenSourceOperationErrorMessage)
)

func stripCommonImagePrefix(image, common string) string {
Expand Down
6 changes: 3 additions & 3 deletions pkg/testworkflows/testworkflowprocessor/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,21 +303,21 @@ func ProcessArtifacts(_ InternalProcessor, layer Intermediate, container Contain

func StubExecute(_ InternalProcessor, _ Intermediate, _ Container, step testworkflowsv1.Step) (Stage, error) {
if step.Execute != nil {
return nil, errors.New(`"execute" operation is not available when running the Testkube Agent in the standalone mode`)
return nil, constants.ErrOpenSourceExecuteOperationIsNotAvailable
}
return nil, nil
}

func StubParallel(_ InternalProcessor, _ Intermediate, _ Container, step testworkflowsv1.Step) (Stage, error) {
if step.Parallel != nil {
return nil, errors.New(`"parallel" operation is not available when running the Testkube Agent in the standalone mode`)
return nil, constants.ErrOpenSourceParallelOperationIsNotAvailable
}
return nil, nil
}

func StubServices(_ InternalProcessor, _ Intermediate, _ Container, step testworkflowsv1.Step) (Stage, error) {
if len(step.Services) != 0 {
return nil, errors.New(`"services" are not available when running the Testkube Agent in the standalone mode`)
return nil, constants.ErrOpenSourceServicesOperationIsNotAvailable
}
return nil, nil
}

0 comments on commit a1aa8b6

Please sign in to comment.