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: make the Cloud connection from the Init Process lazy (connect only when needed) #6062

Merged
merged 1 commit into from
Dec 2, 2024
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
2 changes: 1 addition & 1 deletion cmd/testworkflow-init/data/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ func CloudClient() cloud.TestKubeCloudAPIClient {

func Credentials() credentials.CredentialRepository {
cfg := GetState().InternalConfig
return credentials.NewCredentialRepository(CloudClient(), cfg.Worker.Connection.ApiKey, cfg.Execution.Id)
return credentials.NewCredentialRepository(CloudClient, cfg.Worker.Connection.ApiKey, cfg.Execution.Id)
}
8 changes: 4 additions & 4 deletions pkg/credentials/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ type CredentialRepository interface {
}

type credentialRepository struct {
client cloud.TestKubeCloudAPIClient
getClient func() cloud.TestKubeCloudAPIClient
apiKey string
executionId string
}

func NewCredentialRepository(client cloud.TestKubeCloudAPIClient, apiKey, executionId string) CredentialRepository {
return &credentialRepository{client: client, apiKey: apiKey, executionId: executionId}
func NewCredentialRepository(getClient func() cloud.TestKubeCloudAPIClient, apiKey, executionId string) CredentialRepository {
return &credentialRepository{getClient: getClient, apiKey: apiKey, executionId: executionId}
}

func (c *credentialRepository) Get(ctx context.Context, name string) ([]byte, error) {
ctx = agentclient.AddAPIKeyMeta(ctx, c.apiKey)
opts := []grpc.CallOption{grpc.UseCompressor(gzip.Name), grpc.MaxCallRecvMsgSize(math.MaxInt32)}
result, err := c.client.GetCredential(ctx, &cloud.CredentialRequest{Name: name, ExecutionId: c.executionId}, opts...)
result, err := c.getClient().GetCredential(ctx, &cloud.CredentialRequest{Name: name, ExecutionId: c.executionId}, opts...)
if err != nil {
return nil, err
}
Expand Down
Loading