mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 23:15:14 +00:00
Namespace controller must wait for terminating resources
This commit is contained in:
parent
f1eaa8a27b
commit
5f06138798
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user