Skip to content

Commit

Permalink
Create New Job when Canary's Interval changes
Browse files Browse the repository at this point in the history
- Currently whenever the Canary analysis interval changes, flagger does
not reflect this into canary's job.
- This change will make sure the canary analysis interval got updated whenever
the Canary object's interval changes
  • Loading branch information
huydinhle committed Mar 8, 2019
1 parent fcd5207 commit 6196f69
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
17 changes: 11 additions & 6 deletions pkg/controller/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import "time"

// CanaryJob holds the reference to a canary deployment schedule
type CanaryJob struct {
Name string
Namespace string
SkipTests bool
function func(name string, namespace string, skipTests bool)
done chan bool
ticker *time.Ticker
Name string
Namespace string
SkipTests bool
function func(name string, namespace string, skipTests bool)
done chan bool
ticker *time.Ticker
analysisInterval time.Duration
}

// Start runs the canary analysis on a schedule
Expand All @@ -33,3 +34,7 @@ func (j CanaryJob) Stop() {
close(j.done)
j.ticker.Stop()
}

func (j CanaryJob) GetCanaryAnalysisInterval() time.Duration {
return j.analysisInterval
}
26 changes: 16 additions & 10 deletions pkg/controller/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,24 @@ func (c *Controller) scheduleCanaries() {
name := key.(string)
current[name] = fmt.Sprintf("%s.%s", canary.Spec.TargetRef.Name, canary.Namespace)

// schedule new jobs
if _, exists := c.jobs[name]; !exists {
job := CanaryJob{
Name: canary.Name,
Namespace: canary.Namespace,
function: c.advanceCanary,
done: make(chan bool),
ticker: time.NewTicker(canary.GetAnalysisInterval()),
job, exists := c.jobs[name]
// schedule new job for exsiting job with different analysisInterval or non-existing job
if (exists && job.GetCanaryAnalysisInterval() != canary.GetAnalysisInterval()) || !exists {
if exists {
job.Stop()
}

c.jobs[name] = job
job.Start()
newJob := CanaryJob{
Name: canary.Name,
Namespace: canary.Namespace,
function: c.advanceCanary,
done: make(chan bool),
ticker: time.NewTicker(canary.GetAnalysisInterval()),
analysisInterval: canary.GetAnalysisInterval(),
}

c.jobs[name] = newJob
newJob.Start()
}

// compute canaries per namespace total
Expand Down

0 comments on commit 6196f69

Please sign in to comment.