Skip to content

Commit

Permalink
Enable LoadBalancer status check
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf committed Apr 21, 2020
1 parent 27e8da3 commit 4b7cf44
Showing 1 changed file with 6 additions and 30 deletions.
36 changes: 6 additions & 30 deletions pkg/l4/l4controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ package l4

import (
context2 "context"
"reflect"
"testing"
"time"

"k8s.io/client-go/kubernetes"
testing2 "k8s.io/client-go/testing"
"k8s.io/ingress-gce/pkg/loadbalancers"
"k8s.io/ingress-gce/pkg/neg/types"

Expand All @@ -42,8 +39,7 @@ import (
)

const (
clusterUID = "aaaaa"
resetLBStatus = "{\"status\":{\"loadBalancer\":{\"ingress\":null}}}"
clusterUID = "aaaaa"
)

func newServiceController() *L4Controller {
Expand Down Expand Up @@ -93,23 +89,6 @@ func getKeyForSvc(svc *api_v1.Service, t *testing.T) string {
return key
}

// validatePatchRequest validates that the given client patched the resource with the given change.
// This is needed because there is a bug in go-client test implementation where a patch operation cannot be used
// to delete fields - https://github.com/kubernetes/client-go/issues/607
// TODO remove this once https://github.com/kubernetes/client-go/issues/607 has been fixed.
func validatePatchRequest(client kubernetes.Interface, patchVal string, t *testing.T) {
fakeClient := client.(*fake.Clientset)
actionLen := len(fakeClient.Actions())
if actionLen == 0 {
t.Errorf("Expected atleast one action in fake client")
}
// The latest action should be the one setting status to the given value
patchAction := fakeClient.Actions()[actionLen-1].(testing2.PatchAction)
if !reflect.DeepEqual(patchAction.GetPatch(), []byte(patchVal)) {
t.Errorf("Expected patch '%s', got '%s'", patchVal, string(patchAction.GetPatch()))
}
}

func validateSvcStatus(svc *api_v1.Service, expectStatus bool, t *testing.T) {
if common.HasGivenFinalizer(svc.ObjectMeta, common.ILBFinalizerV2) != expectStatus {
t.Fatalf("Expected L4 finalizer present to be %v, but it was %v", expectStatus, !expectStatus)
Expand All @@ -120,8 +99,7 @@ func validateSvcStatus(svc *api_v1.Service, expectStatus bool, t *testing.T) {
}
}
if len(svc.Status.LoadBalancer.Ingress) > 0 && !expectStatus {
// TODO uncomment below once https://github.com/kubernetes/client-go/issues/607 has been fixed.
// t.Fatalf("Expected LoadBalancer status to be empty, Got %v", svc.Status.LoadBalancer)
t.Fatalf("Expected LoadBalancer status to be empty, Got %v", svc.Status.LoadBalancer)
}
}

Expand Down Expand Up @@ -165,8 +143,7 @@ func TestProcessCreateOrUpdate(t *testing.T) {
if err != nil {
t.Errorf("Failed to sync updated service %s, err %v", newSvc.Name, err)
}
// TODO remove this once https://github.com/kubernetes/client-go/issues/607 has been fixed.
validatePatchRequest(l4c.client, resetLBStatus, t)

// List the service and ensure that it contains the finalizer as well as Status field.
newSvc, err = l4c.client.CoreV1().Services(newSvc.Namespace).Get(context2.TODO(), newSvc.Name, v1.GetOptions{})
if err != nil {
Expand All @@ -184,7 +161,7 @@ func TestProcessDeletion(t *testing.T) {
if err != nil {
t.Errorf("Failed to sync newly added service %s, err %v", newSvc.Name, err)
}
// List the service and ensure that it contains the finalizer as well as Status field.
// List the service and ensure that it does not contain the finalizer or the status field
newSvc, err = l4c.client.CoreV1().Services(newSvc.Namespace).Get(context2.TODO(), newSvc.Name, v1.GetOptions{})
if err != nil {
t.Errorf("Failed to lookup service %s, err: %v", newSvc.Name, err)
Expand All @@ -201,9 +178,8 @@ func TestProcessDeletion(t *testing.T) {
if err != nil {
t.Errorf("Failed to sync updated service %s, err %v", newSvc.Name, err)
}
// TODO remove this once https://github.com/kubernetes/client-go/issues/607 has been fixed.
validatePatchRequest(l4c.client, resetLBStatus, t)
// List the service and ensure that it contains the finalizer as well as Status field.

// List the service and ensure that it does not contain the finalizer or the status field
newSvc, err = l4c.client.CoreV1().Services(newSvc.Namespace).Get(context2.TODO(), newSvc.Name, v1.GetOptions{})
if err != nil {
t.Errorf("Failed to lookup service %s, err: %v", newSvc.Name, err)
Expand Down

0 comments on commit 4b7cf44

Please sign in to comment.