2014-06-06 23:40:48 +00:00
|
|
|
/*
|
|
|
|
Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
2014-06-11 20:03:46 +00:00
|
|
|
|
2014-06-06 23:40:48 +00:00
|
|
|
// A basic integration test for the service.
|
|
|
|
// Assumes that there is a pre-existing etcd server running on localhost.
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-03-09 22:46:47 +00:00
|
|
|
"errors"
|
2015-02-16 21:29:11 +00:00
|
|
|
"fmt"
|
2014-06-06 23:40:48 +00:00
|
|
|
"io/ioutil"
|
2014-10-04 04:34:30 +00:00
|
|
|
"net"
|
2014-06-24 23:31:33 +00:00
|
|
|
"net/http"
|
2014-06-06 23:40:48 +00:00
|
|
|
"net/http/httptest"
|
2015-01-12 00:40:06 +00:00
|
|
|
"os"
|
2014-07-02 20:51:27 +00:00
|
|
|
"reflect"
|
2014-06-27 03:24:10 +00:00
|
|
|
"runtime"
|
2014-10-28 00:57:28 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2014-07-02 20:51:27 +00:00
|
|
|
"sync"
|
2014-06-06 23:40:48 +00:00
|
|
|
"time"
|
|
|
|
|
2015-02-07 21:30:53 +00:00
|
|
|
kubeletapp "github.com/GoogleCloudPlatform/kubernetes/cmd/kubelet/app"
|
2014-06-06 23:40:48 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
2015-03-09 22:46:47 +00:00
|
|
|
apierrors "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
2014-09-11 17:02:53 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
2015-03-24 17:24:07 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
|
2014-11-02 06:50:00 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
|
2014-06-11 20:03:46 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
2015-03-23 16:31:50 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
|
2014-12-19 09:27:01 +00:00
|
|
|
nodeControllerPkg "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/controller"
|
2014-10-22 01:21:44 +00:00
|
|
|
replicationControllerPkg "github.com/GoogleCloudPlatform/kubernetes/pkg/controller"
|
2015-03-09 22:46:47 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet"
|
2015-03-10 05:39:00 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/cadvisor"
|
2014-09-09 04:33:17 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools"
|
2014-07-01 20:30:19 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
2014-06-24 01:28:06 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/master"
|
2015-01-25 03:22:18 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/probe"
|
2014-10-03 22:27:22 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/service"
|
2014-06-25 03:51:57 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
2014-08-18 21:42:08 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/wait"
|
2015-03-19 05:18:31 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume/empty_dir"
|
2015-01-07 19:33:21 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/admission/admit"
|
2014-08-21 20:35:50 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler"
|
2015-02-02 18:32:31 +00:00
|
|
|
_ "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/algorithmprovider"
|
2014-08-21 20:35:50 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/factory"
|
|
|
|
|
2014-06-06 23:40:48 +00:00
|
|
|
"github.com/coreos/go-etcd/etcd"
|
2014-06-25 03:51:57 +00:00
|
|
|
"github.com/golang/glog"
|
2015-03-18 08:21:10 +00:00
|
|
|
"github.com/spf13/pflag"
|
2014-06-06 23:40:48 +00:00
|
|
|
)
|
|
|
|
|
2014-07-01 20:30:19 +00:00
|
|
|
var (
|
2014-09-09 04:33:17 +00:00
|
|
|
fakeDocker1, fakeDocker2 dockertools.FakeDockerClient
|
2015-03-18 08:21:10 +00:00
|
|
|
// API version that should be used by the client to talk to the server.
|
|
|
|
apiVersion string
|
2014-07-01 20:30:19 +00:00
|
|
|
)
|
2014-06-27 22:02:06 +00:00
|
|
|
|
2014-10-10 22:19:23 +00:00
|
|
|
type fakeKubeletClient struct{}
|
2014-07-02 00:08:32 +00:00
|
|
|
|
2015-01-14 02:11:24 +00:00
|
|
|
func (fakeKubeletClient) GetPodStatus(host, podNamespace, podID string) (api.PodStatusResult, error) {
|
2014-12-21 02:49:10 +00:00
|
|
|
glog.V(3).Infof("Trying to get container info for %v/%v/%v", host, podNamespace, podID)
|
2014-07-02 00:08:32 +00:00
|
|
|
// This is a horrible hack to get around the fact that we can't provide
|
|
|
|
// different port numbers per kubelet...
|
|
|
|
var c client.PodInfoGetter
|
|
|
|
switch host {
|
|
|
|
case "localhost":
|
2014-10-10 22:19:23 +00:00
|
|
|
c = &client.HTTPKubeletClient{
|
2014-07-02 00:08:32 +00:00
|
|
|
Client: http.DefaultClient,
|
|
|
|
Port: 10250,
|
|
|
|
}
|
2015-01-28 22:39:57 +00:00
|
|
|
case "127.0.0.1":
|
2014-10-10 22:19:23 +00:00
|
|
|
c = &client.HTTPKubeletClient{
|
2014-07-02 00:08:32 +00:00
|
|
|
Client: http.DefaultClient,
|
|
|
|
Port: 10251,
|
|
|
|
}
|
|
|
|
default:
|
2014-10-15 18:56:19 +00:00
|
|
|
glog.Fatalf("Can't get info for: '%v', '%v - %v'", host, podNamespace, podID)
|
2014-07-02 00:08:32 +00:00
|
|
|
}
|
2015-02-09 19:30:05 +00:00
|
|
|
r, err := c.GetPodStatus("127.0.0.1", podNamespace, podID)
|
2015-01-28 22:39:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return r, err
|
|
|
|
}
|
|
|
|
r.Status.PodIP = "1.2.3.4"
|
2015-03-25 11:09:35 +00:00
|
|
|
for i := range r.Status.ContainerStatuses {
|
|
|
|
r.Status.ContainerStatuses[i].Ready = true
|
2015-01-28 22:39:57 +00:00
|
|
|
}
|
|
|
|
return r, nil
|
2014-07-02 00:08:32 +00:00
|
|
|
}
|
|
|
|
|
2015-03-02 00:34:48 +00:00
|
|
|
func (fakeKubeletClient) GetNodeInfo(host string) (api.NodeInfo, error) {
|
|
|
|
return api.NodeInfo{}, nil
|
|
|
|
}
|
|
|
|
|
2015-03-23 18:42:39 +00:00
|
|
|
func (fakeKubeletClient) GetConnectionInfo(host string) (string, uint, http.RoundTripper, error) {
|
|
|
|
return "", 0, nil, errors.New("Not Implemented")
|
|
|
|
}
|
|
|
|
|
2015-01-31 01:03:57 +00:00
|
|
|
func (fakeKubeletClient) HealthCheck(host string) (probe.Result, error) {
|
2015-01-27 18:22:53 +00:00
|
|
|
return probe.Success, nil
|
2014-10-10 22:19:23 +00:00
|
|
|
}
|
|
|
|
|
2014-07-18 20:22:26 +00:00
|
|
|
type delegateHandler struct {
|
|
|
|
delegate http.Handler
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *delegateHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|
|
|
if h.delegate != nil {
|
|
|
|
h.delegate.ServeHTTP(w, req)
|
2014-07-26 23:09:15 +00:00
|
|
|
return
|
2014-07-18 20:22:26 +00:00
|
|
|
}
|
|
|
|
w.WriteHeader(http.StatusNotFound)
|
|
|
|
}
|
|
|
|
|
2015-03-24 10:10:26 +00:00
|
|
|
func startComponents(firstManifestURL, secondManifestURL, apiVersion string) (string, string) {
|
2014-06-06 23:40:48 +00:00
|
|
|
// Setup
|
2015-02-09 19:30:05 +00:00
|
|
|
servers := []string{}
|
2014-06-25 03:51:57 +00:00
|
|
|
glog.Infof("Creating etcd client pointing to %v", servers)
|
2015-01-28 22:39:57 +00:00
|
|
|
machineList := []string{"localhost", "127.0.0.1"}
|
2014-06-06 23:40:48 +00:00
|
|
|
|
2014-07-18 20:22:26 +00:00
|
|
|
handler := delegateHandler{}
|
2014-08-09 21:12:55 +00:00
|
|
|
apiServer := httptest.NewServer(&handler)
|
2014-07-15 20:24:41 +00:00
|
|
|
|
|
|
|
etcdClient := etcd.NewClient(servers)
|
2014-11-11 05:15:36 +00:00
|
|
|
sleep := 4 * time.Second
|
|
|
|
ok := false
|
|
|
|
for i := 0; i < 3; i++ {
|
|
|
|
keys, err := etcdClient.Get("/", false, false)
|
|
|
|
if err != nil {
|
|
|
|
glog.Warningf("Unable to list root etcd keys: %v", err)
|
|
|
|
if i < 2 {
|
|
|
|
time.Sleep(sleep)
|
|
|
|
sleep = sleep * sleep
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
for _, node := range keys.Node.Nodes {
|
|
|
|
if _, err := etcdClient.Delete(node.Key, true); err != nil {
|
|
|
|
glog.Fatalf("Unable delete key: %v", err)
|
|
|
|
}
|
2014-08-28 04:32:04 +00:00
|
|
|
}
|
2014-11-11 05:15:36 +00:00
|
|
|
ok = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if !ok {
|
|
|
|
glog.Fatalf("Failed to connect to etcd")
|
2014-08-28 04:32:04 +00:00
|
|
|
}
|
2014-07-15 20:24:41 +00:00
|
|
|
|
2015-03-18 08:21:10 +00:00
|
|
|
cl := client.NewOrDie(&client.Config{Host: apiServer.URL, Version: apiVersion})
|
2014-07-18 20:22:26 +00:00
|
|
|
|
2014-09-26 01:11:01 +00:00
|
|
|
helper, err := master.NewEtcdHelper(etcdClient, "")
|
2014-09-11 23:01:29 +00:00
|
|
|
if err != nil {
|
|
|
|
glog.Fatalf("Unable to get etcd helper: %v", err)
|
|
|
|
}
|
|
|
|
|
2014-07-18 20:22:26 +00:00
|
|
|
// Master
|
2014-10-28 00:57:28 +00:00
|
|
|
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)
|
|
|
|
}
|
2014-10-22 01:21:44 +00:00
|
|
|
|
2015-02-09 19:30:05 +00:00
|
|
|
publicAddress := net.ParseIP(host)
|
|
|
|
if publicAddress == nil {
|
|
|
|
glog.Fatalf("no public address for %s", host)
|
|
|
|
}
|
|
|
|
|
2014-10-23 20:56:18 +00:00
|
|
|
// Create a master and install handlers into mux.
|
2014-10-28 20:02:19 +00:00
|
|
|
m := master.New(&master.Config{
|
2014-10-23 20:56:18 +00:00
|
|
|
EtcdHelper: helper,
|
|
|
|
KubeletClient: fakeKubeletClient{},
|
|
|
|
EnableLogsSupport: false,
|
2015-03-13 15:44:11 +00:00
|
|
|
EnableProfiling: true,
|
2014-10-23 20:56:18 +00:00
|
|
|
APIPrefix: "/api",
|
2014-11-02 06:50:00 +00:00
|
|
|
Authorizer: apiserver.NewAlwaysAllowAuthorizer(),
|
2015-01-07 19:33:21 +00:00
|
|
|
AdmissionControl: admit.NewAlwaysAdmit(),
|
2015-01-06 19:26:17 +00:00
|
|
|
ReadWritePort: portNumber,
|
|
|
|
ReadOnlyPort: portNumber,
|
2015-02-09 19:30:05 +00:00
|
|
|
PublicAddress: publicAddress,
|
2015-01-28 22:39:57 +00:00
|
|
|
CacheTimeout: 2 * time.Second,
|
2015-03-18 08:21:10 +00:00
|
|
|
EnableV1Beta3: true,
|
2014-10-23 20:56:18 +00:00
|
|
|
})
|
2014-10-28 20:02:19 +00:00
|
|
|
handler.delegate = m.Handler
|
2014-07-18 20:22:26 +00:00
|
|
|
|
2014-08-21 20:35:50 +00:00
|
|
|
// Scheduler
|
2014-11-19 16:16:25 +00:00
|
|
|
schedulerConfigFactory := factory.NewConfigFactory(cl)
|
2014-12-10 04:25:45 +00:00
|
|
|
schedulerConfig, err := schedulerConfigFactory.Create()
|
2014-11-19 16:16:25 +00:00
|
|
|
if err != nil {
|
2015-01-04 04:51:14 +00:00
|
|
|
glog.Fatalf("Couldn't create scheduler config: %v", err)
|
2014-11-19 16:16:25 +00:00
|
|
|
}
|
2014-10-07 20:10:58 +00:00
|
|
|
scheduler.New(schedulerConfig).Run()
|
2014-08-21 20:35:50 +00:00
|
|
|
|
2014-10-03 22:27:22 +00:00
|
|
|
endpoints := service.NewEndpointController(cl)
|
2015-03-23 03:06:12 +00:00
|
|
|
// ensure the service endpoints are sync'd several times within the window that the integration tests wait
|
|
|
|
go util.Forever(func() { endpoints.SyncServiceEndpoints() }, time.Second*4)
|
2014-10-03 22:27:22 +00:00
|
|
|
|
2014-10-22 01:21:44 +00:00
|
|
|
controllerManager := replicationControllerPkg.NewReplicationManager(cl)
|
2014-07-20 19:00:52 +00:00
|
|
|
|
2015-02-13 19:57:27 +00:00
|
|
|
// TODO: Write an integration test for the replication controllers watch.
|
|
|
|
controllerManager.Run(1 * time.Second)
|
2014-06-06 23:40:48 +00:00
|
|
|
|
2015-03-24 17:24:07 +00:00
|
|
|
nodeResources := &api.NodeResources{
|
|
|
|
Capacity: api.ResourceList{
|
|
|
|
api.ResourceName(api.ResourceCPU): resource.MustParse("10"),
|
|
|
|
api.ResourceName(api.ResourceMemory): resource.MustParse("10G"),
|
|
|
|
}}
|
2015-02-07 19:53:42 +00:00
|
|
|
|
2015-03-23 16:31:50 +00:00
|
|
|
nodeController := nodeControllerPkg.NewNodeController(nil, "", machineList, nodeResources, cl, fakeKubeletClient{},
|
|
|
|
record.FromSource(api.EventSource{Component: "controllermanager"}), 10, 5*time.Minute)
|
2015-02-23 21:04:45 +00:00
|
|
|
nodeController.Run(5*time.Second, true, false)
|
2015-03-10 05:39:00 +00:00
|
|
|
cadvisorInterface := new(cadvisor.Fake)
|
2014-10-22 01:21:44 +00:00
|
|
|
|
2014-07-15 20:24:41 +00:00
|
|
|
// Kubelet (localhost)
|
2015-03-09 22:46:47 +00:00
|
|
|
testRootDir := makeTempDirOrDie("kubelet_integ_1.", "")
|
|
|
|
configFilePath := makeTempDirOrDie("config", testRootDir)
|
2015-01-12 00:40:06 +00:00
|
|
|
glog.Infof("Using %s as root dir for kubelet #1", testRootDir)
|
2015-03-23 22:31:13 +00:00
|
|
|
kcfg := kubeletapp.SimpleKubelet(cl, &fakeDocker1, machineList[0], testRootDir, firstManifestURL, "127.0.0.1", 10250, api.NamespaceDefault, empty_dir.ProbeVolumePlugins(), nil, cadvisorInterface, configFilePath, nil)
|
2015-03-23 03:02:18 +00:00
|
|
|
kubeletapp.RunKubelet(kcfg)
|
2014-07-15 20:24:41 +00:00
|
|
|
// Kubelet (machine)
|
2014-06-29 05:16:26 +00:00
|
|
|
// Create a second kubelet so that the guestbook example's two redis slaves both
|
2014-06-24 01:28:06 +00:00
|
|
|
// have a place they can schedule.
|
2015-03-09 22:46:47 +00:00
|
|
|
testRootDir = makeTempDirOrDie("kubelet_integ_2.", "")
|
2015-01-12 00:40:06 +00:00
|
|
|
glog.Infof("Using %s as root dir for kubelet #2", testRootDir)
|
2015-03-23 22:31:13 +00:00
|
|
|
kcfg = kubeletapp.SimpleKubelet(cl, &fakeDocker2, machineList[1], testRootDir, secondManifestURL, "127.0.0.1", 10251, api.NamespaceDefault, empty_dir.ProbeVolumePlugins(), nil, cadvisorInterface, "", nil)
|
2015-03-23 03:02:18 +00:00
|
|
|
kubeletapp.RunKubelet(kcfg)
|
2015-03-09 22:46:47 +00:00
|
|
|
return apiServer.URL, configFilePath
|
2014-07-01 20:30:19 +00:00
|
|
|
}
|
2014-06-06 23:40:48 +00:00
|
|
|
|
2015-03-09 22:46:47 +00:00
|
|
|
func makeTempDirOrDie(prefix string, baseDir string) string {
|
|
|
|
if baseDir == "" {
|
|
|
|
baseDir = "/tmp"
|
|
|
|
}
|
|
|
|
tempDir, err := ioutil.TempDir(baseDir, prefix)
|
2015-01-12 00:40:06 +00:00
|
|
|
if err != nil {
|
|
|
|
glog.Fatalf("Can't make a temp rootdir: %v", err)
|
|
|
|
}
|
|
|
|
if err = os.MkdirAll(tempDir, 0750); err != nil {
|
|
|
|
glog.Fatalf("Can't mkdir(%q): %v", tempDir, err)
|
|
|
|
}
|
|
|
|
return tempDir
|
|
|
|
}
|
|
|
|
|
2014-08-18 21:42:08 +00:00
|
|
|
// podsOnMinions returns true when all of the selected pods exist on a minion.
|
|
|
|
func podsOnMinions(c *client.Client, pods api.PodList) wait.ConditionFunc {
|
2014-10-10 22:19:23 +00:00
|
|
|
podInfo := fakeKubeletClient{}
|
2014-08-18 21:42:08 +00:00
|
|
|
return func() (bool, error) {
|
|
|
|
for i := range pods.Items {
|
2014-11-13 15:52:13 +00:00
|
|
|
host, id, namespace := pods.Items[i].Status.Host, pods.Items[i].Name, pods.Items[i].Namespace
|
2015-02-18 21:20:42 +00:00
|
|
|
glog.Infof("Check whether pod %s.%s exists on node %q", id, namespace, host)
|
2014-08-18 21:42:08 +00:00
|
|
|
if len(host) == 0 {
|
2015-02-18 21:20:42 +00:00
|
|
|
glog.Infof("Pod %s.%s is not bound to a host yet", id, namespace)
|
2014-08-18 21:42:08 +00:00
|
|
|
return false, nil
|
|
|
|
}
|
2015-01-14 02:11:24 +00:00
|
|
|
if _, err := podInfo.GetPodStatus(host, namespace, id); err != nil {
|
2015-02-09 21:55:36 +00:00
|
|
|
glog.Infof("GetPodStatus error: %v", err)
|
2014-08-18 21:42:08 +00:00
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-23 21:14:15 +00:00
|
|
|
func endpointsSet(c *client.Client, serviceNamespace, serviceID string, endpointCount int) wait.ConditionFunc {
|
2014-10-03 03:24:30 +00:00
|
|
|
return func() (bool, error) {
|
2014-10-23 21:14:15 +00:00
|
|
|
endpoints, err := c.Endpoints(serviceNamespace).Get(serviceID)
|
2014-10-03 03:24:30 +00:00
|
|
|
if err != nil {
|
2015-02-27 02:02:04 +00:00
|
|
|
glog.Infof("Error on creating endpoints: %v", err)
|
2014-10-03 03:24:30 +00:00
|
|
|
return false, nil
|
|
|
|
}
|
2015-03-20 21:24:43 +00:00
|
|
|
count := 0
|
|
|
|
for _, ss := range endpoints.Subsets {
|
|
|
|
for _, addr := range ss.Addresses {
|
|
|
|
for _, port := range ss.Ports {
|
|
|
|
count++
|
|
|
|
glog.Infof("%s/%s endpoint: %s:%d %#v", serviceNamespace, serviceID, addr.IP, port.Port, addr.TargetRef)
|
|
|
|
}
|
|
|
|
}
|
2015-03-23 03:06:12 +00:00
|
|
|
}
|
2015-03-20 21:24:43 +00:00
|
|
|
return count == endpointCount, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func countEndpoints(eps *api.Endpoints) int {
|
|
|
|
count := 0
|
|
|
|
for i := range eps.Subsets {
|
|
|
|
count += len(eps.Subsets[i].Addresses) * len(eps.Subsets[i].Ports)
|
2014-10-03 03:24:30 +00:00
|
|
|
}
|
2015-03-20 21:24:43 +00:00
|
|
|
return count
|
2014-10-03 03:24:30 +00:00
|
|
|
}
|
|
|
|
|
2014-10-23 21:14:15 +00:00
|
|
|
func podExists(c *client.Client, podNamespace string, podID string) wait.ConditionFunc {
|
2014-10-03 03:24:30 +00:00
|
|
|
return func() (bool, error) {
|
2014-10-23 21:14:15 +00:00
|
|
|
_, err := c.Pods(podNamespace).Get(podID)
|
2014-10-03 03:24:30 +00:00
|
|
|
return err == nil, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-09 22:46:47 +00:00
|
|
|
func podNotFound(c *client.Client, podNamespace string, podID string) wait.ConditionFunc {
|
|
|
|
return func() (bool, error) {
|
|
|
|
_, err := c.Pods(podNamespace).Get(podID)
|
|
|
|
return apierrors.IsNotFound(err), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func podRunning(c *client.Client, podNamespace string, podID string) wait.ConditionFunc {
|
|
|
|
return func() (bool, error) {
|
|
|
|
pod, err := c.Pods(podNamespace).Get(podID)
|
2015-03-23 03:06:12 +00:00
|
|
|
if apierrors.IsNotFound(err) {
|
|
|
|
return false, nil
|
|
|
|
}
|
2015-03-09 22:46:47 +00:00
|
|
|
if err != nil {
|
2015-03-25 13:22:24 +00:00
|
|
|
// This could be a connection error so we want to retry, but log the error.
|
|
|
|
glog.Errorf("Error when reading pod %q: %v", podID, err)
|
|
|
|
return false, nil
|
2015-03-09 22:46:47 +00:00
|
|
|
}
|
|
|
|
if pod.Status.Phase != api.PodRunning {
|
2015-03-25 13:22:24 +00:00
|
|
|
return false, nil
|
2015-03-09 22:46:47 +00:00
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func runStaticPodTest(c *client.Client, configFilePath string) {
|
2015-03-24 10:10:26 +00:00
|
|
|
var testCases = []struct {
|
|
|
|
desc string
|
|
|
|
fileContents string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "static-pod-from-manifest",
|
|
|
|
fileContents: `version: v1beta2
|
|
|
|
id: static-pod-from-manifest
|
2015-03-09 22:46:47 +00:00
|
|
|
containers:
|
2015-03-24 10:10:26 +00:00
|
|
|
- name: static-container
|
|
|
|
image: kubernetes/pause`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "static-pod-from-spec",
|
|
|
|
fileContents: `{
|
|
|
|
"kind": "Pod",
|
|
|
|
"apiVersion": "v1beta3",
|
|
|
|
"metadata": {
|
|
|
|
"name": "static-pod-from-spec"
|
|
|
|
},
|
|
|
|
"spec": {
|
|
|
|
"containers": [{
|
|
|
|
"name": "static-container",
|
|
|
|
"image": "kubernetes/pause"
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
}`,
|
|
|
|
},
|
2015-03-09 22:46:47 +00:00
|
|
|
}
|
|
|
|
|
2015-03-24 10:10:26 +00:00
|
|
|
for _, testCase := range testCases {
|
|
|
|
func() {
|
|
|
|
desc := testCase.desc
|
|
|
|
manifestFile, err := ioutil.TempFile(configFilePath, "")
|
|
|
|
defer os.Remove(manifestFile.Name())
|
|
|
|
ioutil.WriteFile(manifestFile.Name(), []byte(testCase.fileContents), 0600)
|
|
|
|
|
|
|
|
// Wait for the mirror pod to be created.
|
|
|
|
podName := fmt.Sprintf("%s-localhost", desc)
|
|
|
|
namespace := kubelet.NamespaceDefault
|
|
|
|
if err := wait.Poll(time.Second, time.Minute*2,
|
|
|
|
podRunning(c, namespace, podName)); err != nil {
|
|
|
|
if pods, err := c.Pods(namespace).List(labels.Everything()); err == nil {
|
|
|
|
for _, pod := range pods.Items {
|
|
|
|
glog.Infof("pod found: %s/%s", namespace, pod.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
glog.Fatalf("%s FAILED: mirror pod has not been created or is not running: %v", desc, err)
|
|
|
|
}
|
|
|
|
// Delete the mirror pod, and wait for it to be recreated.
|
|
|
|
c.Pods(namespace).Delete(podName)
|
|
|
|
if err = wait.Poll(time.Second, time.Second*30,
|
|
|
|
podRunning(c, namespace, podName)); err != nil {
|
|
|
|
glog.Fatalf("%s FAILED: mirror pod has not been re-created or is not running: %v", desc, err)
|
|
|
|
}
|
|
|
|
// Remove the manifest file, and wait for the mirror pod to be deleted.
|
|
|
|
os.Remove(manifestFile.Name())
|
|
|
|
if err = wait.Poll(time.Second, time.Second*30,
|
|
|
|
podNotFound(c, namespace, podName)); err != nil {
|
|
|
|
glog.Fatalf("%s FAILED: mirror pod has not been deleted: %v", desc, err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
2015-03-09 22:46:47 +00:00
|
|
|
}
|
|
|
|
|
2014-08-18 21:42:08 +00:00
|
|
|
func runReplicationControllerTest(c *client.Client) {
|
2015-03-18 08:21:10 +00:00
|
|
|
clientAPIVersion := c.APIVersion()
|
|
|
|
data, err := ioutil.ReadFile("cmd/integration/" + clientAPIVersion + "-controller.json")
|
2014-06-06 23:40:48 +00:00
|
|
|
if err != nil {
|
2014-11-20 10:00:36 +00:00
|
|
|
glog.Fatalf("Unexpected error: %v", err)
|
2014-06-06 23:40:48 +00:00
|
|
|
}
|
2014-11-07 02:09:46 +00:00
|
|
|
var controller api.ReplicationController
|
2014-11-06 22:01:40 +00:00
|
|
|
if err := api.Scheme.DecodeInto(data, &controller); err != nil {
|
2014-11-20 10:00:36 +00:00
|
|
|
glog.Fatalf("Unexpected error: %v", err)
|
2014-06-06 23:40:48 +00:00
|
|
|
}
|
|
|
|
|
2014-07-07 18:44:14 +00:00
|
|
|
glog.Infof("Creating replication controllers")
|
2015-02-16 21:29:11 +00:00
|
|
|
updated, err := c.ReplicationControllers("test").Create(&controller)
|
2015-02-16 04:43:45 +00:00
|
|
|
if err != nil {
|
2014-11-20 10:00:36 +00:00
|
|
|
glog.Fatalf("Unexpected error: %v", err)
|
2014-06-06 23:40:48 +00:00
|
|
|
}
|
2014-07-07 18:44:14 +00:00
|
|
|
glog.Infof("Done creating replication controllers")
|
|
|
|
|
2014-06-09 05:38:45 +00:00
|
|
|
// Give the controllers some time to actually create the pods
|
2015-02-16 04:43:45 +00:00
|
|
|
if err := wait.Poll(time.Second, time.Second*30, client.ControllerHasDesiredReplicas(c, updated)); err != nil {
|
2014-08-18 21:42:08 +00:00
|
|
|
glog.Fatalf("FAILED: pods never created %v", err)
|
|
|
|
}
|
2014-06-06 23:40:48 +00:00
|
|
|
|
2014-08-18 21:42:08 +00:00
|
|
|
// wait for minions to indicate they have info about the desired pods
|
2015-02-16 21:29:11 +00:00
|
|
|
pods, err := c.Pods("test").List(labels.Set(updated.Spec.Selector).AsSelector())
|
2014-08-18 21:42:08 +00:00
|
|
|
if err != nil {
|
|
|
|
glog.Fatalf("FAILED: unable to get pods to list: %v", err)
|
2014-06-06 23:40:48 +00:00
|
|
|
}
|
2014-10-07 00:14:34 +00:00
|
|
|
if err := wait.Poll(time.Second, time.Second*30, podsOnMinions(c, *pods)); err != nil {
|
2014-08-18 21:42:08 +00:00
|
|
|
glog.Fatalf("FAILED: pods never started running %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
glog.Infof("Pods created")
|
2014-07-01 20:30:19 +00:00
|
|
|
}
|
|
|
|
|
2014-10-29 00:20:40 +00:00
|
|
|
func runAPIVersionsTest(c *client.Client) {
|
|
|
|
v, err := c.ServerAPIVersions()
|
2015-03-18 08:21:10 +00:00
|
|
|
clientVersion := c.APIVersion()
|
2014-10-29 00:20:40 +00:00
|
|
|
if err != nil {
|
|
|
|
glog.Fatalf("failed to get api versions: %v", err)
|
|
|
|
}
|
2015-03-18 08:21:10 +00:00
|
|
|
// Verify that the server supports the API version used by the client.
|
|
|
|
for _, version := range v.Versions {
|
|
|
|
if version == clientVersion {
|
|
|
|
glog.Infof("Version test passed")
|
|
|
|
return
|
|
|
|
}
|
2014-10-29 00:20:40 +00:00
|
|
|
}
|
2015-03-18 08:21:10 +00:00
|
|
|
glog.Fatalf("Server does not support APIVersion used by client. Server supported APIVersions: '%v', client APIVersion: '%v'", v.Versions, clientVersion)
|
2014-10-29 00:20:40 +00:00
|
|
|
}
|
|
|
|
|
2015-02-16 21:29:11 +00:00
|
|
|
func runSelfLinkTestOnNamespace(c *client.Client, namespace string) {
|
2015-03-18 08:21:10 +00:00
|
|
|
svcBody := api.Service{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: "selflinktest",
|
|
|
|
Namespace: namespace,
|
|
|
|
Labels: map[string]string{
|
|
|
|
"name": "selflinktest",
|
2014-10-30 22:04:11 +00:00
|
|
|
},
|
2015-03-18 08:21:10 +00:00
|
|
|
},
|
|
|
|
Spec: api.ServiceSpec{
|
|
|
|
Port: 12345,
|
|
|
|
// This is here because validation requires it.
|
|
|
|
Selector: map[string]string{
|
|
|
|
"foo": "bar",
|
2014-10-30 22:04:11 +00:00
|
|
|
},
|
2015-03-18 08:21:10 +00:00
|
|
|
Protocol: "TCP",
|
|
|
|
SessionAffinity: "None",
|
2014-10-30 22:04:11 +00:00
|
|
|
},
|
2015-03-18 08:21:10 +00:00
|
|
|
}
|
|
|
|
services := c.Services(namespace)
|
|
|
|
svc, err := services.Create(&svcBody)
|
2014-10-30 22:04:11 +00:00
|
|
|
if err != nil {
|
|
|
|
glog.Fatalf("Failed creating selflinktest service: %v", err)
|
|
|
|
}
|
2015-03-18 08:21:10 +00:00
|
|
|
err = c.Get().RequestURI(svc.SelfLink).Do().Into(svc)
|
2014-10-30 22:04:11 +00:00
|
|
|
if err != nil {
|
|
|
|
glog.Fatalf("Failed listing service with supplied self link '%v': %v", svc.SelfLink, err)
|
|
|
|
}
|
|
|
|
|
2015-03-18 08:21:10 +00:00
|
|
|
svcList, err := services.List(labels.Everything())
|
2014-10-30 22:04:11 +00:00
|
|
|
if err != nil {
|
|
|
|
glog.Fatalf("Failed listing services: %v", err)
|
|
|
|
}
|
|
|
|
|
2015-03-18 08:21:10 +00:00
|
|
|
err = c.Get().RequestURI(svcList.SelfLink).Do().Into(svcList)
|
2014-10-30 22:04:11 +00:00
|
|
|
if err != nil {
|
|
|
|
glog.Fatalf("Failed listing services with supplied self link '%v': %v", svcList.SelfLink, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
found := false
|
|
|
|
for i := range svcList.Items {
|
|
|
|
item := &svcList.Items[i]
|
|
|
|
if item.Name != "selflinktest" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
found = true
|
2015-03-18 08:21:10 +00:00
|
|
|
err = c.Get().RequestURI(item.SelfLink).Do().Into(svc)
|
2014-10-30 22:04:11 +00:00
|
|
|
if err != nil {
|
|
|
|
glog.Fatalf("Failed listing service with supplied self link '%v': %v", item.SelfLink, err)
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if !found {
|
2015-02-16 21:29:11 +00:00
|
|
|
glog.Fatalf("never found selflinktest service in namespace %s", namespace)
|
2014-10-30 22:04:11 +00:00
|
|
|
}
|
2015-02-16 21:29:11 +00:00
|
|
|
glog.Infof("Self link test passed in namespace %s", namespace)
|
2014-10-30 22:04:11 +00:00
|
|
|
|
|
|
|
// TODO: Should test PUT at some point, too.
|
|
|
|
}
|
|
|
|
|
2014-07-02 20:51:27 +00:00
|
|
|
func runAtomicPutTest(c *client.Client) {
|
2015-03-18 08:21:10 +00:00
|
|
|
svcBody := api.Service{
|
|
|
|
TypeMeta: api.TypeMeta{
|
|
|
|
APIVersion: c.APIVersion(),
|
|
|
|
},
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: "atomicservice",
|
|
|
|
Labels: map[string]string{
|
|
|
|
"name": "atomicService",
|
2014-07-02 20:51:27 +00:00
|
|
|
},
|
2015-03-18 08:21:10 +00:00
|
|
|
},
|
|
|
|
Spec: api.ServiceSpec{
|
|
|
|
Port: 12345,
|
|
|
|
// This is here because validation requires it.
|
|
|
|
Selector: map[string]string{
|
|
|
|
"foo": "bar",
|
2014-07-11 04:14:46 +00:00
|
|
|
},
|
2015-03-18 08:21:10 +00:00
|
|
|
Protocol: "TCP",
|
|
|
|
SessionAffinity: "None",
|
2014-07-02 20:51:27 +00:00
|
|
|
},
|
2015-03-18 08:21:10 +00:00
|
|
|
}
|
|
|
|
services := c.Services(api.NamespaceDefault)
|
|
|
|
svc, err := services.Create(&svcBody)
|
2014-07-02 20:51:27 +00:00
|
|
|
if err != nil {
|
|
|
|
glog.Fatalf("Failed creating atomicService: %v", err)
|
|
|
|
}
|
2014-07-07 18:44:14 +00:00
|
|
|
glog.Info("Created atomicService")
|
2014-07-11 04:14:46 +00:00
|
|
|
testLabels := labels.Set{
|
|
|
|
"foo": "bar",
|
|
|
|
}
|
2014-07-07 18:44:14 +00:00
|
|
|
for i := 0; i < 5; i++ {
|
2014-07-02 20:51:27 +00:00
|
|
|
// a: z, b: y, etc...
|
|
|
|
testLabels[string([]byte{byte('a' + i)})] = string([]byte{byte('z' - i)})
|
|
|
|
}
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
wg.Add(len(testLabels))
|
|
|
|
for label, value := range testLabels {
|
|
|
|
go func(l, v string) {
|
|
|
|
for {
|
2014-07-07 18:44:14 +00:00
|
|
|
glog.Infof("Starting to update (%s, %s)", l, v)
|
2015-03-18 08:21:10 +00:00
|
|
|
tmpSvc, err := services.Get(svc.Name)
|
2014-07-02 20:51:27 +00:00
|
|
|
if err != nil {
|
|
|
|
glog.Errorf("Error getting atomicService: %v", err)
|
|
|
|
continue
|
|
|
|
}
|
2014-10-30 13:29:11 +00:00
|
|
|
if tmpSvc.Spec.Selector == nil {
|
|
|
|
tmpSvc.Spec.Selector = map[string]string{l: v}
|
2014-07-02 20:51:27 +00:00
|
|
|
} else {
|
2014-10-30 13:29:11 +00:00
|
|
|
tmpSvc.Spec.Selector[l] = v
|
2014-07-02 20:51:27 +00:00
|
|
|
}
|
2014-07-07 18:44:14 +00:00
|
|
|
glog.Infof("Posting update (%s, %s)", l, v)
|
2015-03-18 08:21:10 +00:00
|
|
|
tmpSvc, err = services.Update(tmpSvc)
|
2014-07-02 20:51:27 +00:00
|
|
|
if err != nil {
|
2015-03-09 22:46:47 +00:00
|
|
|
if apierrors.IsConflict(err) {
|
2014-09-30 00:15:00 +00:00
|
|
|
glog.Infof("Conflict: (%s, %s)", l, v)
|
|
|
|
// This is what we expect.
|
|
|
|
continue
|
2014-07-02 20:51:27 +00:00
|
|
|
}
|
|
|
|
glog.Errorf("Unexpected error putting atomicService: %v", err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
2014-07-07 18:44:14 +00:00
|
|
|
glog.Infof("Done update (%s, %s)", l, v)
|
2014-07-02 20:51:27 +00:00
|
|
|
wg.Done()
|
|
|
|
}(label, value)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
2015-03-18 08:21:10 +00:00
|
|
|
svc, err = services.Get(svc.Name)
|
|
|
|
if err != nil {
|
2014-07-02 20:51:27 +00:00
|
|
|
glog.Fatalf("Failed getting atomicService after writers are complete: %v", err)
|
|
|
|
}
|
2014-10-30 13:29:11 +00:00
|
|
|
if !reflect.DeepEqual(testLabels, labels.Set(svc.Spec.Selector)) {
|
|
|
|
glog.Fatalf("Selector PUTs were not atomic: wanted %v, got %v", testLabels, svc.Spec.Selector)
|
2014-07-02 20:51:27 +00:00
|
|
|
}
|
|
|
|
glog.Info("Atomic PUTs work.")
|
|
|
|
}
|
|
|
|
|
2015-02-21 18:54:48 +00:00
|
|
|
func runPatchTest(c *client.Client) {
|
|
|
|
name := "patchservice"
|
2015-03-18 08:21:10 +00:00
|
|
|
svcBody := api.Service{
|
|
|
|
TypeMeta: api.TypeMeta{
|
|
|
|
APIVersion: c.APIVersion(),
|
|
|
|
},
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: name,
|
|
|
|
Labels: map[string]string{
|
|
|
|
"name": name,
|
2015-02-21 18:54:48 +00:00
|
|
|
},
|
2015-03-18 08:21:10 +00:00
|
|
|
},
|
|
|
|
Spec: api.ServiceSpec{
|
|
|
|
Port: 12345,
|
|
|
|
// This is here because validation requires it.
|
|
|
|
Selector: map[string]string{
|
|
|
|
"foo": "bar",
|
2015-02-21 18:54:48 +00:00
|
|
|
},
|
2015-03-18 08:21:10 +00:00
|
|
|
Protocol: "TCP",
|
|
|
|
SessionAffinity: "None",
|
2015-02-21 18:54:48 +00:00
|
|
|
},
|
2015-03-18 08:21:10 +00:00
|
|
|
}
|
|
|
|
services := c.Services(api.NamespaceDefault)
|
|
|
|
svc, err := services.Create(&svcBody)
|
2015-02-21 18:54:48 +00:00
|
|
|
if err != nil {
|
|
|
|
glog.Fatalf("Failed creating patchservice: %v", err)
|
|
|
|
}
|
|
|
|
if len(svc.Labels) != 1 {
|
|
|
|
glog.Fatalf("Original length does not equal one")
|
|
|
|
}
|
|
|
|
|
|
|
|
// add label
|
2015-03-18 08:21:10 +00:00
|
|
|
svc.Labels["foo"] = "bar"
|
|
|
|
if _, err = services.Update(svc); err != nil {
|
2015-02-21 18:54:48 +00:00
|
|
|
glog.Fatalf("Failed updating patchservice: %v", err)
|
|
|
|
}
|
2015-03-18 08:21:10 +00:00
|
|
|
if svc, err = services.Get(name); err != nil {
|
2015-02-21 18:54:48 +00:00
|
|
|
glog.Fatalf("Failed getting patchservice: %v", err)
|
|
|
|
}
|
|
|
|
if len(svc.Labels) != 2 || svc.Labels["foo"] != "bar" {
|
|
|
|
glog.Fatalf("Failed updating patchservice, labels are: %v", svc.Labels)
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove one label
|
2015-03-18 08:21:10 +00:00
|
|
|
delete(svc.Labels, "name")
|
|
|
|
if _, err = services.Update(svc); err != nil {
|
2015-02-21 18:54:48 +00:00
|
|
|
glog.Fatalf("Failed updating patchservice: %v", err)
|
|
|
|
}
|
2015-03-18 08:21:10 +00:00
|
|
|
if svc, err = services.Get(name); err != nil {
|
2015-02-21 18:54:48 +00:00
|
|
|
glog.Fatalf("Failed getting patchservice: %v", err)
|
|
|
|
}
|
|
|
|
if len(svc.Labels) != 1 || svc.Labels["foo"] != "bar" {
|
|
|
|
glog.Fatalf("Failed updating patchservice, labels are: %v", svc.Labels)
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove all labels
|
2015-03-18 08:21:10 +00:00
|
|
|
svc.Labels = nil
|
|
|
|
if _, err = services.Update(svc); err != nil {
|
2015-02-21 18:54:48 +00:00
|
|
|
glog.Fatalf("Failed updating patchservice: %v", err)
|
|
|
|
}
|
2015-03-18 08:21:10 +00:00
|
|
|
if svc, err = services.Get(name); err != nil {
|
2015-02-21 18:54:48 +00:00
|
|
|
glog.Fatalf("Failed getting patchservice: %v", err)
|
|
|
|
}
|
|
|
|
if svc.Labels != nil {
|
|
|
|
glog.Fatalf("Failed remove all labels from patchservice: %v", svc.Labels)
|
|
|
|
}
|
|
|
|
|
|
|
|
glog.Info("PATCHs work.")
|
|
|
|
}
|
|
|
|
|
2014-10-28 00:57:28 +00:00
|
|
|
func runMasterServiceTest(client *client.Client) {
|
|
|
|
time.Sleep(12 * time.Second)
|
2015-03-18 08:21:10 +00:00
|
|
|
svcList, err := client.Services(api.NamespaceDefault).List(labels.Everything())
|
2014-10-28 00:57:28 +00:00
|
|
|
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 {
|
2015-03-18 08:21:10 +00:00
|
|
|
ep, err := client.Endpoints(api.NamespaceDefault).Get("kubernetes")
|
2014-10-28 00:57:28 +00:00
|
|
|
if err != nil {
|
|
|
|
glog.Fatalf("unexpected error listing endpoints for kubernetes service: %v", err)
|
|
|
|
}
|
2015-03-20 21:24:43 +00:00
|
|
|
if countEndpoints(ep) == 0 {
|
2014-10-28 00:57:28 +00:00
|
|
|
glog.Fatalf("no endpoints for kubernetes service: %v", ep)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
glog.Errorf("no RW service found: %v", found)
|
|
|
|
}
|
|
|
|
if foundRO {
|
2015-03-18 08:21:10 +00:00
|
|
|
ep, err := client.Endpoints(api.NamespaceDefault).Get("kubernetes-ro")
|
2014-10-28 00:57:28 +00:00
|
|
|
if err != nil {
|
|
|
|
glog.Fatalf("unexpected error listing endpoints for kubernetes service: %v", err)
|
|
|
|
}
|
2015-03-20 21:24:43 +00:00
|
|
|
if countEndpoints(ep) == 0 {
|
2014-10-28 00:57:28 +00:00
|
|
|
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.")
|
|
|
|
}
|
|
|
|
|
2014-10-03 03:24:30 +00:00
|
|
|
func runServiceTest(client *client.Client) {
|
2015-02-16 04:43:45 +00:00
|
|
|
pod := &api.Pod{
|
2014-10-23 20:51:34 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: "foo",
|
|
|
|
Labels: map[string]string{
|
|
|
|
"name": "thisisalonglabel",
|
|
|
|
},
|
|
|
|
},
|
2014-11-13 15:52:13 +00:00
|
|
|
Spec: api.PodSpec{
|
|
|
|
Containers: []api.Container{
|
|
|
|
{
|
|
|
|
Name: "c1",
|
|
|
|
Image: "foo",
|
2015-02-23 22:25:56 +00:00
|
|
|
Ports: []api.ContainerPort{
|
2014-11-13 15:52:13 +00:00
|
|
|
{ContainerPort: 1234},
|
2014-10-03 03:24:30 +00:00
|
|
|
},
|
2015-03-18 08:21:10 +00:00
|
|
|
ImagePullPolicy: api.PullIfNotPresent,
|
2014-10-03 03:24:30 +00:00
|
|
|
},
|
|
|
|
},
|
2015-03-14 01:38:07 +00:00
|
|
|
RestartPolicy: api.RestartPolicyAlways,
|
2015-01-26 17:52:50 +00:00
|
|
|
DNSPolicy: api.DNSClusterFirst,
|
2014-10-03 03:24:30 +00:00
|
|
|
},
|
2014-11-13 15:52:13 +00:00
|
|
|
Status: api.PodStatus{
|
2014-10-03 03:24:30 +00:00
|
|
|
PodIP: "1.2.3.4",
|
|
|
|
},
|
|
|
|
}
|
2015-02-16 04:43:45 +00:00
|
|
|
pod, err := client.Pods(api.NamespaceDefault).Create(pod)
|
2014-10-03 03:24:30 +00:00
|
|
|
if err != nil {
|
|
|
|
glog.Fatalf("Failed to create pod: %v, %v", pod, err)
|
|
|
|
}
|
2014-10-23 21:14:15 +00:00
|
|
|
if err := wait.Poll(time.Second, time.Second*20, podExists(client, pod.Namespace, pod.Name)); err != nil {
|
2014-10-03 03:24:30 +00:00
|
|
|
glog.Fatalf("FAILED: pod never started running %v", err)
|
|
|
|
}
|
2015-02-16 04:43:45 +00:00
|
|
|
svc1 := &api.Service{
|
2014-10-23 20:51:34 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{Name: "service1"},
|
2014-10-30 13:29:11 +00:00
|
|
|
Spec: api.ServiceSpec{
|
|
|
|
Selector: map[string]string{
|
|
|
|
"name": "thisisalonglabel",
|
|
|
|
},
|
2015-01-26 17:52:50 +00:00
|
|
|
Port: 8080,
|
|
|
|
Protocol: "TCP",
|
|
|
|
SessionAffinity: "None",
|
2014-10-03 03:24:30 +00:00
|
|
|
},
|
|
|
|
}
|
2015-02-16 04:43:45 +00:00
|
|
|
svc1, err = client.Services(api.NamespaceDefault).Create(svc1)
|
2014-09-18 23:03:34 +00:00
|
|
|
if err != nil {
|
|
|
|
glog.Fatalf("Failed to create service: %v, %v", svc1, err)
|
|
|
|
}
|
2015-02-16 21:29:11 +00:00
|
|
|
|
2015-03-09 14:23:52 +00:00
|
|
|
// create an identical service in the non-default namespace
|
2015-02-16 21:29:11 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2015-03-23 03:06:12 +00:00
|
|
|
if err := wait.Poll(time.Second, time.Second*30, endpointsSet(client, svc1.Namespace, svc1.Name, 1)); err != nil {
|
2014-09-18 23:03:34 +00:00
|
|
|
glog.Fatalf("FAILED: unexpected endpoints: %v", err)
|
|
|
|
}
|
|
|
|
// A second service with the same port.
|
2015-02-16 04:43:45 +00:00
|
|
|
svc2 := &api.Service{
|
2014-10-23 20:51:34 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{Name: "service2"},
|
2014-10-30 13:29:11 +00:00
|
|
|
Spec: api.ServiceSpec{
|
|
|
|
Selector: map[string]string{
|
|
|
|
"name": "thisisalonglabel",
|
|
|
|
},
|
2015-01-26 17:52:50 +00:00
|
|
|
Port: 8080,
|
|
|
|
Protocol: "TCP",
|
|
|
|
SessionAffinity: "None",
|
2014-09-18 23:03:34 +00:00
|
|
|
},
|
|
|
|
}
|
2015-02-16 04:43:45 +00:00
|
|
|
svc2, err = client.Services(api.NamespaceDefault).Create(svc2)
|
2014-10-03 03:24:30 +00:00
|
|
|
if err != nil {
|
2014-09-18 23:03:34 +00:00
|
|
|
glog.Fatalf("Failed to create service: %v, %v", svc2, err)
|
2014-10-03 03:24:30 +00:00
|
|
|
}
|
2015-03-23 03:06:12 +00:00
|
|
|
if err := wait.Poll(time.Second, time.Second*30, endpointsSet(client, svc2.Namespace, svc2.Name, 1)); err != nil {
|
2014-10-03 03:24:30 +00:00
|
|
|
glog.Fatalf("FAILED: unexpected endpoints: %v", err)
|
|
|
|
}
|
2015-02-16 21:29:11 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2014-10-03 03:24:30 +00:00
|
|
|
glog.Info("Service test passed.")
|
|
|
|
}
|
|
|
|
|
2014-07-02 20:51:27 +00:00
|
|
|
type testFunc func(*client.Client)
|
|
|
|
|
2015-03-18 08:21:10 +00:00
|
|
|
func addFlags(fs *pflag.FlagSet) {
|
|
|
|
fs.StringVar(&apiVersion, "apiVersion", latest.Version, "API version that should be used by the client for communicating with the server")
|
|
|
|
}
|
|
|
|
|
2014-07-01 20:30:19 +00:00
|
|
|
func main() {
|
2014-07-02 20:51:27 +00:00
|
|
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
2015-03-18 08:21:10 +00:00
|
|
|
addFlags(pflag.CommandLine)
|
|
|
|
|
|
|
|
util.InitFlags()
|
2014-07-01 20:30:19 +00:00
|
|
|
util.ReallyCrash = true
|
|
|
|
util.InitLogs()
|
|
|
|
defer util.FlushLogs()
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
defer util.FlushLogs()
|
|
|
|
time.Sleep(3 * time.Minute)
|
|
|
|
glog.Fatalf("This test has timed out.")
|
|
|
|
}()
|
|
|
|
|
2015-03-18 08:21:10 +00:00
|
|
|
glog.Infof("Running tests for APIVersion: %s", apiVersion)
|
2014-07-01 20:30:19 +00:00
|
|
|
|
2015-03-24 10:10:26 +00:00
|
|
|
firstManifestURL := ServeCachedManifestFile(testPodSpecFile)
|
|
|
|
secondManifestURL := ServeCachedManifestFile(testManifestFile)
|
|
|
|
apiServerURL, configFilePath := startComponents(firstManifestURL, secondManifestURL, apiVersion)
|
2014-07-01 20:30:19 +00:00
|
|
|
|
|
|
|
// Ok. we're good to go.
|
|
|
|
glog.Infof("API Server started on %s", apiServerURL)
|
|
|
|
// Wait for the synchronization threads to come up.
|
|
|
|
time.Sleep(time.Second * 10)
|
|
|
|
|
2015-03-18 08:21:10 +00:00
|
|
|
kubeClient := client.NewOrDie(&client.Config{Host: apiServerURL, Version: apiVersion})
|
2014-07-02 20:51:27 +00:00
|
|
|
|
|
|
|
// Run tests in parallel
|
|
|
|
testFuncs := []testFunc{
|
|
|
|
runReplicationControllerTest,
|
|
|
|
runAtomicPutTest,
|
2015-02-21 18:54:48 +00:00
|
|
|
runPatchTest,
|
2014-10-03 03:24:30 +00:00
|
|
|
runServiceTest,
|
2014-10-29 00:20:40 +00:00
|
|
|
runAPIVersionsTest,
|
2014-10-28 00:57:28 +00:00
|
|
|
runMasterServiceTest,
|
2015-02-16 21:29:11 +00:00
|
|
|
func(c *client.Client) {
|
2015-03-18 08:21:10 +00:00
|
|
|
runSelfLinkTestOnNamespace(c, api.NamespaceDefault)
|
2015-02-16 21:29:11 +00:00
|
|
|
runSelfLinkTestOnNamespace(c, "other")
|
|
|
|
},
|
2015-03-09 22:46:47 +00:00
|
|
|
func(c *client.Client) {
|
|
|
|
runStaticPodTest(c, configFilePath)
|
|
|
|
},
|
2014-07-02 20:51:27 +00:00
|
|
|
}
|
2015-03-18 08:21:10 +00:00
|
|
|
|
2014-07-02 20:51:27 +00:00
|
|
|
var wg sync.WaitGroup
|
|
|
|
wg.Add(len(testFuncs))
|
|
|
|
for i := range testFuncs {
|
|
|
|
f := testFuncs[i]
|
|
|
|
go func() {
|
|
|
|
f(kubeClient)
|
|
|
|
wg.Done()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
wg.Wait()
|
2014-06-24 01:28:06 +00:00
|
|
|
|
2015-03-11 22:34:41 +00:00
|
|
|
// Check that kubelet tried to make the containers.
|
2014-06-24 01:28:06 +00:00
|
|
|
// Using a set to list unique creation attempts. Our fake is
|
|
|
|
// really stupid, so kubelet tries to create these multiple times.
|
2015-03-11 22:34:41 +00:00
|
|
|
createdConts := util.StringSet{}
|
2014-06-24 23:31:33 +00:00
|
|
|
for _, p := range fakeDocker1.Created {
|
2014-06-24 01:28:06 +00:00
|
|
|
// The last 8 characters are random, so slice them off.
|
2014-06-24 17:19:47 +00:00
|
|
|
if n := len(p); n > 8 {
|
2015-03-11 22:34:41 +00:00
|
|
|
createdConts.Insert(p[:n-8])
|
2014-06-24 01:28:06 +00:00
|
|
|
}
|
|
|
|
}
|
2014-06-24 23:31:33 +00:00
|
|
|
for _, p := range fakeDocker2.Created {
|
|
|
|
// The last 8 characters are random, so slice them off.
|
|
|
|
if n := len(p); n > 8 {
|
2015-03-11 22:34:41 +00:00
|
|
|
createdConts.Insert(p[:n-8])
|
2014-06-24 23:31:33 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-24 10:10:26 +00:00
|
|
|
// We expect 9: 2 pod infra containers + 2 containers from the replication controller +
|
|
|
|
// 1 pod infra container + 2 containers from the URL on first Kubelet +
|
|
|
|
// 1 pod infra container + 2 containers from the URL on second Kubelet +
|
|
|
|
// 1 pod infra container + 1 container from the service test.
|
|
|
|
// In addition, runStaticPodTest creates 2 pod infra containers +
|
|
|
|
// 2 pod containers from the file (1 for manifest and 1 for spec)
|
|
|
|
// The total number of container created is 13
|
2015-03-09 22:46:47 +00:00
|
|
|
|
2015-03-24 10:10:26 +00:00
|
|
|
if len(createdConts) != 16 {
|
|
|
|
glog.Fatalf("Expected 16 containers; got %v\n\nlist of created containers:\n\n%#v\n\nDocker 1 Created:\n\n%#v\n\nDocker 2 Created:\n\n%#v\n\n", len(createdConts), createdConts.List(), fakeDocker1.Created, fakeDocker2.Created)
|
2014-06-24 01:28:06 +00:00
|
|
|
}
|
2015-03-11 22:34:41 +00:00
|
|
|
glog.Infof("OK - found created containers: %#v", createdConts.List())
|
2014-06-06 23:40:48 +00:00
|
|
|
}
|
2014-06-24 23:31:33 +00:00
|
|
|
|
2014-07-08 06:30:18 +00:00
|
|
|
// ServeCachedManifestFile serves a file for kubelet to read.
|
2015-03-24 10:10:26 +00:00
|
|
|
func ServeCachedManifestFile(contents string) (servingAddress string) {
|
2014-06-24 23:31:33 +00:00
|
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if r.URL.Path == "/manifest" {
|
2015-03-24 10:10:26 +00:00
|
|
|
w.Write([]byte(contents))
|
2014-06-24 23:31:33 +00:00
|
|
|
return
|
|
|
|
}
|
2014-06-25 03:51:57 +00:00
|
|
|
glog.Fatalf("Got request: %#v\n", r)
|
2014-06-24 23:31:33 +00:00
|
|
|
http.NotFound(w, r)
|
|
|
|
}))
|
|
|
|
return server.URL + "/manifest"
|
|
|
|
}
|
|
|
|
|
2015-03-24 10:10:26 +00:00
|
|
|
const (
|
|
|
|
testPodSpecFile = `{
|
|
|
|
"kind": "Pod",
|
|
|
|
"apiVersion": "v1beta3",
|
|
|
|
"metadata": {
|
|
|
|
"name": "container-vm-guestbook-pod-spec"
|
|
|
|
},
|
|
|
|
"spec": {
|
|
|
|
"containers": [
|
|
|
|
{
|
|
|
|
"name": "redis",
|
|
|
|
"image": "dockerfile/redis",
|
|
|
|
"volumeMounts": [{
|
|
|
|
"name": "redis-data",
|
|
|
|
"mountPath": "/data"
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "guestbook",
|
|
|
|
"image": "google/guestbook-python-redis",
|
|
|
|
"ports": [{
|
|
|
|
"name": "www",
|
|
|
|
"hostPort": 80,
|
|
|
|
"containerPort": 80
|
|
|
|
}]
|
|
|
|
}],
|
|
|
|
"volumes": [{ "name": "redis-data" }]
|
|
|
|
}
|
|
|
|
}`
|
|
|
|
)
|
|
|
|
|
2014-06-24 23:31:33 +00:00
|
|
|
const (
|
|
|
|
// This is copied from, and should be kept in sync with:
|
|
|
|
// https://raw.githubusercontent.com/GoogleCloudPlatform/container-vm-guestbook-redis-python/master/manifest.yaml
|
2014-11-15 01:16:05 +00:00
|
|
|
// Note that kubelet complains about these containers not having a self link.
|
2014-08-04 22:52:59 +00:00
|
|
|
testManifestFile = `version: v1beta2
|
2015-03-24 10:10:26 +00:00
|
|
|
id: container-vm-guestbook-manifest
|
2014-06-24 23:31:33 +00:00
|
|
|
containers:
|
|
|
|
- name: redis
|
|
|
|
image: dockerfile/redis
|
|
|
|
volumeMounts:
|
|
|
|
- name: redis-data
|
2014-06-30 23:16:06 +00:00
|
|
|
mountPath: /data
|
2014-06-24 23:31:33 +00:00
|
|
|
|
|
|
|
- name: guestbook
|
|
|
|
image: google/guestbook-python-redis
|
|
|
|
ports:
|
|
|
|
- name: www
|
|
|
|
hostPort: 80
|
|
|
|
containerPort: 80
|
|
|
|
|
|
|
|
volumes:
|
|
|
|
- name: redis-data`
|
|
|
|
)
|