Fix service controller not release loadBalancer issue in corner case.

This commit is contained in:
Hongcai Ren
2019-06-25 20:17:51 +08:00
committed by RainbowMango
parent 20b58990b9
commit 9618d1d955
2 changed files with 44 additions and 15 deletions

View File

@@ -833,6 +833,16 @@ func TestProcessServiceDeletion(t *testing.T) {
}
// Test cases:
// index finalizer timestamp wantLB | clean-up
// 0 0 0 0 | false (No finalizer, no clean up)
// 1 0 0 1 | false (Ignored as same with case 0)
// 2 0 1 0 | false (Ignored as same with case 0)
// 3 0 1 1 | false (Ignored as same with case 0)
// 4 1 0 0 | true
// 5 1 0 1 | false
// 6 1 1 0 | true (Service is deleted, needs clean up)
// 7 1 1 1 | true (Ignored as same with case 6)
func TestNeedsCleanup(t *testing.T) {
testCases := []struct {
desc string
@@ -840,27 +850,31 @@ func TestNeedsCleanup(t *testing.T) {
expectNeedsCleanup bool
}{
{
desc: "service without finalizer without timestamp",
desc: "service without finalizer",
svc: &v1.Service{},
expectNeedsCleanup: false,
},
{
desc: "service without finalizer with timestamp",
svc: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
DeletionTimestamp: &metav1.Time{
Time: time.Now(),
},
},
},
expectNeedsCleanup: false,
},
{
desc: "service with finalizer without timestamp",
desc: "service with finalizer without timestamp without LB",
svc: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Finalizers: []string{servicehelper.LoadBalancerCleanupFinalizer},
},
Spec: v1.ServiceSpec{
Type: v1.ServiceTypeNodePort,
},
},
expectNeedsCleanup: true,
},
{
desc: "service with finalizer without timestamp with LB",
svc: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Finalizers: []string{servicehelper.LoadBalancerCleanupFinalizer},
},
Spec: v1.ServiceSpec{
Type: v1.ServiceTypeLoadBalancer,
},
},
expectNeedsCleanup: false,
},
@@ -868,10 +882,10 @@ func TestNeedsCleanup(t *testing.T) {
desc: "service with finalizer with timestamp",
svc: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Finalizers: []string{servicehelper.LoadBalancerCleanupFinalizer},
DeletionTimestamp: &metav1.Time{
Time: time.Now(),
},
Finalizers: []string{servicehelper.LoadBalancerCleanupFinalizer, "unrelated"},
},
},
expectNeedsCleanup: true,