From 657066e3e6bd6698a2566a63548677b9a2a43345 Mon Sep 17 00:00:00 2001 From: khanhtc1202 Date: Wed, 13 Jan 2021 14:02:43 +0900 Subject: [PATCH 1/2] Report StateStatus in all cases except piped process is terminated --- pkg/app/piped/controller/scheduler.go | 12 +++++++++--- pkg/app/piped/executor/stopsignal.go | 6 +++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pkg/app/piped/controller/scheduler.go b/pkg/app/piped/controller/scheduler.go index 087337b545..398e2080dc 100644 --- a/pkg/app/piped/controller/scheduler.go +++ b/pkg/app/piped/controller/scheduler.go @@ -412,9 +412,9 @@ func (s *scheduler) executeStage(sig executor.StopSignal, ps model.PipelineStage lp = s.logPersister.StageLogPersister(s.deployment.Id, ps.Id) ) defer func() { - // When the piped has been stopped while the stage is still running + // When the piped has been terminated (PS kill) while the stage is still running // we should not mark the log persister as completed. - if !model.IsCompletedStage(finalStatus) && sig.Stopped() { + if !model.IsCompletedStage(finalStatus) && sig.Terminated() { return } lp.Complete(time.Minute) @@ -499,14 +499,20 @@ func (s *scheduler) executeStage(sig executor.StopSignal, ps model.PipelineStage // Start running executor. status := ex.Execute(sig) + // Commit deployment state status in the following cases: + // - Apply state successfully. + // - State was canceled while running (cancel via Controlpane). + // - Apply state failed but not because of terminating piped process. if status == model.StageStatus_STAGE_SUCCESS || status == model.StageStatus_STAGE_CANCELLED || - (status == model.StageStatus_STAGE_FAILURE && !sig.Stopped()) { + (status == model.StageStatus_STAGE_FAILURE && !sig.Terminated()) { s.reportStageStatus(ctx, ps.Id, status, ps.Requires) return status } + // In case piped process got killed (Terminated signal occurred) + // the original state status will be returned. return originalStatus } diff --git a/pkg/app/piped/executor/stopsignal.go b/pkg/app/piped/executor/stopsignal.go index 6d7f982acf..79f5a1b3d6 100644 --- a/pkg/app/piped/executor/stopsignal.go +++ b/pkg/app/piped/executor/stopsignal.go @@ -40,7 +40,7 @@ type StopSignal interface { Context() context.Context Ch() <-chan StopSignalType Signal() StopSignalType - Stopped() bool + Terminated() bool } type StopSignalHandler interface { @@ -101,7 +101,7 @@ func (s *stopSignal) Signal() StopSignalType { return StopSignalType(value) } -func (s *stopSignal) Stopped() bool { +func (s *stopSignal) Terminated() bool { value := s.signal.Load() - return StopSignalType(value) != StopSignalNone + return StopSignalType(value) != StopSignalTerminate } From 8844ccb1c6241c8747197ecba1026b798e8a01bc Mon Sep 17 00:00:00 2001 From: khanhtc1202 Date: Wed, 13 Jan 2021 14:15:55 +0900 Subject: [PATCH 2/2] Update condition --- pkg/app/piped/executor/stopsignal.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/app/piped/executor/stopsignal.go b/pkg/app/piped/executor/stopsignal.go index 79f5a1b3d6..18d84be14d 100644 --- a/pkg/app/piped/executor/stopsignal.go +++ b/pkg/app/piped/executor/stopsignal.go @@ -103,5 +103,5 @@ func (s *stopSignal) Signal() StopSignalType { func (s *stopSignal) Terminated() bool { value := s.signal.Load() - return StopSignalType(value) != StopSignalTerminate + return StopSignalType(value) == StopSignalTerminate }