Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for ingress status update #535

Merged
merged 1 commit into from
Apr 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions core/pkg/ingress/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ func (s *statusSync) sync(key interface{}) error {
s.runLock.Lock()
defer s.runLock.Unlock()

if s.syncQueue.IsShuttingDown() {
glog.V(2).Infof("skipping Ingress status update (shutting down in progress)")
return nil
}

if !s.elector.IsLeader() {
glog.V(2).Infof("skipping Ingress status update (I am not the current leader)")
return nil
Expand Down Expand Up @@ -249,6 +254,7 @@ func (s *statusSync) updateStatus(newIPs []api.LoadBalancerIngress) {
ing := cur.(*extensions.Ingress)

if !class.IsValid(ing, s.Config.IngressClass, s.Config.DefaultIngressClass) {
wg.Done()
continue
}

Expand Down
64 changes: 46 additions & 18 deletions core/pkg/ingress/status/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ import (
"testing"
"time"

cache_store "k8s.io/ingress/core/pkg/cache"
"k8s.io/ingress/core/pkg/k8s"
"k8s.io/ingress/core/pkg/task"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/client/cache"
testclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
"k8s.io/kubernetes/pkg/util/sets"

cache_store "k8s.io/ingress/core/pkg/cache"
"k8s.io/ingress/core/pkg/ingress/annotations/class"
"k8s.io/ingress/core/pkg/k8s"
"k8s.io/ingress/core/pkg/task"
)

func buildLoadBalancerIngressByIP() loadBalancerIngressByIP {
Expand Down Expand Up @@ -150,6 +151,7 @@ func buildSimpleClientSet() *testclient.Clientset {
ObjectMeta: api.ObjectMeta{
Name: "ingress-controller-leader",
Namespace: api.NamespaceDefault,
SelfLink: "/api/v1/namespaces/default/endpoints/ingress-controller-leader",
},
}}},
&extensions.IngressList{Items: buildExtensionsIngresses()},
Expand Down Expand Up @@ -178,6 +180,25 @@ func buildExtensionsIngresses() []extensions.Ingress {
},
},
},
{
ObjectMeta: api.ObjectMeta{
Name: "foo_ingress_different_class",
Namespace: api.NamespaceDefault,
Annotations: map[string]string{
class.IngressKey: "no-nginx",
},
},
Status: extensions.IngressStatus{
LoadBalancer: api.LoadBalancerStatus{
Ingress: []api.LoadBalancerIngress{
{
IP: "0.0.0.0",
Hostname: "foo.bar.com",
},
},
},
},
},
{
ObjectMeta: api.ObjectMeta{
Name: "foo_ingress_2",
Expand All @@ -192,16 +213,13 @@ func buildExtensionsIngresses() []extensions.Ingress {
}
}

func buildIngressLIstener() cache_store.StoreToIngressLister {
func buildIngressListener() cache_store.StoreToIngressLister {
store := cache.NewStore(cache.MetaNamespaceKeyFunc)
ids := sets.NewString("foo_ingress_non_01")
for id := range ids {
store.Add(&extensions.Ingress{
ObjectMeta: api.ObjectMeta{
Name: id,
Namespace: api.NamespaceDefault,
}})
}
store.Add(&extensions.Ingress{
ObjectMeta: api.ObjectMeta{
Name: "foo_ingress_non_01",
Namespace: api.NamespaceDefault,
}})
store.Add(&extensions.Ingress{
ObjectMeta: api.ObjectMeta{
Name: "foo_ingress_1",
Expand Down Expand Up @@ -230,7 +248,7 @@ func buildStatusSync() statusSync {
Config: Config{
Client: buildSimpleClientSet(),
PublishService: api.NamespaceDefault + "/" + "foo",
IngressLister: buildIngressLIstener(),
IngressLister: buildIngressListener(),
},
}
}
Expand All @@ -240,9 +258,11 @@ func TestStatusActions(t *testing.T) {
os.Setenv("POD_NAME", "foo1")
os.Setenv("POD_NAMESPACE", api.NamespaceDefault)
c := Config{
Client: buildSimpleClientSet(),
PublishService: "",
IngressLister: buildIngressLIstener(),
Client: buildSimpleClientSet(),
PublishService: "",
IngressLister: buildIngressListener(),
DefaultIngressClass: "nginx",
IngressClass: "",
}
// create object
fkSync := NewStatusSyncer(c)
Expand All @@ -253,7 +273,7 @@ func TestStatusActions(t *testing.T) {
fk := fkSync.(statusSync)

ns := make(chan struct{})
// start it and wait for the election and syn actions
// start it and wait for the election and sync actions
go fk.Run(ns)
// wait for the election
time.Sleep(100 * time.Millisecond)
Expand Down Expand Up @@ -286,6 +306,14 @@ func TestStatusActions(t *testing.T) {
t.Fatalf("returned %v but expected %v", fooIngress2CurIPs, newIPs2)
}

oic, err := fk.Client.Extensions().Ingresses(api.NamespaceDefault).Get("foo_ingress_different_class")
if err != nil {
t.Fatalf("unexpected error")
}
if oic.Status.LoadBalancer.Ingress[0].IP != "0.0.0.0" && oic.Status.LoadBalancer.Ingress[0].Hostname != "foo.bar.com" {
t.Fatalf("invalid ingress status for rule with different class")
}

// end test
ns <- struct{}{}
}
Expand Down