Check if multiple canaries have the same target

- log an error on target duplication ref #13
This commit is contained in:
stefanprodan
2019-01-15 21:43:05 +02:00
parent 23e8c7d616
commit 9232c8647a
+12 -2
View File
@@ -12,7 +12,7 @@ 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 {
@@ -20,7 +20,7 @@ func (c *Controller) scheduleCanaries() {
// 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 {
@@ -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)