@@ -126,6 +126,10 @@ func (f *Framework) CreateNamespace(baseName string, labels map[string]string) (
126
126
func (f * Framework ) DeleteNamespace (namespace string , timeout time.Duration ) error {
127
127
startTime := time .Now ()
128
128
if err := f .ClientSet .CoreV1 ().Namespaces ().Delete (namespace , nil ); err != nil {
129
+ if apierrors .IsNotFound (err ) {
130
+ Logf ("Namespace %v was already deleted" , namespace )
131
+ return nil
132
+ }
129
133
return err
130
134
}
131
135
@@ -180,35 +184,28 @@ func (f *Framework) AfterEach() {
180
184
181
185
// DeleteNamespace at the very end in defer, to avoid any expectation
182
186
// failures preventing deleting the namespace.
183
- defer func () {
184
- nsDeletionErrors := map [string ]error {}
185
-
186
- if deleteNamespace {
187
- // TODO: skip namespace deletion
188
- for _ , ns := range f .namespacesToDelete {
189
- By (fmt .Sprintf ("Destroying namespace %q for this suite." , ns .Name ))
190
- if err := f .DeleteNamespace (ns .Name , 5 * time .Minute ); err != nil {
191
- if ! apierrors .IsNotFound (err ) {
192
- nsDeletionErrors [ns .Name ] = err
193
- } else {
194
- Logf ("Namespace %v was already deleted" , ns .Name )
195
- }
196
- }
187
+ nsDeletionErrors := map [string ]error {}
188
+
189
+ if deleteNamespace {
190
+ for _ , ns := range f .namespacesToDelete {
191
+ By (fmt .Sprintf ("Destroying namespace %q for this suite." , ns .Name ))
192
+ if err := f .DeleteNamespace (ns .Name , 5 * time .Minute ); err != nil {
193
+ nsDeletionErrors [ns .Name ] = err
197
194
}
198
195
}
196
+ }
199
197
200
- // Paranoia -- prevent reuse!
201
- f .Namespace = nil
202
- f .ClientSet = nil
203
- f .namespacesToDelete = nil
198
+ // Paranoia -- prevent reuse!
199
+ f .Namespace = nil
200
+ f .ClientSet = nil
201
+ f .namespacesToDelete = nil
204
202
205
- // if we had errors deleting, report them now.
206
- if len (nsDeletionErrors ) != 0 {
207
- messages := []string {}
208
- for namespaceKey , namespaceErr := range nsDeletionErrors {
209
- messages = append (messages , fmt .Sprintf ("Couldn't delete ns: %q: %s (%#v)" , namespaceKey , namespaceErr , namespaceErr ))
210
- }
211
- Failf (strings .Join (messages , "," ))
203
+ // if we had errors deleting, report them now.
204
+ if len (nsDeletionErrors ) != 0 {
205
+ messages := []string {}
206
+ for namespaceKey , namespaceErr := range nsDeletionErrors {
207
+ messages = append (messages , fmt .Sprintf ("Couldn't delete ns: %q: %s (%#v)" , namespaceKey , namespaceErr , namespaceErr ))
212
208
}
213
- }()
209
+ Failf (strings .Join (messages , "," ))
210
+ }
214
211
}
0 commit comments