From 8513f51da6466e6cf95609df45b64639e8267bf7 Mon Sep 17 00:00:00 2001 From: boindil Date: Wed, 19 Oct 2022 21:29:06 +0200 Subject: [PATCH 1/2] prevent deletion of jobs added through config file when updating docker label jobs --- cli/config.go | 6 ++++++ cli/docker-labels.go | 1 + 2 files changed, 7 insertions(+) diff --git a/cli/config.go b/cli/config.go index 3520331..81ce3f5 100644 --- a/cli/config.go +++ b/cli/config.go @@ -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 @@ -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() { diff --git a/cli/docker-labels.go b/cli/docker-labels.go index ef19517..511a42a 100644 --- a/cli/docker-labels.go +++ b/cli/docker-labels.go @@ -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) From a04d26a6dff008011d052e200ba64c1cdd9b4c83 Mon Sep 17 00:00:00 2001 From: Jose Lopes Date: Thu, 10 Nov 2022 23:32:06 +0000 Subject: [PATCH 2/2] Fixed tests --- cli/config_test.go | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/cli/config_test.go b/cli/config_test.go index 295a8b8..b414094 100644 --- a/cli/config_test.go +++ b/cli/config_test.go @@ -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", @@ -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, }, }, },