Skip to content

Commit a64d83d

Browse files
authored
Add toolRegistry as a common field for the Client in the SDK (#5621)
1 parent b7ec95d commit a64d83d

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

pkg/plugin/sdk/client.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
"github.com/pipe-cd/pipecd/pkg/plugin/pipedapi"
2121
"github.com/pipe-cd/pipecd/pkg/plugin/pipedservice"
22+
"github.com/pipe-cd/pipecd/pkg/plugin/toolregistry"
2223
)
2324

2425
// Client is a toolkit for interacting with the piped service.
@@ -42,6 +43,10 @@ type Client struct {
4243
// logPersister is used to persist the stage logs.
4344
// This field exists only when the client is working with a specific stage; for example, when this client is passed as the ExecuteStage method's argument.
4445
logPersister StageLogPersister
46+
47+
// toolRegistry is used to install and get the path of the tools used in the plugin.
48+
// TODO: We should consider installing the tools in other way.
49+
toolRegistry *toolregistry.ToolRegistry
4550
}
4651

4752
// StageLogPersister is a interface for persisting the stage logs.
@@ -139,3 +144,9 @@ func (c *Client) GetDeploymentSharedMetadata(ctx context.Context, key string) (s
139144
func (c *Client) LogPersister() StageLogPersister {
140145
return c.logPersister
141146
}
147+
148+
// ToolRegistry returns the tool registry.
149+
// Use this to install and get the path of the tools used in the plugin.
150+
func (c *Client) ToolRegistry() *toolregistry.ToolRegistry {
151+
return c.toolRegistry
152+
}

pkg/plugin/sdk/deployment.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/pipe-cd/pipecd/pkg/plugin/logpersister"
3333
"github.com/pipe-cd/pipecd/pkg/plugin/pipedapi"
3434
"github.com/pipe-cd/pipecd/pkg/plugin/signalhandler"
35+
"github.com/pipe-cd/pipecd/pkg/plugin/toolregistry"
3536
)
3637

3738
var (
@@ -114,6 +115,7 @@ type commonFields struct {
114115
logger *zap.Logger
115116
logPersister logPersister
116117
client *pipedapi.PipedServiceClient
118+
toolRegistry *toolregistry.ToolRegistry
117119
}
118120

119121
// DeploymentPluginServiceServer is the gRPC server that handles requests from the piped.
@@ -205,6 +207,7 @@ func (s *DeploymentPluginServiceServer[Config, DeployTargetConfig]) ExecuteStage
205207
deploymentID: request.GetInput().GetDeployment().GetId(),
206208
stageID: request.GetInput().GetStage().GetId(),
207209
logPersister: lp,
210+
toolRegistry: s.toolRegistry,
208211
}
209212

210213
// Get the deploy targets set on the deployment from the piped plugin config.
@@ -308,6 +311,7 @@ func (s *StagePluginServiceServer[Config, DeployTargetConfig]) ExecuteStage(ctx
308311
deploymentID: request.GetInput().GetDeployment().GetId(),
309312
stageID: request.GetInput().GetStage().GetId(),
310313
logPersister: lp,
314+
toolRegistry: s.toolRegistry,
311315
}
312316

313317
return executeStage(ctx, s.base, &s.config, nil, client, request, s.logger) // TODO: pass the deployTargets

pkg/plugin/sdk/sdk.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
config "github.com/pipe-cd/pipecd/pkg/configv1"
3232
"github.com/pipe-cd/pipecd/pkg/plugin/logpersister"
3333
"github.com/pipe-cd/pipecd/pkg/plugin/pipedapi"
34+
"github.com/pipe-cd/pipecd/pkg/plugin/toolregistry"
3435
"github.com/pipe-cd/pipecd/pkg/rpc"
3536
)
3637

@@ -161,6 +162,7 @@ func (s *plugin) run(ctx context.Context, input cli.Input) (runErr error) {
161162
logger: input.Logger.Named("deployment-service"),
162163
logPersister: persister,
163164
client: pipedapiClient,
165+
toolRegistry: toolregistry.NewToolRegistry(pipedapiClient),
164166
})
165167
if err := deploymentServiceServer.setConfig(cfg.Config); err != nil {
166168
input.Logger.Error("failed to set configuration", zap.Error(err))

0 commit comments

Comments
 (0)