Skip to content

Add toolRegistry as a common field for the Client in the SDK #5621

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

Merged
merged 2 commits into from
Mar 5, 2025
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
11 changes: 11 additions & 0 deletions pkg/plugin/sdk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

"github.com/pipe-cd/pipecd/pkg/plugin/pipedapi"
"github.com/pipe-cd/pipecd/pkg/plugin/pipedservice"
"github.com/pipe-cd/pipecd/pkg/plugin/toolregistry"
)

// Client is a toolkit for interacting with the piped service.
Expand All @@ -42,6 +43,10 @@
// logPersister is used to persist the stage logs.
// 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.
logPersister StageLogPersister

// toolRegistry is used to install and get the path of the tools used in the plugin.
// TODO: We should consider installing the tools in other way.
toolRegistry *toolregistry.ToolRegistry
}

// StageLogPersister is a interface for persisting the stage logs.
Expand Down Expand Up @@ -139,3 +144,9 @@
func (c *Client) LogPersister() StageLogPersister {
return c.logPersister
}

// ToolRegistry returns the tool registry.
// Use this to install and get the path of the tools used in the plugin.
func (c *Client) ToolRegistry() *toolregistry.ToolRegistry {
return c.toolRegistry

Check warning on line 151 in pkg/plugin/sdk/client.go

View check run for this annotation

Codecov / codecov/patch

pkg/plugin/sdk/client.go#L150-L151

Added lines #L150 - L151 were not covered by tests
}
4 changes: 4 additions & 0 deletions pkg/plugin/sdk/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"github.com/pipe-cd/pipecd/pkg/plugin/logpersister"
"github.com/pipe-cd/pipecd/pkg/plugin/pipedapi"
"github.com/pipe-cd/pipecd/pkg/plugin/signalhandler"
"github.com/pipe-cd/pipecd/pkg/plugin/toolregistry"
)

var (
Expand Down Expand Up @@ -114,6 +115,7 @@
logger *zap.Logger
logPersister logPersister
client *pipedapi.PipedServiceClient
toolRegistry *toolregistry.ToolRegistry
}

// DeploymentPluginServiceServer is the gRPC server that handles requests from the piped.
Expand Down Expand Up @@ -205,6 +207,7 @@
deploymentID: request.GetInput().GetDeployment().GetId(),
stageID: request.GetInput().GetStage().GetId(),
logPersister: lp,
toolRegistry: s.toolRegistry,

Check warning on line 210 in pkg/plugin/sdk/deployment.go

View check run for this annotation

Codecov / codecov/patch

pkg/plugin/sdk/deployment.go#L210

Added line #L210 was not covered by tests
}

// Get the deploy targets set on the deployment from the piped plugin config.
Expand Down Expand Up @@ -308,6 +311,7 @@
deploymentID: request.GetInput().GetDeployment().GetId(),
stageID: request.GetInput().GetStage().GetId(),
logPersister: lp,
toolRegistry: s.toolRegistry,
}

return executeStage(ctx, s.base, &s.config, nil, client, request, s.logger) // TODO: pass the deployTargets
Expand Down
2 changes: 2 additions & 0 deletions pkg/plugin/sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
config "github.com/pipe-cd/pipecd/pkg/configv1"
"github.com/pipe-cd/pipecd/pkg/plugin/logpersister"
"github.com/pipe-cd/pipecd/pkg/plugin/pipedapi"
"github.com/pipe-cd/pipecd/pkg/plugin/toolregistry"
"github.com/pipe-cd/pipecd/pkg/rpc"
)

Expand Down Expand Up @@ -161,6 +162,7 @@
logger: input.Logger.Named("deployment-service"),
logPersister: persister,
client: pipedapiClient,
toolRegistry: toolregistry.NewToolRegistry(pipedapiClient),

Check warning on line 165 in pkg/plugin/sdk/sdk.go

View check run for this annotation

Codecov / codecov/patch

pkg/plugin/sdk/sdk.go#L165

Added line #L165 was not covered by tests
})
if err := deploymentServiceServer.setConfig(cfg.Config); err != nil {
input.Logger.Error("failed to set configuration", zap.Error(err))
Expand Down