From 3a2550d0424f6005658d58fef3fd72470fdb5020 Mon Sep 17 00:00:00 2001 From: Reed Allman Date: Tue, 3 Apr 2018 11:21:56 -0700 Subject: [PATCH] change slots when annotations change (#914) when the annotations change, we need to get a different slot key to launch new containers with these annotations and let the old containers die off unused. I started on a test for this, but changing all combinations of each field in isolation to change is not very fun without reflection, and there's still a subset of fields we're managing, so it put us in about the same spot as we are now. --- api/agent/slots.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/api/agent/slots.go b/api/agent/slots.go index cf67920cb..86d357a12 100644 --- a/api/agent/slots.go +++ b/api/agent/slots.go @@ -326,6 +326,25 @@ func getSlotQueueKey(call *call) string { hash.Write(unsafeBytes("\x00")) } + // we need to additionally delimit config and annotations to eliminate overlap bug + hash.Write(unsafeBytes("\x00")) + + keys = keys[:0] // clear keys + for k := range call.Annotations { + i := sort.SearchStrings(keys, k) + keys = append(keys, "") + copy(keys[i+1:], keys[i:]) + keys[i] = k + } + + for _, k := range keys { + hash.Write(unsafeBytes(k)) + hash.Write(unsafeBytes("\x00")) + v, _ := call.Annotations.Get(k) + hash.Write(v) + hash.Write(unsafeBytes("\x00")) + } + var buf [sha1.Size]byte hash.Sum(buf[:0]) return string(buf[:])