Alter graceful deletion to not use TTL
Avoid TTL by deleting pods immediately when they aren't scheduled, and letting the Kubelet delete them otherwise. Ensure the Kubelet uses pod.Spec.TerminationGracePeriodSeconds when no pod.DeletionGracePeriodSeconds is available.
This commit is contained in:
@@ -121,8 +121,10 @@ func TestDelete(t *testing.T) {
|
||||
key = etcdtest.AddPrefix(key)
|
||||
test := resttest.New(t, storage, fakeEtcdClient.SetError)
|
||||
|
||||
expectedNode := "some-node"
|
||||
createFn := func() runtime.Object {
|
||||
pod := validChangedPod()
|
||||
pod.Spec.NodeName = expectedNode
|
||||
fakeEtcdClient.Data[key] = tools.EtcdResponseWithError{
|
||||
R: &etcd.Response{
|
||||
Node: &etcd.Node{
|
||||
@@ -137,9 +139,18 @@ func TestDelete(t *testing.T) {
|
||||
if fakeEtcdClient.Data[key].R.Node == nil {
|
||||
return false
|
||||
}
|
||||
return fakeEtcdClient.Data[key].R.Node.TTL != 0
|
||||
obj, err := latest.Codec.Decode([]byte(fakeEtcdClient.Data[key].R.Node.Value))
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
pod := obj.(*api.Pod)
|
||||
t.Logf("found object %#v", pod.ObjectMeta)
|
||||
return pod.DeletionTimestamp != nil && pod.DeletionGracePeriodSeconds != nil && *pod.DeletionGracePeriodSeconds != 0
|
||||
}
|
||||
test.TestDeleteGraceful(createFn, 30, gracefulSetFn)
|
||||
|
||||
expectedNode = ""
|
||||
test.TestDelete(createFn, gracefulSetFn)
|
||||
}
|
||||
|
||||
func expectPod(t *testing.T, out runtime.Object) (*api.Pod, bool) {
|
||||
|
@@ -92,22 +92,38 @@ func (podStrategy) CheckGracefulDelete(obj runtime.Object, options *api.DeleteOp
|
||||
if options == nil {
|
||||
return false
|
||||
}
|
||||
pod := obj.(*api.Pod)
|
||||
period := int64(0)
|
||||
// user has specified a value
|
||||
if options.GracePeriodSeconds != nil {
|
||||
period = *options.GracePeriodSeconds
|
||||
} else {
|
||||
// use the default value if set, or deletes the pod immediately (0)
|
||||
pod := obj.(*api.Pod)
|
||||
if pod.Spec.TerminationGracePeriodSeconds != nil {
|
||||
period = *pod.Spec.TerminationGracePeriodSeconds
|
||||
}
|
||||
}
|
||||
// if the pod is not scheduled, delete immediately
|
||||
if len(pod.Spec.NodeName) == 0 {
|
||||
period = 0
|
||||
}
|
||||
// ensure the options and the pod are in sync
|
||||
options.GracePeriodSeconds = &period
|
||||
return true
|
||||
}
|
||||
|
||||
type podStrategyWithoutGraceful struct {
|
||||
podStrategy
|
||||
}
|
||||
|
||||
// CheckGracefulDelete prohibits graceful deletion.
|
||||
func (podStrategyWithoutGraceful) CheckGracefulDelete(obj runtime.Object, options *api.DeleteOptions) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// StrategyWithoutGraceful implements the legacy instant delele behavior.
|
||||
var StrategyWithoutGraceful = podStrategyWithoutGraceful{Strategy}
|
||||
|
||||
type podStatusStrategy struct {
|
||||
podStrategy
|
||||
}
|
||||
|
Reference in New Issue
Block a user