Skip to content

Commit b099bc0

Browse files
authored
Add example plugin implementation using SDK (#5583)
* Rename pippedsdk to sdk Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> * Add example initial implementations Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> * Fix unmarshalling nil config Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> * Implement DetermineVersions and DetermineStrategy for PipelineSyncPlugin Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> * Add copyright notice Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> --------- Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev>
1 parent 88ec254 commit b099bc0

File tree

5 files changed

+91
-5
lines changed

5 files changed

+91
-5
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2025 The PipeCD Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package main
16+
17+
import (
18+
"log"
19+
20+
"github.com/pipe-cd/pipecd/pkg/plugin/sdk"
21+
)
22+
23+
func main() {
24+
sdk.RegisterPipelineSyncPlugin(&plugin{})
25+
26+
if err := sdk.Run(); err != nil {
27+
log.Fatalln(err)
28+
}
29+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2025 The PipeCD Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package main
16+
17+
import (
18+
"context"
19+
20+
"github.com/pipe-cd/pipecd/pkg/plugin/logpersister"
21+
"github.com/pipe-cd/pipecd/pkg/plugin/sdk"
22+
)
23+
24+
type plugin struct{}
25+
26+
type config struct{}
27+
28+
// Name implements sdk.Plugin.
29+
func (p *plugin) Name() string {
30+
return "example"
31+
}
32+
33+
// Version implements sdk.Plugin.
34+
func (p *plugin) Version() string {
35+
return "0.0.1"
36+
}
37+
38+
// BuildPipelineSyncStages implements sdk.PipelineSyncPlugin.
39+
func (p *plugin) BuildPipelineSyncStages(context.Context, *config, *sdk.Client, sdk.TODO) (sdk.TODO, error) {
40+
return sdk.TODO{}, nil
41+
}
42+
43+
// ExecuteStage implements sdk.PipelineSyncPlugin.
44+
func (p *plugin) ExecuteStage(context.Context, *config, sdk.DeployTargetsNone, *sdk.Client, logpersister.StageLogPersister, sdk.TODO) (sdk.TODO, error) {
45+
return sdk.TODO{}, nil
46+
}
47+
48+
// FetchDefinedStages implements sdk.PipelineSyncPlugin.
49+
func (p *plugin) FetchDefinedStages() []string {
50+
return []string{"EXAMPLE_PLAN", "EXAMPLE_APPLY"}
51+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package pipedsdk
15+
package sdk
1616

1717
import (
1818
"context"
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package pipedsdk
15+
package sdk
1616

1717
import (
1818
"context"
@@ -137,6 +137,9 @@ func (s *DeploymentPluginServiceServer[Config, DeployTargetConfig]) setCommonFie
137137
}
138138

139139
func (s *DeploymentPluginServiceServer[Config, DeployTargetConfig]) setConfig(bytes []byte) error {
140+
if bytes == nil {
141+
return nil
142+
}
140143
if err := json.Unmarshal(bytes, &s.config); err != nil {
141144
return fmt.Errorf("failed to unmarshal the plugin config: %v", err)
142145
}
@@ -191,6 +194,9 @@ func (s *PipelineSyncPluginServiceServer[Config, DeployTargetConfig]) setCommonF
191194
}
192195

193196
func (s *PipelineSyncPluginServiceServer[Config, DeployTargetConfig]) setConfig(bytes []byte) error {
197+
if bytes == nil {
198+
return nil
199+
}
194200
if err := json.Unmarshal(bytes, &s.config); err != nil {
195201
return fmt.Errorf("failed to unmarshal the plugin config: %v", err)
196202
}
@@ -201,10 +207,10 @@ func (s *PipelineSyncPluginServiceServer[Config, DeployTargetConfig]) FetchDefin
201207
return &deployment.FetchDefinedStagesResponse{Stages: s.base.FetchDefinedStages()}, nil
202208
}
203209
func (s *PipelineSyncPluginServiceServer[Config, DeployTargetConfig]) DetermineVersions(context.Context, *deployment.DetermineVersionsRequest) (*deployment.DetermineVersionsResponse, error) {
204-
return nil, status.Errorf(codes.Unimplemented, "method DetermineVersions not implemented")
210+
return &deployment.DetermineVersionsResponse{}, nil
205211
}
206212
func (s *PipelineSyncPluginServiceServer[Config, DeployTargetConfig]) DetermineStrategy(context.Context, *deployment.DetermineStrategyRequest) (*deployment.DetermineStrategyResponse, error) {
207-
return nil, status.Errorf(codes.Unimplemented, "method DetermineStrategy not implemented")
213+
return &deployment.DetermineStrategyResponse{Unsupported: true}, nil
208214
}
209215
func (s *PipelineSyncPluginServiceServer[Config, DeployTargetConfig]) BuildPipelineSyncStages(ctx context.Context, request *deployment.BuildPipelineSyncStagesRequest) (*deployment.BuildPipelineSyncStagesResponse, error) {
210216
return nil, status.Errorf(codes.Unimplemented, "method BuildPipelineSyncStages not implemented")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
// package pipedsdk provides software development kits for building PipeCD piped plugins.
16-
package pipedsdk
16+
package sdk
1717

1818
import (
1919
"context"

0 commit comments

Comments
 (0)