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

fix: add timeout to grpc conn #4107

Merged
merged 6 commits into from
Jun 30, 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
38 changes: 20 additions & 18 deletions pkg/envs/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,25 @@ import (

// Params are the environment variables provided by the Testkube api-server
type Params struct {
Endpoint string // RUNNER_ENDPOINT
AccessKeyID string // RUNNER_ACCESSKEYID
SecretAccessKey string // RUNNER_SECRETACCESSKEY
Region string // RUNNER_REGION
Token string // RUNNER_TOKEN
Bucket string // RUNNER_BUCKET
Ssl bool // RUNNER_SSL
ScrapperEnabled bool // RUNNER_SCRAPPERENABLED
DataDir string // RUNNER_DATADIR
GitUsername string // RUNNER_GITUSERNAME
GitToken string // RUNNER_GITTOKEN
ClusterID string `envconfig:"RUNNER_CLUSTERID"` // RUNNER_CLUSTERID
CDEventsTarget string `envconfig:"RUNNER_CDEVENTS_TARGET"` // RUNNER_CDEVENTS_TARGET
DashboardURI string `envconfig:"RUNNER_DASHBOARD_URI"` // RUNNER_DASHBOARD_URI
CloudMode bool `envconfig:"RUNNER_CLOUD_MODE"` // RUNNER_CLOUD_MODE
CloudAPIKey string `envconfig:"RUNNER_CLOUD_API_KEY"` // RUNNER_CLOUD_API_KEY
CloudAPITLSInsecure bool `envconfig:"RUNNER_CLOUD_API_TLS_INSECURE"` // RUNNER_CLOUD_API_TLS_INSECURE
CloudAPIURL string `envconfig:"RUNNER_CLOUD_API_URL"` // RUNNER_CLOUD_API_URL
Endpoint string // RUNNER_ENDPOINT
AccessKeyID string // RUNNER_ACCESSKEYID
SecretAccessKey string // RUNNER_SECRETACCESSKEY
Region string // RUNNER_REGION
Token string // RUNNER_TOKEN
Bucket string // RUNNER_BUCKET
Ssl bool // RUNNER_SSL
ScrapperEnabled bool // RUNNER_SCRAPPERENABLED
DataDir string // RUNNER_DATADIR
GitUsername string // RUNNER_GITUSERNAME
GitToken string // RUNNER_GITTOKEN
ClusterID string `envconfig:"RUNNER_CLUSTERID"` // RUNNER_CLUSTERID
CDEventsTarget string `envconfig:"RUNNER_CDEVENTS_TARGET"` // RUNNER_CDEVENTS_TARGET
DashboardURI string `envconfig:"RUNNER_DASHBOARD_URI"` // RUNNER_DASHBOARD_URI
CloudMode bool `envconfig:"RUNNER_CLOUD_MODE"` // RUNNER_CLOUD_MODE
CloudAPIKey string `envconfig:"RUNNER_CLOUD_API_KEY"` // RUNNER_CLOUD_API_KEY
CloudAPITLSInsecure bool `envconfig:"RUNNER_CLOUD_API_TLS_INSECURE"` // RUNNER_CLOUD_API_TLS_INSECURE
CloudAPIURL string `envconfig:"RUNNER_CLOUD_API_URL"` // RUNNER_CLOUD_API_URL
CloudConnectionTimeoutSec int `envconfig:"RUNNER_CLOUD_CONNECTION_TIMEOUT" default:"10"` // RUNNER_CLOUD_CONNECTION_TIMEOUT
}

// LoadTestkubeVariables loads the parameters provided as environment variables in the Test CRD
Expand Down Expand Up @@ -66,6 +67,7 @@ func printParams(params Params) {
output.PrintLogf("RUNNER_CLOUD_API_TLS_INSECURE=\"%t\"", params.CloudAPITLSInsecure)
output.PrintLogf("RUNNER_CLOUD_API_URL=\"%s\"", params.CloudAPIURL)
printSensitiveParam("RUNNER_CLOUD_API_KEY", params.CloudAPIKey)
output.PrintLogf("RUNNER_CLOUD_CONNECTION_TIMEOUT=%d", params.CloudConnectionTimeoutSec)
}

// printSensitiveParam shows in logs if a parameter is set or not
Expand Down
9 changes: 7 additions & 2 deletions pkg/executor/scraper/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package factory
import (
"context"
"fmt"
"time"

cloudevents "github.com/cloudevents/sdk-go/v2"
"github.com/pkg/errors"
Expand Down Expand Up @@ -89,12 +90,16 @@ func GetScraper(ctx context.Context, params envs.Params, extractorType Extractor
}

func getCloudLoader(ctx context.Context, params envs.Params) (uploader *cloudscraper.CloudUploader, err error) {
output.PrintLog(fmt.Sprintf("%s Uploading artifacts using Cloud Uploader", ui.IconCheckMark))
// timeout blocking connection to cloud
ctxTimeout, cancel := context.WithTimeout(ctx, time.Duration(params.CloudConnectionTimeoutSec)*time.Second)
defer cancel()

grpcConn, err := agent.NewGRPCConnection(ctx, params.CloudAPITLSInsecure, params.CloudAPIURL, log.DefaultLogger)
output.PrintLogf("%s Uploading artifacts using Cloud Uploader (timeout:%ds)", ui.IconCheckMark, params.CloudConnectionTimeoutSec)
grpcConn, err := agent.NewGRPCConnection(ctxTimeout, params.CloudAPITLSInsecure, params.CloudAPIURL, log.DefaultLogger)
if err != nil {
return nil, err
}
output.PrintLogf("%s Connected to Testkube Cloud", ui.IconCheckMark)

grpcClient := cloud.NewTestKubeCloudAPIClient(grpcConn)
cloudExecutor := cloudexecutor.NewCloudGRPCExecutor(grpcClient, grpcConn, params.CloudAPIKey)
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/test_scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestGetExecuteOptions(t *testing.T) {
ExecutionLabels: map[string]string{"label": "value"},
Namespace: "namespace",
VariablesFile: "",
Variables: map[string]testkube.Variable{"var": testkube.Variable{Name: "one"}},
Variables: map[string]testkube.Variable{"var": {Name: "one"}},
Command: []string{"run"},
Args: []string{},
ArgsMode: "",
Expand Down