Skip to content

Commit

Permalink
add support for cloud capabilities (#5398)
Browse files Browse the repository at this point in the history
  • Loading branch information
dejanzele authored May 8, 2024
1 parent cef0142 commit 6031cb6
Show file tree
Hide file tree
Showing 6 changed files with 260 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func newArtifactUploader() Uploader {
if env.CloudEnabled() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
client := env.Cloud(ctx)
client, _ := env.Cloud(ctx)
return NewCloudUploader(client, WithParallelismCloud(30), CloudDetectMimetype)
}
return NewDirectUploader(WithParallelism(30), DirectDetectMimetype)
Expand Down
28 changes: 22 additions & 6 deletions cmd/tcl/testworkflow-toolkit/commands/artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ import (
"strings"
"time"

"google.golang.org/protobuf/types/known/emptypb"

"github.com/kubeshop/testkube/pkg/agent"
"github.com/kubeshop/testkube/pkg/capabilities"
"github.com/kubeshop/testkube/pkg/cloud"

"github.com/kubeshop/testkube/pkg/filesystem"

"github.com/minio/minio-go/v7"
Expand Down Expand Up @@ -102,10 +108,20 @@ func NewArtifactsCmd() *cobra.Command {
if env.CloudEnabled() {
ctx, cancel := context.WithTimeout(cmd.Context(), 30*time.Second)
defer cancel()
client := env.Cloud(ctx)
defer client.Close()
if env.JUnitParserEnabled() {
junitProcessor := artifacts.NewJUnitPostProcessor(filesystem.NewOSFileSystem(), client)
ctx = agent.AddAPIKeyMeta(ctx, env.Config().Cloud.ApiKey)
executor, client := env.Cloud(ctx)
proContext, err := client.GetProContext(ctx, &emptypb.Empty{})
var supported []*cloud.Capability
if err != nil {
fmt.Printf("Warning: couldn't get capabilities: %s\n", err.Error())
}
if proContext != nil {
supported = proContext.Capabilities
}
defer executor.Close()

if env.JUnitParserEnabled() || capabilities.Enabled(supported, capabilities.CapabilityJUnitReports) {
junitProcessor := artifacts.NewJUnitPostProcessor(filesystem.NewOSFileSystem(), executor)
handlerOpts = append(handlerOpts, artifacts.WithPostProcessor(junitProcessor))
}
if compress != "" {
Expand All @@ -114,10 +130,10 @@ func NewArtifactsCmd() *cobra.Command {
if unpack {
opts = append(opts, cloudUnpack)
}
uploader = artifacts.NewCloudUploader(client, opts...)
uploader = artifacts.NewCloudUploader(executor, opts...)
} else {
processor = artifacts.NewDirectProcessor()
uploader = artifacts.NewCloudUploader(client, artifacts.WithParallelismCloud(30), artifacts.CloudDetectMimetype)
uploader = artifacts.NewCloudUploader(executor, artifacts.WithParallelismCloud(30), artifacts.CloudDetectMimetype)
}
} else if compress != "" && unpack {
processor = artifacts.NewTarCachedProcessor(compress, compressCachePath)
Expand Down
4 changes: 2 additions & 2 deletions cmd/tcl/testworkflow-toolkit/env/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ func ObjectStorageClient() (*minio.Client, error) {
return c, c.Connect()
}

func Cloud(ctx context.Context) cloudexecutor.Executor {
func Cloud(ctx context.Context) (cloudexecutor.Executor, cloud.TestKubeCloudAPIClient) {
cfg := Config().Cloud
grpcConn, err := agent.NewGRPCConnection(ctx, cfg.TlsInsecure, cfg.SkipVerify, cfg.Url, "", "", "", log.DefaultLogger)
if err != nil {
ui.Fail(fmt.Errorf("failed to connect with Cloud: %w", err))
}
grpcClient := cloud.NewTestKubeCloudAPIClient(grpcConn)
return cloudexecutor.NewCloudGRPCExecutor(grpcClient, grpcConn, cfg.ApiKey)
return cloudexecutor.NewCloudGRPCExecutor(grpcClient, grpcConn, cfg.ApiKey), grpcClient
}
16 changes: 16 additions & 0 deletions pkg/capabilities/capabilities.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package capabilities

import "github.com/kubeshop/testkube/pkg/cloud"

type Capability string

const CapabilityJUnitReports Capability = "junit-reports"

func Enabled(capabilities []*cloud.Capability, capability Capability) bool {
for _, c := range capabilities {
if c.Name == string(capability) {
return c.Enabled
}
}
return false
}
Loading

0 comments on commit 6031cb6

Please sign in to comment.