mirror of https://github.com/k3s-io/k3s
Add e2e and integration tests.
parent
7146ec9d49
commit
35bd8d4a11
|
@ -98,6 +98,38 @@ func loadClientOrDie() *client.Client {
|
|||
return c
|
||||
}
|
||||
|
||||
func TestKubernetesROService(c *client.Client) bool {
|
||||
svc := api.ServiceList{}
|
||||
err := c.Get().
|
||||
Namespace("default").
|
||||
AbsPath("/api/v1beta1/proxy/services/kubernetes-ro/api/v1beta1/services").
|
||||
Do().
|
||||
Into(&svc)
|
||||
if err != nil {
|
||||
glog.Errorf("unexpected error listing services using ro service: %v", err)
|
||||
return false
|
||||
}
|
||||
var foundRW, foundRO bool
|
||||
for i := range svc.Items {
|
||||
if svc.Items[i].Name == "kubernetes" {
|
||||
foundRW = true
|
||||
}
|
||||
if svc.Items[i].Name == "kubernetes-ro" {
|
||||
foundRO = true
|
||||
}
|
||||
}
|
||||
if !foundRW {
|
||||
glog.Error("no RW service found")
|
||||
}
|
||||
if !foundRO {
|
||||
glog.Error("no RO service found")
|
||||
}
|
||||
if !foundRW || !foundRO {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func TestPodUpdate(c *client.Client) bool {
|
||||
podClient := c.Pods(api.NamespaceDefault)
|
||||
|
||||
|
@ -158,7 +190,8 @@ func main() {
|
|||
c := loadClientOrDie()
|
||||
|
||||
tests := []func(c *client.Client) bool{
|
||||
// TODO(brendandburns): fix this test and re-add it: TestPodUpdate,
|
||||
TestKubernetesROService,
|
||||
// TODO(brendandburns): fix this test and re-add it: TestPodUpdate,
|
||||
}
|
||||
|
||||
passed := true
|
||||
|
|
|
@ -27,6 +27,8 @@ import (
|
|||
"os"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -131,6 +133,16 @@ func startComponents(manifestURL string) (apiServerURL string) {
|
|||
if err != nil {
|
||||
glog.Fatalf("Unable to parse CIDR: %v", err)
|
||||
}
|
||||
glog.Infof("Using portalNet '%v'", portalNet)
|
||||
|
||||
host, port, err := net.SplitHostPort(strings.TrimLeft(apiServer.URL, "http://"))
|
||||
if err != nil {
|
||||
glog.Fatalf("Unable to parse URL '%v': %v", apiServer.URL, err)
|
||||
}
|
||||
portNumber, err := strconv.Atoi(port)
|
||||
if err != nil {
|
||||
glog.Fatalf("Nonnumeric port? %v", err)
|
||||
}
|
||||
mux := http.NewServeMux()
|
||||
// Create a master and install handlers into mux.
|
||||
master.New(&master.Config{
|
||||
|
@ -142,6 +154,10 @@ func startComponents(manifestURL string) (apiServerURL string) {
|
|||
Mux: mux,
|
||||
EnableLogsSupport: false,
|
||||
APIPrefix: "/api",
|
||||
|
||||
ReadWritePort: portNumber,
|
||||
ReadOnlyPort: portNumber,
|
||||
PublicAddress: host,
|
||||
})
|
||||
handler.delegate = mux
|
||||
|
||||
|
@ -342,6 +358,68 @@ func runAtomicPutTest(c *client.Client) {
|
|||
glog.Info("Atomic PUTs work.")
|
||||
}
|
||||
|
||||
func runMasterServiceTest(client *client.Client) {
|
||||
time.Sleep(12 * time.Second)
|
||||
var svcList api.ServiceList
|
||||
err := client.Get().
|
||||
Namespace("default").
|
||||
Path("services").
|
||||
Do().
|
||||
Into(&svcList)
|
||||
if err != nil {
|
||||
glog.Fatalf("unexpected error listing services: %v", err)
|
||||
}
|
||||
var foundRW, foundRO bool
|
||||
found := util.StringSet{}
|
||||
for i := range svcList.Items {
|
||||
found.Insert(svcList.Items[i].Name)
|
||||
if svcList.Items[i].Name == "kubernetes" {
|
||||
foundRW = true
|
||||
}
|
||||
if svcList.Items[i].Name == "kubernetes-ro" {
|
||||
foundRO = true
|
||||
}
|
||||
}
|
||||
if foundRW {
|
||||
var ep api.Endpoints
|
||||
err := client.Get().
|
||||
Namespace("default").
|
||||
Path("endpoints").
|
||||
Path("kubernetes").
|
||||
Do().
|
||||
Into(&ep)
|
||||
if err != nil {
|
||||
glog.Fatalf("unexpected error listing endpoints for kubernetes service: %v", err)
|
||||
}
|
||||
if len(ep.Endpoints) == 0 {
|
||||
glog.Fatalf("no endpoints for kubernetes service: %v", ep)
|
||||
}
|
||||
} else {
|
||||
glog.Errorf("no RW service found: %v", found)
|
||||
}
|
||||
if foundRO {
|
||||
var ep api.Endpoints
|
||||
err := client.Get().
|
||||
Namespace("default").
|
||||
Path("endpoints").
|
||||
Path("kubernetes-ro").
|
||||
Do().
|
||||
Into(&ep)
|
||||
if err != nil {
|
||||
glog.Fatalf("unexpected error listing endpoints for kubernetes service: %v", err)
|
||||
}
|
||||
if len(ep.Endpoints) == 0 {
|
||||
glog.Fatalf("no endpoints for kubernetes service: %v", ep)
|
||||
}
|
||||
} else {
|
||||
glog.Errorf("no RO service found: %v", found)
|
||||
}
|
||||
if !foundRW || !foundRO {
|
||||
glog.Fatalf("Kubernetes service test failed: %v", found)
|
||||
}
|
||||
glog.Infof("Master service test passed.")
|
||||
}
|
||||
|
||||
func runServiceTest(client *client.Client) {
|
||||
pod := api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
|
@ -438,6 +516,7 @@ func main() {
|
|||
runAtomicPutTest,
|
||||
runServiceTest,
|
||||
runAPIVersionsTest,
|
||||
runMasterServiceTest,
|
||||
}
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(len(testFuncs))
|
||||
|
|
|
@ -19,6 +19,7 @@ limitations under the License.
|
|||
package integration
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"reflect"
|
||||
|
@ -29,6 +30,8 @@ import (
|
|||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/master"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/version"
|
||||
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -41,8 +44,14 @@ func TestClient(t *testing.T) {
|
|||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
mux := http.NewServeMux()
|
||||
|
||||
_, portalNet, err := net.ParseCIDR("10.0.0.0/24")
|
||||
if err != nil {
|
||||
glog.Fatalf("Unable to parse CIDR: %v", err)
|
||||
}
|
||||
master.New(&master.Config{
|
||||
EtcdHelper: helper,
|
||||
PortalNet: portalNet,
|
||||
Mux: mux,
|
||||
EnableLogsSupport: false,
|
||||
EnableUISupport: false,
|
||||
|
|
Loading…
Reference in New Issue