-
Notifications
You must be signed in to change notification settings - Fork 157
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
Prepare Plugin SDK #5529
Merged
Merged
Prepare Plugin SDK #5529
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b0aae52
Add initial implementation of pipedsdk for PipeCD plugins
Warashi e71e92c
Implement pipedsdk client and deployment plugin interfaces
Warashi b3d0b1b
Add version support and common fields to deployment and pipeline sync…
Warashi cb7f67a
Refactor pipedsdk deployment and sdk packages for improved code organ…
Warashi 7c84fb3
Enhance pipedsdk client and deployment plugin interfaces with additio…
Warashi 55e13dd
Update piped-plugin-service flag description for clarity
Warashi 337e8c8
Add clarification to DeploymentPlugin interface regarding Config para…
Warashi 3cc9a8d
Apply suggestions from code review
Warashi 178b0b2
Fix build
Warashi e6ebd92
Update copyright notice year
Warashi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2025 The PipeCD Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package pipedsdk | ||
|
||
import "github.com/pipe-cd/pipecd/pkg/plugin/pipedapi" | ||
|
||
// Client is a toolkit for interacting with the piped service. | ||
// It provides methods to call the piped service APIs. | ||
// It's a wrapper around the raw piped service client. | ||
type Client struct { | ||
base *pipedapi.PipedServiceClient | ||
|
||
// applicationID is used to identify the application that the client is working with. | ||
applicationID string | ||
// deploymentID is used to identify the deployment that the client is working with. | ||
// This field exists only when the client is working with a specific deployment; for example, when this client is passed as the deployoment plugin's argument. | ||
deploymentID string | ||
// stageID is used to identify the stage that the client is working with. | ||
// 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. | ||
stageID string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
// Copyright 2025 The PipeCD Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package pipedsdk | ||
|
||
import ( | ||
"context" | ||
|
||
"go.uber.org/zap" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
|
||
config "github.com/pipe-cd/pipecd/pkg/configv1" | ||
"github.com/pipe-cd/pipecd/pkg/plugin/api/v1alpha1/deployment" | ||
"github.com/pipe-cd/pipecd/pkg/plugin/logpersister" | ||
"github.com/pipe-cd/pipecd/pkg/plugin/pipedapi" | ||
) | ||
|
||
var ( | ||
deploymentServiceServer interface { | ||
Plugin | ||
|
||
Register(server *grpc.Server) | ||
setCommonFields(commonFields) | ||
deployment.DeploymentServiceServer | ||
} | ||
) | ||
|
||
// DeploymentPlugin is the interface that be implemented by a full-spec deployment plugin. | ||
// This kind of plugin should implement all methods to manage resources and execute stages. | ||
// The Config parameter is the plugin's config defined in piped's config. | ||
type DeploymentPlugin[Config any] interface { | ||
PipelineSyncPlugin[Config] | ||
|
||
// DetermineVersions determines the versions of the resources that will be deployed. | ||
DetermineVersions(context.Context, *Config, *Client, TODO) (TODO, error) | ||
// DetermineStrategy determines the strategy to deploy the resources. | ||
DetermineStrategy(context.Context, *Config, *Client, TODO) (TODO, error) | ||
// BuildQuickSyncStages builds the stages that will be executed during the quick sync process. | ||
BuildQuickSyncStages(context.Context, *Config, *Client, TODO) (TODO, error) | ||
} | ||
|
||
// PipelineSyncPlugin is the interface implemented by a pipeline sync plugin. | ||
// This kind of plugin may not implement quick sync stages, and will not manage resources like deployment plugin. | ||
// It only focuses on executing stages which is generic for all kinds of pipeline sync plugins. | ||
type PipelineSyncPlugin[Config any] interface { | ||
Plugin | ||
|
||
// FetchDefinedStages returns the list of stages that the plugin can execute. | ||
FetchDefinedStages() []string | ||
// BuildPipelineSyncStages builds the stages that will be executed by the plugin. | ||
BuildPipelineSyncStages(context.Context, *Config, *Client, TODO) (TODO, error) | ||
// ExecuteStage executes the given stage. | ||
ExecuteStage(context.Context, *Config, *Client, logpersister.StageLogPersister, TODO) (TODO, error) | ||
} | ||
|
||
// RegisterDeploymentPlugin registers the given deployment plugin. | ||
// It will be used when running the piped. | ||
func RegisterDeploymentPlugin[Config any](plugin DeploymentPlugin[Config]) { | ||
deploymentServiceServer = &DeploymentPluginServiceServer[Config]{base: plugin} | ||
} | ||
|
||
// RegisterPipelineSyncPlugin registers the given pipeline sync plugin. | ||
// It will be used when running the piped. | ||
func RegisterPipelineSyncPlugin[Config any](plugin PipelineSyncPlugin[Config]) { | ||
deploymentServiceServer = &PipelineSyncPluginServiceServer[Config]{base: plugin} | ||
} | ||
|
||
type logPersister interface { | ||
StageLogPersister(deploymentID, stageID string) logpersister.StageLogPersister | ||
} | ||
|
||
type commonFields struct { | ||
config *config.PipedPlugin | ||
logger *zap.Logger | ||
logPersister logPersister | ||
client *pipedapi.PipedServiceClient | ||
} | ||
|
||
// DeploymentPluginServiceServer is the gRPC server that handles requests from the piped. | ||
type DeploymentPluginServiceServer[Config any] struct { | ||
deployment.UnimplementedDeploymentServiceServer | ||
commonFields | ||
|
||
base DeploymentPlugin[Config] | ||
} | ||
|
||
// Name returns the name of the plugin. | ||
func (s *DeploymentPluginServiceServer[Config]) Name() string { | ||
return s.base.Name() | ||
} | ||
|
||
func (s *DeploymentPluginServiceServer[Config]) Version() string { | ||
return s.base.Version() | ||
} | ||
|
||
// Register registers the server to the given gRPC server. | ||
func (s *DeploymentPluginServiceServer[Config]) Register(server *grpc.Server) { | ||
deployment.RegisterDeploymentServiceServer(server, s) | ||
} | ||
|
||
func (s *DeploymentPluginServiceServer[Config]) setCommonFields(fields commonFields) { | ||
s.commonFields = fields | ||
} | ||
|
||
func (s *DeploymentPluginServiceServer[Config]) FetchDefinedStages(context.Context, *deployment.FetchDefinedStagesRequest) (*deployment.FetchDefinedStagesResponse, error) { | ||
return &deployment.FetchDefinedStagesResponse{Stages: s.base.FetchDefinedStages()}, nil | ||
} | ||
func (s *DeploymentPluginServiceServer[Config]) DetermineVersions(context.Context, *deployment.DetermineVersionsRequest) (*deployment.DetermineVersionsResponse, error) { | ||
return nil, status.Errorf(codes.Unimplemented, "method DetermineVersions not implemented") | ||
} | ||
func (s *DeploymentPluginServiceServer[Config]) DetermineStrategy(context.Context, *deployment.DetermineStrategyRequest) (*deployment.DetermineStrategyResponse, error) { | ||
return nil, status.Errorf(codes.Unimplemented, "method DetermineStrategy not implemented") | ||
} | ||
func (s *DeploymentPluginServiceServer[Config]) BuildPipelineSyncStages(context.Context, *deployment.BuildPipelineSyncStagesRequest) (*deployment.BuildPipelineSyncStagesResponse, error) { | ||
return nil, status.Errorf(codes.Unimplemented, "method BuildPipelineSyncStages not implemented") | ||
} | ||
func (s *DeploymentPluginServiceServer[Config]) BuildQuickSyncStages(context.Context, *deployment.BuildQuickSyncStagesRequest) (*deployment.BuildQuickSyncStagesResponse, error) { | ||
return nil, status.Errorf(codes.Unimplemented, "method BuildQuickSyncStages not implemented") | ||
} | ||
func (s *DeploymentPluginServiceServer[Config]) ExecuteStage(context.Context, *deployment.ExecuteStageRequest) (*deployment.ExecuteStageResponse, error) { | ||
return nil, status.Errorf(codes.Unimplemented, "method ExecuteStage not implemented") | ||
} | ||
|
||
// PipelineSyncPluginServiceServer is the gRPC server that handles requests from the piped. | ||
type PipelineSyncPluginServiceServer[Config any] struct { | ||
deployment.UnimplementedDeploymentServiceServer | ||
commonFields | ||
|
||
base PipelineSyncPlugin[Config] | ||
} | ||
|
||
// Name returns the name of the plugin. | ||
func (s *PipelineSyncPluginServiceServer[Config]) Name() string { | ||
return s.base.Name() | ||
} | ||
|
||
// Version returns the version of the plugin. | ||
func (s *PipelineSyncPluginServiceServer[Config]) Version() string { | ||
return s.base.Version() | ||
} | ||
|
||
// Register registers the server to the given gRPC server. | ||
func (s *PipelineSyncPluginServiceServer[Config]) Register(server *grpc.Server) { | ||
deployment.RegisterDeploymentServiceServer(server, s) | ||
} | ||
|
||
func (s *PipelineSyncPluginServiceServer[Config]) setCommonFields(fields commonFields) { | ||
s.commonFields = fields | ||
} | ||
|
||
func (s *PipelineSyncPluginServiceServer[Config]) FetchDefinedStages(context.Context, *deployment.FetchDefinedStagesRequest) (*deployment.FetchDefinedStagesResponse, error) { | ||
return &deployment.FetchDefinedStagesResponse{Stages: s.base.FetchDefinedStages()}, nil | ||
} | ||
func (s *PipelineSyncPluginServiceServer[Config]) DetermineVersions(context.Context, *deployment.DetermineVersionsRequest) (*deployment.DetermineVersionsResponse, error) { | ||
return nil, status.Errorf(codes.Unimplemented, "method DetermineVersions not implemented") | ||
} | ||
func (s *PipelineSyncPluginServiceServer[Config]) DetermineStrategy(context.Context, *deployment.DetermineStrategyRequest) (*deployment.DetermineStrategyResponse, error) { | ||
return nil, status.Errorf(codes.Unimplemented, "method DetermineStrategy not implemented") | ||
} | ||
func (s *PipelineSyncPluginServiceServer[Config]) BuildPipelineSyncStages(context.Context, *deployment.BuildPipelineSyncStagesRequest) (*deployment.BuildPipelineSyncStagesResponse, error) { | ||
return nil, status.Errorf(codes.Unimplemented, "method BuildPipelineSyncStages not implemented") | ||
} | ||
func (s *PipelineSyncPluginServiceServer[Config]) BuildQuickSyncStages(context.Context, *deployment.BuildQuickSyncStagesRequest) (*deployment.BuildQuickSyncStagesResponse, error) { | ||
return nil, status.Errorf(codes.Unimplemented, "method BuildQuickSyncStages not implemented") | ||
} | ||
func (s *PipelineSyncPluginServiceServer[Config]) ExecuteStage(context.Context, *deployment.ExecuteStageRequest) (*deployment.ExecuteStageResponse, error) { | ||
return nil, status.Errorf(codes.Unimplemented, "method ExecuteStage not implemented") | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
Config
parameter is the plugin's config defined in piped's config.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a comment to explain that 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added config on this commit.
337e8c8