@@ -45,10 +45,11 @@ type scheduler struct {
45
45
46
46
stageBasedPluginsMap map [string ]pluginapi.PluginClient
47
47
48
- apiClient apiClient
49
- gitClient gitClient
50
- metadataStore metadatastore.MetadataStore
51
- notifier notifier
48
+ apiClient apiClient
49
+ gitClient gitClient
50
+ metadataStore metadatastore.MetadataStore
51
+ notifier notifier
52
+ secretDecrypter secretDecrypter
52
53
53
54
targetDSP deploysource.Provider
54
55
runningDSP deploysource.Provider
@@ -80,6 +81,7 @@ func newScheduler(
80
81
gitClient gitClient ,
81
82
stageBasedPluginsMap map [string ]pluginapi.PluginClient ,
82
83
notifier notifier ,
84
+ secretsDecrypter secretDecrypter ,
83
85
logger * zap.Logger ,
84
86
tracerProvider trace.TracerProvider ,
85
87
) * scheduler {
@@ -99,6 +101,7 @@ func newScheduler(
99
101
gitClient : gitClient ,
100
102
metadataStore : metadatastore .NewMetadataStore (apiClient , d ),
101
103
notifier : notifier ,
104
+ secretDecrypter : secretsDecrypter ,
102
105
doneDeploymentStatus : d .Status ,
103
106
cancelledCh : make (chan * model.ReportableCommand , 1 ),
104
107
logger : logger ,
@@ -165,7 +168,7 @@ func (s *scheduler) Cancel(cmd model.ReportableCommand) {
165
168
}
166
169
167
170
// Run starts running the scheduler.
168
- // It determines what stage should be executed next by which executor .
171
+ // It determines what stage should be executed next by which plugin .
169
172
// The returning error does not mean that the pipeline was failed,
170
173
// but it means that the scheduler could not finish its job normally.
171
174
func (s * scheduler ) Run (ctx context.Context ) error {
@@ -193,7 +196,7 @@ func (s *scheduler) Run(ctx context.Context) error {
193
196
}
194
197
controllermetrics .UpdateDeploymentStatus (s .deployment , model .DeploymentStatus_DEPLOYMENT_RUNNING )
195
198
196
- // notify the deployment started event
199
+ // Notify the deployment started event
197
200
users , groups , err := s .getApplicationNotificationMentions (model .NotificationEventType_EVENT_DEPLOYMENT_STARTED )
198
201
if err != nil {
199
202
s .logger .Error ("failed to get the list of users or groups" , zap .Error (err ))
@@ -223,16 +226,20 @@ func (s *scheduler) Run(ctx context.Context) error {
223
226
Branch : s .deployment .GitPath .Repo .Branch ,
224
227
}
225
228
226
- s .runningDSP = deploysource .NewProvider (
227
- filepath .Join (s .workingDir , "running-deploysource" ),
228
- deploysource .NewGitSourceCloner (s .gitClient , repoCfg , "running" , s .deployment .RunningCommitHash ),
229
- s .deployment .GetGitPath (), nil , // TODO: pass secret decrypter?
230
- )
229
+ if s .deployment .RunningCommitHash != "" {
230
+ s .runningDSP = deploysource .NewProvider (
231
+ filepath .Join (s .workingDir , "running-deploysource" ),
232
+ deploysource .NewGitSourceCloner (s .gitClient , repoCfg , "running" , s .deployment .RunningCommitHash ),
233
+ s .deployment .GetGitPath (),
234
+ s .secretDecrypter ,
235
+ )
236
+ }
231
237
232
238
s .targetDSP = deploysource .NewProvider (
233
239
filepath .Join (s .workingDir , "target-deploysource" ),
234
240
deploysource .NewGitSourceCloner (s .gitClient , repoCfg , "target" , s .deployment .Trigger .Commit .Hash ),
235
- s .deployment .GetGitPath (), nil , // TODO: pass secret decrypter?
241
+ s .deployment .GetGitPath (),
242
+ s .secretDecrypter ,
236
243
)
237
244
238
245
ds , err := s .targetDSP .Get (ctx , io .Discard )
@@ -469,13 +476,13 @@ func (s *scheduler) executeStage(sig StopSignal, ps *model.PipelineStage) (final
469
476
470
477
rds , err := s .runningDSP .Get (ctx , io .Discard )
471
478
if err != nil {
472
- s .logger .Error ("failed to get running deployment source" , zap .Error (err ))
479
+ s .logger .Error ("failed to get running deployment source" , zap .String ( "stage-name" , ps . Name ), zap . Error (err ))
473
480
return model .StageStatus_STAGE_FAILURE
474
481
}
475
482
476
483
tds , err := s .targetDSP .Get (ctx , io .Discard )
477
484
if err != nil {
478
- s .logger .Error ("failed to get target deployment source" , zap .Error (err ))
485
+ s .logger .Error ("failed to get target deployment source" , zap .String ( "stage-name" , ps . Name ), zap . Error (err ))
479
486
return model .StageStatus_STAGE_FAILURE
480
487
}
481
488
@@ -508,16 +515,15 @@ func (s *scheduler) executeStage(sig StopSignal, ps *model.PipelineStage) (final
508
515
// Find the executor plugin for this stage.
509
516
plugin , ok := s .stageBasedPluginsMap [ps .Name ]
510
517
if ! ok {
511
- err := fmt .Errorf ("no registered plugin that can perform for stage %s" , ps .Name )
512
- s .logger .Error (err .Error ())
518
+ s .logger .Error ("failed to find the plugin for the stage" , zap .String ("stage-name" , ps .Name ))
513
519
s .reportStageStatus (ctx , ps .Id , model .StageStatus_STAGE_FAILURE , ps .Requires )
514
520
return model .StageStatus_STAGE_FAILURE
515
521
}
516
522
517
523
// Load the stage configuration.
518
524
stageConfig , stageConfigFound := s .genericApplicationConfig .GetStageByte (ps .Index )
519
525
if ! stageConfigFound {
520
- s .logger .Error ("Unable to find the stage configuration" )
526
+ s .logger .Error ("Unable to find the stage configuration" , zap . String ( "stage-name" , ps . Name ) )
521
527
if err := s .reportStageStatus (ctx , ps .Id , model .StageStatus_STAGE_FAILURE , ps .Requires ); err != nil {
522
528
s .logger .Error ("failed to report stage status" , zap .Error (err ))
523
529
}
@@ -535,7 +541,7 @@ func (s *scheduler) executeStage(sig StopSignal, ps *model.PipelineStage) (final
535
541
},
536
542
})
537
543
if err != nil {
538
- s .logger .Error ("failed to execute stage" , zap .Error (err ))
544
+ s .logger .Error ("failed to execute stage" , zap .String ( "stage-name" , ps . Name ), zap . Error (err ))
539
545
s .reportStageStatus (ctx , ps .Id , model .StageStatus_STAGE_FAILURE , ps .Requires )
540
546
return model .StageStatus_STAGE_FAILURE
541
547
}
0 commit comments