Skip to content

Commit 398f35c

Browse files
fix(web,cli): use defaults.Set instead of hand-setting RunJob.Delete
Per review on #745: reuse the codebase's existing struct-tag-default convention (creasty/defaults, already used in registerAllJobs) instead of hand-setting Delete = "true". This also fixes the sibling gaps of the same bug class for API-created and persisted run jobs: Pull (default:"true", was silently false) and HistoryLimit (default:"10", was 0, unbounded run history). Future-proof: defaults.Set only fills zero values, so an explicit false survives if delete is ever exposed in jobRequest/persist.Job. Signed-off-by: Matheus Amendola <matheusamendolaa@gmail.com>
1 parent 194e7dc commit 398f35c

2 files changed

Lines changed: 6 additions & 10 deletions

File tree

cli/daemon.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"sync"
1515
"time"
1616

17+
"github.com/creasty/defaults"
1718
"github.com/gobs/args"
1819

1920
cfgvalidator "github.com/netresearch/ofelia/config"
@@ -609,15 +610,13 @@ func (c *DaemonCommand) buildPersistedRunJob(name string, j *persist.Job, provid
609610
return nil, fmt.Errorf("docker provider unavailable for run job")
610611
}
611612
rj := core.NewRunJob(provider)
613+
// struct-tag defaults are only applied by the config decoder — apply them here too.
614+
_ = defaults.Set(rj)
612615
rj.Name = name
613616
rj.Schedule = j.Schedule
614617
rj.Command = j.Command
615618
rj.Image = j.Image
616619
rj.Container = j.Container
617-
// Same gap as newRunJobFromRequest (web/server.go): Delete's "true" default only
618-
// applies through the config.ini decoder, and persisted API jobs are rebuilt here on
619-
// every daemon restart without going through it.
620-
rj.Delete = "true"
621620
return rj, nil
622621
}
623622

web/server.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"sync"
1717
"time"
1818

19+
"github.com/creasty/defaults"
1920
"github.com/gobs/args"
2021
cron "github.com/netresearch/go-cron"
2122

@@ -754,17 +755,13 @@ func (s *Server) newRunJobFromRequest(req *jobRequest) (core.Job, error) {
754755
return nil, fmt.Errorf("docker provider unavailable for run job")
755756
}
756757
j := core.NewRunJob(s.provider)
758+
// struct-tag defaults are only applied by the config decoder — apply them here too.
759+
_ = defaults.Set(j)
757760
j.Name = req.Name
758761
j.Schedule = req.Schedule
759762
j.Command = req.Command
760763
j.Image = req.Image
761764
j.Container = req.Container
762-
// RunJob.Delete only gets its "true" default (core/runjob.go) via the config.ini
763-
// decoder's default-tag handling; jobs built here from a jobRequest never go through
764-
// that decoder, so Delete was left at its zero value ("") and deleteContainer() treated
765-
// that as false — the container from every API-created run job was left behind,
766-
// colliding with the next run's `docker create` on the same name.
767-
j.Delete = "true"
768765
return j, nil
769766
}
770767

0 commit comments

Comments
 (0)