Skip to content

Commit

Permalink
Check if multiple canaries have the same target
Browse files Browse the repository at this point in the history
- log an error on target duplication ref #13
  • Loading branch information
stefanprodan committed Jan 15, 2019
1 parent 23e8c7d commit 9232c86
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/controller/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import (
// for new canaries new jobs are created and started
// for the removed canaries the jobs are stopped and deleted
func (c *Controller) scheduleCanaries() {
current := make(map[string]bool)
current := make(map[string]string)
stats := make(map[string]int)

c.canaries.Range(func(key interface{}, value interface{}) bool {
canary := value.(*flaggerv1.Canary)

// format: <name>.<namespace>
name := key.(string)
current[name] = true
current[name] = fmt.Sprintf("%s.%s", canary.Spec.TargetRef.Name, canary.Namespace)

// schedule new jobs
if _, exists := c.jobs[name]; !exists {
Expand Down Expand Up @@ -54,6 +54,16 @@ func (c *Controller) scheduleCanaries() {
}
}

// check if multiple canaries have the same target
for canaryName, targetName := range current {
for name, target := range current {
if name != canaryName && target == targetName {
c.logger.Errorf("Bad things will happen! Found more than one canary with the same target %s",
targetName)
}
}
}

// set total canaries per namespace metric
for k, v := range stats {
c.recorder.SetTotal(k, v)
Expand Down

0 comments on commit 9232c86

Please sign in to comment.