Skip to content

Commit

Permalink
Merge pull request #49 from joshlopes/main
Browse files Browse the repository at this point in the history
Prevent deletion of jobs
  • Loading branch information
maietta authored Nov 10, 2022
2 parents ea4533d + a04d26a commit cff87dc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
6 changes: 6 additions & 0 deletions cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ func (c *Config) dockerLabelsUpdate(labels map[string]map[string]string) {

// Calculate the delta
for name, j := range c.ExecJobs {
// this prevents deletion of jobs that were added by reading a configuration file
if !j.FromDockerLabel {
continue
}

found := false
for newJobsName, newJob := range parsedLabelConfig.ExecJobs {
// Check if the schedule has changed
Expand Down Expand Up @@ -178,6 +183,7 @@ type ExecJobConfig struct {
middlewares.SaveConfig `mapstructure:",squash"`
middlewares.MailConfig `mapstructure:",squash"`
middlewares.GotifyConfig `mapstructure:",squash"`
FromDockerLabel bool `mapstructure:"fromDockerLabel"`
}

func (c *ExecJobConfig) buildMiddlewares() {
Expand Down
31 changes: 20 additions & 11 deletions cli/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,25 @@ func (s *SuiteConfig) TestLabelsConfig(c *C) {
},
ExpectedConfig: Config{
ExecJobs: map[string]*ExecJobConfig{
"job1": &ExecJobConfig{ExecJob: core.ExecJob{BareJob: core.BareJob{
Schedule: "schedule1",
Command: "command1",
}}},
"job2": &ExecJobConfig{ExecJob: core.ExecJob{
BareJob: core.BareJob{
Schedule: "schedule2",
Command: "command2",
"job1": &ExecJobConfig{
ExecJob: core.ExecJob{
BareJob: core.BareJob{
Schedule: "schedule1",
Command: "command1",
},
},
Container: "other",
}},
FromDockerLabel: true,
},
"job2": &ExecJobConfig{
ExecJob: core.ExecJob{
BareJob: core.BareJob{
Schedule: "schedule2",
Command: "command2",
},
Container: "other",
},
FromDockerLabel: true,
},
},
},
Comment: "Exec jobs from non-service container, saves container name to be able to exect to",
Expand All @@ -221,7 +229,8 @@ func (s *SuiteConfig) TestLabelsConfig(c *C) {
Schedule: "schedule1",
Command: "command1",
}},
OverlapConfig: middlewares.OverlapConfig{NoOverlap: true},
OverlapConfig: middlewares.OverlapConfig{NoOverlap: true},
FromDockerLabel: true,
},
},
},
Expand Down
1 change: 1 addition & 0 deletions cli/docker-labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func (c *Config) buildFromDockerLabels(labels map[string]map[string]string) erro
case jobType == jobExec: // only job exec can be provided on the non-service container
if _, ok := execJobs[jobName]; !ok {
execJobs[jobName] = make(map[string]interface{})
execJobs[jobName]["fromDockerLabel"] = true
}

setJobParam(execJobs[jobName], jopParam, v)
Expand Down

0 comments on commit cff87dc

Please sign in to comment.