From 5f061387982625c4372b0be506aeb45237bc25f0 Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Mon, 25 May 2015 15:39:40 -0400 Subject: [PATCH] Namespace controller must wait for terminating resources --- pkg/namespace/namespace_controller.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/pkg/namespace/namespace_controller.go b/pkg/namespace/namespace_controller.go index 1913457d45f..7557c4f9def 100644 --- a/pkg/namespace/namespace_controller.go +++ b/pkg/namespace/namespace_controller.go @@ -17,6 +17,7 @@ limitations under the License. package namespace import ( + "fmt" "time" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" @@ -119,7 +120,7 @@ func deleteAllContent(kubeClient client.Interface, namespace string) (err error) if err != nil { return err } - err = deletePods(kubeClient, namespace) + estimate, err := deletePods(kubeClient, namespace) if err != nil { return err } @@ -143,6 +144,10 @@ func deleteAllContent(kubeClient client.Interface, namespace string) (err error) if err != nil { return err } + + if estimate > 0 { + return fmt.Errorf("some resources are being gracefully deleted, estimate %d seconds", estimate) + } return nil } @@ -263,18 +268,25 @@ func deleteReplicationControllers(kubeClient client.Interface, ns string) error return nil } -func deletePods(kubeClient client.Interface, ns string) error { +func deletePods(kubeClient client.Interface, ns string) (int64, error) { items, err := kubeClient.Pods(ns).List(labels.Everything(), fields.Everything()) if err != nil { - return err + return 0, err } + estimate := int64(0) for i := range items.Items { + if items.Items[i].Spec.TerminationGracePeriodSeconds != nil { + grace := *items.Items[i].Spec.TerminationGracePeriodSeconds + if grace > estimate { + estimate = grace + } + } err := kubeClient.Pods(ns).Delete(items.Items[i].Name, nil) if err != nil { - return err + return 0, err } } - return nil + return estimate, nil } func deleteEvents(kubeClient client.Interface, ns string) error {