@@ -110,6 +110,9 @@ type Framework struct {
110
110
// the various afterEaches
111
111
afterEaches map [string ]AfterEachActionFunc
112
112
113
+ // beforeEachStarted indicates that BeforeEach has started
114
+ beforeEachStarted bool
115
+
113
116
// configuration for framework's client
114
117
Options Options
115
118
@@ -179,6 +182,8 @@ func NewFramework(baseName string, options Options, client clientset.Interface)
179
182
180
183
// BeforeEach gets a client and makes a namespace.
181
184
func (f * Framework ) BeforeEach () {
185
+ f .beforeEachStarted = true
186
+
182
187
// The fact that we need this feels like a bug in ginkgo.
183
188
// https://github.com/onsi/ginkgo/issues/222
184
189
f .cleanupHandle = AddCleanupAction (f .AfterEach )
@@ -356,8 +361,20 @@ func (f *Framework) AddAfterEach(name string, fn AfterEachActionFunc) {
356
361
357
362
// AfterEach deletes the namespace, after reading its events.
358
363
func (f * Framework ) AfterEach () {
364
+ // If BeforeEach never started AfterEach should be skipped.
365
+ // Currently some tests under e2e/storage have this condition.
366
+ if ! f .beforeEachStarted {
367
+ return
368
+ }
369
+
359
370
RemoveCleanupAction (f .cleanupHandle )
360
371
372
+ // This should not happen. Given ClientSet is a public field a test must have updated it!
373
+ // Error out early before any API calls during cleanup.
374
+ if f .ClientSet == nil {
375
+ Failf ("The framework ClientSet must not be nil at this point" )
376
+ }
377
+
361
378
// DeleteNamespace at the very end in defer, to avoid any
362
379
// expectation failures preventing deleting the namespace.
363
380
defer func () {
0 commit comments