@@ -16,6 +16,8 @@ package pipedsdk
16
16
17
17
import (
18
18
"context"
19
+ "encoding/json"
20
+ "fmt"
19
21
20
22
"go.uber.org/zap"
21
23
"google.golang.org/grpc"
@@ -34,15 +36,22 @@ var (
34
36
35
37
Register (server * grpc.Server )
36
38
setCommonFields (commonFields )
39
+ setConfig ([]byte ) error
37
40
deployment.DeploymentServiceServer
38
41
}
39
42
)
40
43
44
+ // DeployTargetsNone is a type alias for a slice of pointers to DeployTarget
45
+ // with an empty struct as the generic type parameter. It represents a case
46
+ // where there are no deployment targets.
47
+ // This utility is defined for plugins which has no deploy targets handling in ExecuteStage.
48
+ type DeployTargetsNone = []* DeployTarget [struct {}]
49
+
41
50
// DeploymentPlugin is the interface that be implemented by a full-spec deployment plugin.
42
51
// This kind of plugin should implement all methods to manage resources and execute stages.
43
52
// The Config parameter is the plugin's config defined in piped's config.
44
- type DeploymentPlugin [Config any ] interface {
45
- PipelineSyncPlugin [Config ]
53
+ type DeploymentPlugin [Config , DeployTargetConfig any ] interface {
54
+ PipelineSyncPlugin [Config , DeployTargetConfig ]
46
55
47
56
// DetermineVersions determines the versions of the resources that will be deployed.
48
57
DetermineVersions (context.Context , * Config , * Client , TODO ) (TODO , error )
@@ -55,27 +64,38 @@ type DeploymentPlugin[Config any] interface {
55
64
// PipelineSyncPlugin is the interface implemented by a pipeline sync plugin.
56
65
// This kind of plugin may not implement quick sync stages, and will not manage resources like deployment plugin.
57
66
// It only focuses on executing stages which is generic for all kinds of pipeline sync plugins.
58
- type PipelineSyncPlugin [Config any ] interface {
67
+ // The Config parameter is the plugin's config defined in piped's config.
68
+ type PipelineSyncPlugin [Config , DeployTargetConfig any ] interface {
59
69
Plugin
60
70
61
71
// FetchDefinedStages returns the list of stages that the plugin can execute.
62
72
FetchDefinedStages () []string
63
73
// BuildPipelineSyncStages builds the stages that will be executed by the plugin.
64
74
BuildPipelineSyncStages (context.Context , * Config , * Client , TODO ) (TODO , error )
65
75
// ExecuteStage executes the given stage.
66
- ExecuteStage (context.Context , * Config , * Client , logpersister.StageLogPersister , TODO ) (TODO , error )
76
+ ExecuteStage (context.Context , * Config , []* DeployTarget [DeployTargetConfig ], * Client , logpersister.StageLogPersister , TODO ) (TODO , error )
77
+ }
78
+
79
+ // DeployTarget defines the deploy target configuration for the piped.
80
+ type DeployTarget [Config any ] struct {
81
+ // The name of the deploy target.
82
+ Name string `json:"name"`
83
+ // The labes of the deploy target.
84
+ Labels map [string ]string `json:"labels,omitempty"`
85
+ // The configuration of the deploy target.
86
+ Config Config `json:"config"`
67
87
}
68
88
69
89
// RegisterDeploymentPlugin registers the given deployment plugin.
70
90
// It will be used when running the piped.
71
- func RegisterDeploymentPlugin [Config any ](plugin DeploymentPlugin [Config ]) {
72
- deploymentServiceServer = & DeploymentPluginServiceServer [Config ]{base : plugin }
91
+ func RegisterDeploymentPlugin [Config , DeployTargetConfig any ](plugin DeploymentPlugin [Config , DeployTargetConfig ]) {
92
+ deploymentServiceServer = & DeploymentPluginServiceServer [Config , DeployTargetConfig ]{base : plugin }
73
93
}
74
94
75
95
// RegisterPipelineSyncPlugin registers the given pipeline sync plugin.
76
96
// It will be used when running the piped.
77
- func RegisterPipelineSyncPlugin [Config any ](plugin PipelineSyncPlugin [Config ]) {
78
- deploymentServiceServer = & PipelineSyncPluginServiceServer [Config ]{base : plugin }
97
+ func RegisterPipelineSyncPlugin [Config , DeployTargetConfig any ](plugin PipelineSyncPlugin [Config , DeployTargetConfig ]) {
98
+ deploymentServiceServer = & PipelineSyncPluginServiceServer [Config , DeployTargetConfig ]{base : plugin }
79
99
}
80
100
81
101
type logPersister interface {
@@ -90,92 +110,108 @@ type commonFields struct {
90
110
}
91
111
92
112
// DeploymentPluginServiceServer is the gRPC server that handles requests from the piped.
93
- type DeploymentPluginServiceServer [Config any ] struct {
113
+ type DeploymentPluginServiceServer [Config , DeployTargetConfig any ] struct {
94
114
deployment.UnimplementedDeploymentServiceServer
95
115
commonFields
96
116
97
- base DeploymentPlugin [Config ]
117
+ base DeploymentPlugin [Config , DeployTargetConfig ]
118
+ config Config
98
119
}
99
120
100
121
// Name returns the name of the plugin.
101
- func (s * DeploymentPluginServiceServer [Config ]) Name () string {
122
+ func (s * DeploymentPluginServiceServer [Config , DeployTargetConfig ]) Name () string {
102
123
return s .base .Name ()
103
124
}
104
125
105
- func (s * DeploymentPluginServiceServer [Config ]) Version () string {
126
+ func (s * DeploymentPluginServiceServer [Config , DeployTargetConfig ]) Version () string {
106
127
return s .base .Version ()
107
128
}
108
129
109
130
// Register registers the server to the given gRPC server.
110
- func (s * DeploymentPluginServiceServer [Config ]) Register (server * grpc.Server ) {
131
+ func (s * DeploymentPluginServiceServer [Config , DeployTargetConfig ]) Register (server * grpc.Server ) {
111
132
deployment .RegisterDeploymentServiceServer (server , s )
112
133
}
113
134
114
- func (s * DeploymentPluginServiceServer [Config ]) setCommonFields (fields commonFields ) {
135
+ func (s * DeploymentPluginServiceServer [Config , DeployTargetConfig ]) setCommonFields (fields commonFields ) {
115
136
s .commonFields = fields
116
137
}
117
138
118
- func (s * DeploymentPluginServiceServer [Config ]) FetchDefinedStages (context.Context , * deployment.FetchDefinedStagesRequest ) (* deployment.FetchDefinedStagesResponse , error ) {
139
+ func (s * DeploymentPluginServiceServer [Config , DeployTargetConfig ]) setConfig (bytes []byte ) error {
140
+ if err := json .Unmarshal (bytes , & s .config ); err != nil {
141
+ return fmt .Errorf ("failed to unmarshal the plugin config: %v" , err )
142
+ }
143
+ return nil
144
+ }
145
+
146
+ func (s * DeploymentPluginServiceServer [Config , DeployTargetConfig ]) FetchDefinedStages (context.Context , * deployment.FetchDefinedStagesRequest ) (* deployment.FetchDefinedStagesResponse , error ) {
119
147
return & deployment.FetchDefinedStagesResponse {Stages : s .base .FetchDefinedStages ()}, nil
120
148
}
121
- func (s * DeploymentPluginServiceServer [Config ]) DetermineVersions (context.Context , * deployment.DetermineVersionsRequest ) (* deployment.DetermineVersionsResponse , error ) {
149
+ func (s * DeploymentPluginServiceServer [Config , DeployTargetConfig ]) DetermineVersions (context.Context , * deployment.DetermineVersionsRequest ) (* deployment.DetermineVersionsResponse , error ) {
122
150
return nil , status .Errorf (codes .Unimplemented , "method DetermineVersions not implemented" )
123
151
}
124
- func (s * DeploymentPluginServiceServer [Config ]) DetermineStrategy (context.Context , * deployment.DetermineStrategyRequest ) (* deployment.DetermineStrategyResponse , error ) {
152
+ func (s * DeploymentPluginServiceServer [Config , DeployTargetConfig ]) DetermineStrategy (context.Context , * deployment.DetermineStrategyRequest ) (* deployment.DetermineStrategyResponse , error ) {
125
153
return nil , status .Errorf (codes .Unimplemented , "method DetermineStrategy not implemented" )
126
154
}
127
- func (s * DeploymentPluginServiceServer [Config ]) BuildPipelineSyncStages (context.Context , * deployment.BuildPipelineSyncStagesRequest ) (* deployment.BuildPipelineSyncStagesResponse , error ) {
155
+ func (s * DeploymentPluginServiceServer [Config , DeployTargetConfig ]) BuildPipelineSyncStages (ctx context.Context , request * deployment.BuildPipelineSyncStagesRequest ) (* deployment.BuildPipelineSyncStagesResponse , error ) {
128
156
return nil , status .Errorf (codes .Unimplemented , "method BuildPipelineSyncStages not implemented" )
129
157
}
130
- func (s * DeploymentPluginServiceServer [Config ]) BuildQuickSyncStages (context.Context , * deployment.BuildQuickSyncStagesRequest ) (* deployment.BuildQuickSyncStagesResponse , error ) {
158
+ func (s * DeploymentPluginServiceServer [Config , DeployTargetConfig ]) BuildQuickSyncStages (context.Context , * deployment.BuildQuickSyncStagesRequest ) (* deployment.BuildQuickSyncStagesResponse , error ) {
131
159
return nil , status .Errorf (codes .Unimplemented , "method BuildQuickSyncStages not implemented" )
132
160
}
133
- func (s * DeploymentPluginServiceServer [Config ]) ExecuteStage (context.Context , * deployment.ExecuteStageRequest ) (* deployment.ExecuteStageResponse , error ) {
161
+ func (s * DeploymentPluginServiceServer [Config , DeployTargetConfig ]) ExecuteStage (context.Context , * deployment.ExecuteStageRequest ) (* deployment.ExecuteStageResponse , error ) {
134
162
return nil , status .Errorf (codes .Unimplemented , "method ExecuteStage not implemented" )
135
163
}
136
164
137
165
// PipelineSyncPluginServiceServer is the gRPC server that handles requests from the piped.
138
- type PipelineSyncPluginServiceServer [Config any ] struct {
166
+ type PipelineSyncPluginServiceServer [Config , DeployTargetConfig any ] struct {
139
167
deployment.UnimplementedDeploymentServiceServer
140
168
commonFields
141
169
142
- base PipelineSyncPlugin [Config ]
170
+ base PipelineSyncPlugin [Config , DeployTargetConfig ]
171
+ config Config
143
172
}
144
173
145
174
// Name returns the name of the plugin.
146
- func (s * PipelineSyncPluginServiceServer [Config ]) Name () string {
175
+ func (s * PipelineSyncPluginServiceServer [Config , DeployTargetConfig ]) Name () string {
147
176
return s .base .Name ()
148
177
}
149
178
150
179
// Version returns the version of the plugin.
151
- func (s * PipelineSyncPluginServiceServer [Config ]) Version () string {
180
+ func (s * PipelineSyncPluginServiceServer [Config , DeployTargetConfig ]) Version () string {
152
181
return s .base .Version ()
153
182
}
154
183
155
184
// Register registers the server to the given gRPC server.
156
- func (s * PipelineSyncPluginServiceServer [Config ]) Register (server * grpc.Server ) {
185
+ func (s * PipelineSyncPluginServiceServer [Config , DeployTargetConfig ]) Register (server * grpc.Server ) {
157
186
deployment .RegisterDeploymentServiceServer (server , s )
158
187
}
159
188
160
- func (s * PipelineSyncPluginServiceServer [Config ]) setCommonFields (fields commonFields ) {
189
+ func (s * PipelineSyncPluginServiceServer [Config , DeployTargetConfig ]) setCommonFields (fields commonFields ) {
161
190
s .commonFields = fields
162
191
}
163
192
164
- func (s * PipelineSyncPluginServiceServer [Config ]) FetchDefinedStages (context.Context , * deployment.FetchDefinedStagesRequest ) (* deployment.FetchDefinedStagesResponse , error ) {
193
+ func (s * PipelineSyncPluginServiceServer [Config , DeployTargetConfig ]) setConfig (bytes []byte ) error {
194
+ if err := json .Unmarshal (bytes , & s .config ); err != nil {
195
+ return fmt .Errorf ("failed to unmarshal the plugin config: %v" , err )
196
+ }
197
+ return nil
198
+ }
199
+
200
+ func (s * PipelineSyncPluginServiceServer [Config , DeployTargetConfig ]) FetchDefinedStages (context.Context , * deployment.FetchDefinedStagesRequest ) (* deployment.FetchDefinedStagesResponse , error ) {
165
201
return & deployment.FetchDefinedStagesResponse {Stages : s .base .FetchDefinedStages ()}, nil
166
202
}
167
- func (s * PipelineSyncPluginServiceServer [Config ]) DetermineVersions (context.Context , * deployment.DetermineVersionsRequest ) (* deployment.DetermineVersionsResponse , error ) {
203
+ func (s * PipelineSyncPluginServiceServer [Config , DeployTargetConfig ]) DetermineVersions (context.Context , * deployment.DetermineVersionsRequest ) (* deployment.DetermineVersionsResponse , error ) {
168
204
return nil , status .Errorf (codes .Unimplemented , "method DetermineVersions not implemented" )
169
205
}
170
- func (s * PipelineSyncPluginServiceServer [Config ]) DetermineStrategy (context.Context , * deployment.DetermineStrategyRequest ) (* deployment.DetermineStrategyResponse , error ) {
206
+ func (s * PipelineSyncPluginServiceServer [Config , DeployTargetConfig ]) DetermineStrategy (context.Context , * deployment.DetermineStrategyRequest ) (* deployment.DetermineStrategyResponse , error ) {
171
207
return nil , status .Errorf (codes .Unimplemented , "method DetermineStrategy not implemented" )
172
208
}
173
- func (s * PipelineSyncPluginServiceServer [Config ]) BuildPipelineSyncStages (context.Context , * deployment.BuildPipelineSyncStagesRequest ) (* deployment.BuildPipelineSyncStagesResponse , error ) {
209
+ func (s * PipelineSyncPluginServiceServer [Config , DeployTargetConfig ]) BuildPipelineSyncStages (ctx context.Context , request * deployment.BuildPipelineSyncStagesRequest ) (* deployment.BuildPipelineSyncStagesResponse , error ) {
174
210
return nil , status .Errorf (codes .Unimplemented , "method BuildPipelineSyncStages not implemented" )
175
211
}
176
- func (s * PipelineSyncPluginServiceServer [Config ]) BuildQuickSyncStages (context.Context , * deployment.BuildQuickSyncStagesRequest ) (* deployment.BuildQuickSyncStagesResponse , error ) {
212
+ func (s * PipelineSyncPluginServiceServer [Config , DeployTargetConfig ]) BuildQuickSyncStages (context.Context , * deployment.BuildQuickSyncStagesRequest ) (* deployment.BuildQuickSyncStagesResponse , error ) {
177
213
return nil , status .Errorf (codes .Unimplemented , "method BuildQuickSyncStages not implemented" )
178
214
}
179
- func (s * PipelineSyncPluginServiceServer [Config ]) ExecuteStage (context.Context , * deployment.ExecuteStageRequest ) (* deployment.ExecuteStageResponse , error ) {
215
+ func (s * PipelineSyncPluginServiceServer [Config , DeployTargetConfig ]) ExecuteStage (context.Context , * deployment.ExecuteStageRequest ) (* deployment.ExecuteStageResponse , error ) {
180
216
return nil , status .Errorf (codes .Unimplemented , "method ExecuteStage not implemented" )
181
217
}
0 commit comments