mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +00:00
Test namespace overlap in test-integration.sh
This commit is contained in:
parent
7e07d711b8
commit
eebe00c259
@ -19,11 +19,11 @@ limitations under the License.
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/url"
|
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -279,7 +279,7 @@ func runReplicationControllerTest(c *client.Client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
glog.Infof("Creating replication controllers")
|
glog.Infof("Creating replication controllers")
|
||||||
updated, err := c.ReplicationControllers(api.NamespaceDefault).Create(&controller)
|
updated, err := c.ReplicationControllers("test").Create(&controller)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Unexpected error: %v", err)
|
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
|
// 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 {
|
if err != nil {
|
||||||
glog.Fatalf("FAILED: unable to get pods to list: %v", err)
|
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")
|
glog.Infof("Version test passed")
|
||||||
}
|
}
|
||||||
|
|
||||||
func runSelfLinkTest(c *client.Client) {
|
func runSelfLinkTestOnNamespace(c *client.Client, namespace string) {
|
||||||
var svc api.Service
|
var svc api.Service
|
||||||
err := c.Post().Resource("services").Body(
|
err := c.Post().
|
||||||
|
NamespaceIfScoped(namespace, len(namespace) > 0).
|
||||||
|
Resource("services").Body(
|
||||||
&api.Service{
|
&api.Service{
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: "selflinktest",
|
Name: "selflinktest",
|
||||||
|
Namespace: namespace,
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
"name": "selflinktest",
|
"name": "selflinktest",
|
||||||
},
|
},
|
||||||
@ -338,20 +341,18 @@ func runSelfLinkTest(c *client.Client) {
|
|||||||
glog.Fatalf("Failed creating selflinktest service: %v", err)
|
glog.Fatalf("Failed creating selflinktest service: %v", err)
|
||||||
}
|
}
|
||||||
// TODO: this is not namespace aware
|
// TODO: this is not namespace aware
|
||||||
link, _ := url.Parse(svc.SelfLink)
|
err = c.Get().RequestURI(svc.SelfLink).Do().Into(&svc)
|
||||||
err = c.Get().AbsPath(link.Path).Do().Into(&svc)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Failed listing service with supplied self link '%v': %v", svc.SelfLink, err)
|
glog.Fatalf("Failed listing service with supplied self link '%v': %v", svc.SelfLink, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var svcList api.ServiceList
|
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 {
|
if err != nil {
|
||||||
glog.Fatalf("Failed listing services: %v", err)
|
glog.Fatalf("Failed listing services: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
link, _ = url.Parse(svcList.SelfLink)
|
err = c.Get().RequestURI(svcList.SelfLink).Do().Into(&svcList)
|
||||||
err = c.Get().AbsPath(link.Path).Do().Into(&svcList)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Failed listing services with supplied self link '%v': %v", svcList.SelfLink, err)
|
glog.Fatalf("Failed listing services with supplied self link '%v': %v", svcList.SelfLink, err)
|
||||||
}
|
}
|
||||||
@ -363,17 +364,16 @@ func runSelfLinkTest(c *client.Client) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
found = true
|
found = true
|
||||||
link, _ = url.Parse(item.SelfLink)
|
err = c.Get().RequestURI(item.SelfLink).Do().Into(&svc)
|
||||||
err = c.Get().AbsPath(link.Path).Do().Into(&svc)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Failed listing service with supplied self link '%v': %v", item.SelfLink, err)
|
glog.Fatalf("Failed listing service with supplied self link '%v': %v", item.SelfLink, err)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if !found {
|
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.
|
// TODO: Should test PUT at some point, too.
|
||||||
}
|
}
|
||||||
@ -571,6 +571,24 @@ func runServiceTest(client *client.Client) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Failed to create service: %v, %v", svc1, err)
|
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 {
|
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)
|
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 {
|
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)
|
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.")
|
glog.Info("Service test passed.")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -629,7 +664,10 @@ func main() {
|
|||||||
runServiceTest,
|
runServiceTest,
|
||||||
runAPIVersionsTest,
|
runAPIVersionsTest,
|
||||||
runMasterServiceTest,
|
runMasterServiceTest,
|
||||||
runSelfLinkTest,
|
func(c *client.Client) {
|
||||||
|
runSelfLinkTestOnNamespace(c, "")
|
||||||
|
runSelfLinkTestOnNamespace(c, "other")
|
||||||
|
},
|
||||||
}
|
}
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(len(testFuncs))
|
wg.Add(len(testFuncs))
|
||||||
|
Loading…
Reference in New Issue
Block a user