Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create New Job when Canary's Interval changes #91

Merged
merged 1 commit into from
Mar 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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