Merge pull request #91 from huydinhle/update-analysis-interval

Sync job when canary's interval changes
fix #86
This commit is contained in:
Stefan Prodan
2019-03-09 19:58:34 +02:00
committed by GitHub
2 changed files with 27 additions and 16 deletions
+11 -6
View File
@@ -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
View File
@@ -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