Test namespace overlap in test-integration.sh

This commit is contained in:
Clayton Coleman 2015-02-16 16:29:11 -05:00
parent 7e07d711b8
commit eebe00c259

View File

@ -19,11 +19,11 @@ limitations under the License.
package main
import (
"fmt"
"io/ioutil"
"net"
"net/http"
"net/http/httptest"
"net/url"
"os"
"reflect"
"runtime"
@ -279,7 +279,7 @@ func runReplicationControllerTest(c *client.Client) {
}
glog.Infof("Creating replication controllers")
updated, err := c.ReplicationControllers(api.NamespaceDefault).Create(&controller)
updated, err := c.ReplicationControllers("test").Create(&controller)
if err != nil {
glog.Fatalf("Unexpected error: %v", err)
}
@ -291,7 +291,7 @@ func runReplicationControllerTest(c *client.Client) {
}
// wait for minions to indicate they have info about the desired pods
pods, err := c.Pods(api.NamespaceDefault).List(labels.Set(updated.Spec.Selector).AsSelector())
pods, err := c.Pods("test").List(labels.Set(updated.Spec.Selector).AsSelector())
if err != nil {
glog.Fatalf("FAILED: unable to get pods to list: %v", err)
}
@ -313,12 +313,15 @@ func runAPIVersionsTest(c *client.Client) {
glog.Infof("Version test passed")
}
func runSelfLinkTest(c *client.Client) {
func runSelfLinkTestOnNamespace(c *client.Client, namespace string) {
var svc api.Service
err := c.Post().Resource("services").Body(
err := c.Post().
NamespaceIfScoped(namespace, len(namespace) > 0).
Resource("services").Body(
&api.Service{
ObjectMeta: api.ObjectMeta{
Name: "selflinktest",
Name: "selflinktest",
Namespace: namespace,
Labels: map[string]string{
"name": "selflinktest",
},
@ -338,20 +341,18 @@ func runSelfLinkTest(c *client.Client) {
glog.Fatalf("Failed creating selflinktest service: %v", err)
}
// TODO: this is not namespace aware
link, _ := url.Parse(svc.SelfLink)
err = c.Get().AbsPath(link.Path).Do().Into(&svc)
err = c.Get().RequestURI(svc.SelfLink).Do().Into(&svc)
if err != nil {
glog.Fatalf("Failed listing service with supplied self link '%v': %v", svc.SelfLink, err)
}
var svcList api.ServiceList
err = c.Get().Resource("services").Do().Into(&svcList)
err = c.Get().NamespaceIfScoped(namespace, len(namespace) > 0).Resource("services").Do().Into(&svcList)
if err != nil {
glog.Fatalf("Failed listing services: %v", err)
}
link, _ = url.Parse(svcList.SelfLink)
err = c.Get().AbsPath(link.Path).Do().Into(&svcList)
err = c.Get().RequestURI(svcList.SelfLink).Do().Into(&svcList)
if err != nil {
glog.Fatalf("Failed listing services with supplied self link '%v': %v", svcList.SelfLink, err)
}
@ -363,17 +364,16 @@ func runSelfLinkTest(c *client.Client) {
continue
}
found = true
link, _ = url.Parse(item.SelfLink)
err = c.Get().AbsPath(link.Path).Do().Into(&svc)
err = c.Get().RequestURI(item.SelfLink).Do().Into(&svc)
if err != nil {
glog.Fatalf("Failed listing service with supplied self link '%v': %v", item.SelfLink, err)
}
break
}
if !found {
glog.Fatalf("never found selflinktest service")
glog.Fatalf("never found selflinktest service in namespace %s", namespace)
}
glog.Infof("Self link test passed")
glog.Infof("Self link test passed in namespace %s", namespace)
// TODO: Should test PUT at some point, too.
}
@ -571,6 +571,24 @@ func runServiceTest(client *client.Client) {
if err != nil {
glog.Fatalf("Failed to create service: %v, %v", svc1, err)
}
// create an identical service in the default namespace
svc3 := &api.Service{
ObjectMeta: api.ObjectMeta{Name: "service1"},
Spec: api.ServiceSpec{
Selector: map[string]string{
"name": "thisisalonglabel",
},
Port: 8080,
Protocol: "TCP",
SessionAffinity: "None",
},
}
svc3, err = client.Services("other").Create(svc3)
if err != nil {
glog.Fatalf("Failed to create service: %v, %v", svc3, err)
}
if err := wait.Poll(time.Second, time.Second*20, endpointsSet(client, svc1.Namespace, svc1.Name, 1)); err != nil {
glog.Fatalf("FAILED: unexpected endpoints: %v", err)
}
@ -593,6 +611,23 @@ func runServiceTest(client *client.Client) {
if err := wait.Poll(time.Second, time.Second*20, endpointsSet(client, svc2.Namespace, svc2.Name, 1)); err != nil {
glog.Fatalf("FAILED: unexpected endpoints: %v", err)
}
if ok, err := endpointsSet(client, svc3.Namespace, svc3.Name, 0)(); !ok || err != nil {
glog.Fatalf("FAILED: service in other namespace should have no endpoints: %v %v", ok, err)
}
svcList, err := client.Services(api.NamespaceAll).List(labels.Everything())
if err != nil {
glog.Fatalf("Failed to list services across namespaces: %v", err)
}
names := util.NewStringSet()
for _, svc := range svcList.Items {
names.Insert(fmt.Sprintf("%s/%s", svc.Namespace, svc.Name))
}
if !names.HasAll("default/kubernetes", "default/kubernetes-ro", "default/service1", "default/service2", "other/service1") {
glog.Fatalf("Unexpected service list: %#v", names)
}
glog.Info("Service test passed.")
}
@ -629,7 +664,10 @@ func main() {
runServiceTest,
runAPIVersionsTest,
runMasterServiceTest,
runSelfLinkTest,
func(c *client.Client) {
runSelfLinkTestOnNamespace(c, "")
runSelfLinkTestOnNamespace(c, "other")
},
}
var wg sync.WaitGroup
wg.Add(len(testFuncs))