From 9232c8647a2c582fcd1ef9283cf373de0464c170 Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Tue, 15 Jan 2019 21:43:05 +0200 Subject: [PATCH] Check if multiple canaries have the same target - log an error on target duplication ref #13 --- pkg/controller/scheduler.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/controller/scheduler.go b/pkg/controller/scheduler.go index 8608d2bba..25a958922 100644 --- a/pkg/controller/scheduler.go +++ b/pkg/controller/scheduler.go @@ -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 := 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)