Skip to content

Commit

Permalink
fix: make the Cloud connection from the Init Process lazy (connect on…
Browse files Browse the repository at this point in the history
…ly when actually needed) (#6062)
  • Loading branch information
rangoo94 authored Dec 2, 2024
1 parent f1fd9b6 commit bcabeae
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
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

0 comments on commit bcabeae

Please sign in to comment.