From bcabeae81942fcf4d6ac138ffefd55e687ff51c5 Mon Sep 17 00:00:00 2001 From: Dawid Rusnak Date: Mon, 2 Dec 2024 10:05:53 +0100 Subject: [PATCH] fix: make the Cloud connection from the Init Process lazy (connect only when actually needed) (#6062) --- cmd/testworkflow-init/data/client.go | 2 +- pkg/credentials/repository.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/testworkflow-init/data/client.go b/cmd/testworkflow-init/data/client.go index 733b7666d1..03dbf050d2 100644 --- a/cmd/testworkflow-init/data/client.go +++ b/cmd/testworkflow-init/data/client.go @@ -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) } diff --git a/pkg/credentials/repository.go b/pkg/credentials/repository.go index 65f568a2c3..4b3c8dd18d 100644 --- a/pkg/credentials/repository.go +++ b/pkg/credentials/repository.go @@ -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 }