mirror of
https://github.com/fluxcd/flagger.git
synced 2026-04-15 06:57:34 +00:00
Merge pull request #91 from huydinhle/update-analysis-interval
Sync job when canary's interval changes fix #86
This commit is contained in:
+11
-6
@@ -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
|
||||
@@ -33,3 +34,7 @@ func (j CanaryJob) Stop() {
|
||||
close(j.done)
|
||||
j.ticker.Stop()
|
||||
}
|
||||
|
||||
func (j CanaryJob) GetCanaryAnalysisInterval() time.Duration {
|
||||
return j.analysisInterval
|
||||
}
|
||||
|
||||
+16
-10
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user