From 775c5a2652e2671c4bd48cd4e041a3f22fd348c6 Mon Sep 17 00:00:00 2001 From: derekwaynecarr Date: Mon, 14 Mar 2016 16:06:19 -0400 Subject: [PATCH] Reduce namespace deletion test flakes by forcing a cache refresh when a namespace is initially deleted --- .../pkg/admission/namespace/lifecycle/admission.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/plugin/pkg/admission/namespace/lifecycle/admission.go b/plugin/pkg/admission/namespace/lifecycle/admission.go index c42c172401de4..0e19de5d4e6af 100644 --- a/plugin/pkg/admission/namespace/lifecycle/admission.go +++ b/plugin/pkg/admission/namespace/lifecycle/admission.go @@ -57,6 +57,18 @@ func (l *lifecycle) Admit(a admission.Attributes) (err error) { // if we're here, then the API server has found a route, which means that if we have a non-empty namespace // its a namespaced resource. if len(a.GetNamespace()) == 0 || a.GetKind() == api.Kind("Namespace") { + // if a namespace is deleted, we want to prevent all further creates into it + // while it is undergoing termination. to reduce incidences where the cache + // is slow to update, we forcefully remove the namespace from our local cache. + // this will cause a live lookup of the namespace to get its latest state even + // before the watch notification is received. + if a.GetOperation() == admission.Delete { + l.store.Delete(&api.Namespace{ + ObjectMeta: api.ObjectMeta{ + Name: a.GetName(), + }, + }) + } return nil }