Skip to content

Commit

Permalink
fix: graceful delete runtime dir. (#2393)
Browse files Browse the repository at this point in the history
* fix: graceful delete runtime dir.

Signed-off-by: joyceliu <joyceliu@yunify.com>

* fix: graceful delete runtime dir.

Signed-off-by: joyceliu <joyceliu@yunify.com>

---------

Signed-off-by: joyceliu <joyceliu@yunify.com>
Co-authored-by: joyceliu <joyceliu@yunify.com>
  • Loading branch information
redscholar and joyceliu authored Sep 6, 2024
1 parent 7eba91a commit 48831c7
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pkg/manager/command_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ func (m *commandManager) Run(ctx context.Context) error {
defer func() {
fmt.Fprintf(m.logOutput, "%s [Pipeline %s] finish. total: %v,success: %v,ignored: %v,failed: %v\n", time.Now().Format(time.TimeOnly+" MST"), ctrlclient.ObjectKeyFromObject(m.Pipeline),
m.Pipeline.Status.TaskResult.Total, m.Pipeline.Status.TaskResult.Success, m.Pipeline.Status.TaskResult.Ignored, m.Pipeline.Status.TaskResult.Failed)
if !m.Pipeline.Spec.Debug && m.Pipeline.Status.Phase == kkcorev1.PipelinePhaseSucceed {
fmt.Fprintf(m.logOutput, "%s [Pipeline %s] clean runtime directory\n", time.Now().Format(time.TimeOnly+" MST"), ctrlclient.ObjectKeyFromObject(m.Pipeline))
// clean runtime directory
if err := os.RemoveAll(_const.GetRuntimeDir()); err != nil {
klog.ErrorS(err, "clean runtime directory error", "pipeline", ctrlclient.ObjectKeyFromObject(m.Pipeline), "runtime_dir", _const.GetRuntimeDir())
go func() {
if !m.Pipeline.Spec.Debug && m.Pipeline.Status.Phase == kkcorev1.PipelinePhaseSucceed {
<-ctx.Done()
fmt.Fprintf(m.logOutput, "%s [Pipeline %s] clean runtime directory\n", time.Now().Format(time.TimeOnly+" MST"), ctrlclient.ObjectKeyFromObject(m.Pipeline))
// clean runtime directory
if err := os.RemoveAll(_const.GetRuntimeDir()); err != nil {
klog.ErrorS(err, "clean runtime directory error", "pipeline", ctrlclient.ObjectKeyFromObject(m.Pipeline), "runtime_dir", _const.GetRuntimeDir())
}
}
}
}()
// if pipeline is cornJob. it's always running.
if m.Pipeline.Spec.JobSpec.Schedule != "" {
m.Pipeline.Status.Phase = kkcorev1.PipelinePhaseRunning
Expand Down

0 comments on commit 48831c7

Please sign in to comment.