Skip to content

Commit

Permalink
Updating integration tests to test both API versions - v1beta1 and 3
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhiljindal committed Mar 18, 2015
1 parent c966ae8 commit 7e36bba
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 154 deletions.
226 changes: 105 additions & 121 deletions cmd/integration/integration.go

Large diffs are not rendered by default.

File renamed without changes.
24 changes: 24 additions & 0 deletions cmd/integration/v1beta3-controller.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"kind": "ReplicationController",
"apiVersion": "v1beta3",
"metadata": {
"name": "nginx-controller",
"labels": {"name": "nginx"}
},
"spec": {
"replicas": 2,
"selector": {"name": "nginx"},
"template": {
"metadata": {
"labels": {"name": "nginx"}
},
"spec": {
"containers": [{
"name": "nginx",
"image": "dockerfile/nginx",
"ports": [{"containerPort": 80}]
}]
}
}
}
}
1 change: 0 additions & 1 deletion cmd/kube-apiserver/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ func (s *APIServer) Run(_ []string) error {
admissionController := admission.NewFromPlugins(client, admissionControlPluginNames, s.AdmissionControlConfigFile)

config := &master.Config{
Client: client,
Cloud: cloud,
EtcdHelper: helper,
EventTTL: s.EventTTL,
Expand Down
5 changes: 2 additions & 3 deletions cmd/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (h *delegateHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
}

// RunApiServer starts an API server in a go routine.
func runApiServer(cl *client.Client, etcdClient tools.EtcdClient, addr net.IP, port int, masterServiceNamespace string) {
func runApiServer(etcdClient tools.EtcdClient, addr net.IP, port int, masterServiceNamespace string) {
handler := delegateHandler{}

helper, err := master.NewEtcdHelper(etcdClient, "")
Expand All @@ -86,7 +86,6 @@ func runApiServer(cl *client.Client, etcdClient tools.EtcdClient, addr net.IP, p

// Create a master and install handlers into mux.
m := master.New(&master.Config{
Client: cl,
EtcdHelper: helper,
KubeletClient: &client.HTTPKubeletClient{
Client: http.DefaultClient,
Expand Down Expand Up @@ -142,7 +141,7 @@ func runControllerManager(machineList []string, cl *client.Client, nodeMilliCPU,
func startComponents(etcdClient tools.EtcdClient, cl *client.Client, addr net.IP, port int) {
machineList := []string{"localhost"}

runApiServer(cl, etcdClient, addr, port, *masterServiceNamespace)
runApiServer(etcdClient, addr, port, *masterServiceNamespace)
runScheduler(cl)
runControllerManager(machineList, cl, *nodeMilliCPU, *nodeMemory)

Expand Down
3 changes: 2 additions & 1 deletion examples/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ func TestExampleObjectSchemas(t *testing.T) {
"pod": &api.Pod{},
},
"../cmd/integration": {
"controller": &api.ReplicationController{},
"v1beta1-controller": &api.ReplicationController{},
"v1beta3-controller": &api.ReplicationController{},
},
"../examples/guestbook": {
"frontend-controller": &api.ReplicationController{},
Expand Down
27 changes: 16 additions & 11 deletions hack/test-integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,25 @@ cleanup() {
kube::log::status "Integration test cleanup complete"
}

"${KUBE_ROOT}/hack/build-go.sh" "$@" cmd/integration
runTests() {
kube::etcd::start

# Run cleanup to stop etcd on interrupt or other kill signal.
trap cleanup EXIT
kube::log::status "Running integration test cases"
KUBE_GOFLAGS="-tags 'integration no-docker' " \
KUBE_RACE="-race" \
"${KUBE_ROOT}/hack/test-go.sh" test/integration

kube::log::status "Running integration test scenario"

kube::etcd::start
"${KUBE_OUTPUT_HOSTBIN}/integration" --v=2 --apiVersion="$1"

kube::log::status "Running integration test cases"
KUBE_GOFLAGS="-tags 'integration no-docker' " \
KUBE_RACE="-race" \
"${KUBE_ROOT}/hack/test-go.sh" test/integration
cleanup
}

kube::log::status "Running integration test scenario"
"${KUBE_ROOT}/hack/build-go.sh" "$@" cmd/integration

"${KUBE_OUTPUT_HOSTBIN}/integration" --v=2
# Run cleanup to stop etcd on interrupt or other kill signal.
trap cleanup EXIT

cleanup
runTests "v1beta1"
runTests "v1beta3"
2 changes: 1 addition & 1 deletion pkg/client/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type Request struct {
baseURL *url.URL
codec runtime.Codec

// If true, add "?namespace=<namespace>" as a query parameter, if false put ns/<namespace> in path
// If true, add "?namespace=<namespace>" as a query parameter, if false put namespaces/<namespace> in path
// Query parameter is considered legacy behavior
namespaceInQuery bool
// If true, lowercase resource prior to inserting into a path, if false, leave it as is. Preserving
Expand Down
22 changes: 20 additions & 2 deletions pkg/client/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ func (c *services) Get(name string) (result *api.Service, err error) {
// Create creates a new service.
func (c *services) Create(svc *api.Service) (result *api.Service, err error) {
result = &api.Service{}
err = c.r.Post().Namespace(c.ns).Resource("services").Body(svc).Do().Into(result)
// v1beta3 does not allow POST without a namespace.
needNamespace := !api.PreV1Beta3(c.r.APIVersion())
namespace := c.ns
if needNamespace && len(namespace) == 0 {
namespace = api.NamespaceDefault
}
err = c.r.Post().Namespace(namespace).Resource("services").Body(svc).Do().Into(result)
return
}

Expand All @@ -88,12 +94,24 @@ func (c *services) Update(svc *api.Service) (result *api.Service, err error) {
err = fmt.Errorf("invalid update object, missing resource version: %v", svc)
return
}
err = c.r.Put().Namespace(c.ns).Resource("services").Name(svc.Name).Body(svc).Do().Into(result)
// v1beta3 does not allow PUT without a namespace.
needNamespace := !api.PreV1Beta3(c.r.APIVersion())
namespace := c.ns
if needNamespace && len(namespace) == 0 {
namespace = api.NamespaceDefault
}
err = c.r.Put().Namespace(namespace).Resource("services").Name(svc.Name).Body(svc).Do().Into(result)
return
}

// Delete deletes an existing service.
func (c *services) Delete(name string) error {
// v1beta3 does not allow DELETE without a namespace.
needNamespace := !api.PreV1Beta3(c.r.APIVersion())
namespace := c.ns
if needNamespace && len(namespace) == 0 {
namespace = api.NamespaceDefault
}
return c.r.Delete().Namespace(c.ns).Resource("services").Name(name).Do().Error()
}

Expand Down
3 changes: 0 additions & 3 deletions pkg/master/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ import (

// Config is a structure used to configure a Master.
type Config struct {
Client *client.Client
Cloud cloudprovider.Interface
EtcdHelper tools.EtcdHelper
EventTTL time.Duration
Expand Down Expand Up @@ -122,7 +121,6 @@ type Config struct {
// Master contains state for a Kubernetes cluster master/api server.
type Master struct {
// "Inputs", Copied from Config
client *client.Client
portalNet *net.IPNet
cacheTimeout time.Duration

Expand Down Expand Up @@ -262,7 +260,6 @@ func New(c *Config) *Master {
glog.V(4).Infof("Setting master service IPs based on PortalNet subnet to %q (read-only) and %q (read-write).", serviceReadOnlyIP, serviceReadWriteIP)

m := &Master{
client: c.Client,
portalNet: c.PortalNet,
rootWebService: new(restful.WebService),
enableLogsSupport: c.EnableLogsSupport,
Expand Down
3 changes: 1 addition & 2 deletions plugin/pkg/scheduler/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ func (factory *ConfigFactory) createMinionLW() *cache.ListWatch {
// Lists all minions and filter out unhealthy ones, then returns
// an enumerator for cache.Poller.
func (factory *ConfigFactory) pollMinions() (cache.Enumerator, error) {
allNodes := &api.NodeList{}
err := factory.Client.Get().Resource("minions").Do().Into(allNodes)
allNodes, err := factory.Client.Nodes().List()
if err != nil {
return nil, err
}
Expand Down
8 changes: 0 additions & 8 deletions test/integration/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ func TestAuthModeAlwaysAllow(t *testing.T) {
defer s.Close()

m = master.New(&master.Config{
Client: client.NewOrDie(&client.Config{Host: s.URL}),
EtcdHelper: helper,
KubeletClient: client.FakeKubeletClient{},
EnableLogsSupport: false,
Expand Down Expand Up @@ -415,7 +414,6 @@ func TestAuthModeAlwaysDeny(t *testing.T) {
defer s.Close()

m = master.New(&master.Config{
Client: client.NewOrDie(&client.Config{Host: s.URL}),
EtcdHelper: helper,
KubeletClient: client.FakeKubeletClient{},
EnableLogsSupport: false,
Expand Down Expand Up @@ -483,7 +481,6 @@ func TestAliceNotForbiddenOrUnauthorized(t *testing.T) {
defer s.Close()

m = master.New(&master.Config{
Client: client.NewOrDie(&client.Config{Host: s.URL}),
EtcdHelper: helper,
KubeletClient: client.FakeKubeletClient{},
EnableLogsSupport: false,
Expand Down Expand Up @@ -569,7 +566,6 @@ func TestBobIsForbidden(t *testing.T) {
defer s.Close()

m = master.New(&master.Config{
Client: client.NewOrDie(&client.Config{Host: s.URL}),
EtcdHelper: helper,
KubeletClient: client.FakeKubeletClient{},
EnableLogsSupport: false,
Expand Down Expand Up @@ -631,7 +627,6 @@ func TestUnknownUserIsUnauthorized(t *testing.T) {
defer s.Close()

m = master.New(&master.Config{
Client: client.NewOrDie(&client.Config{Host: s.URL}),
EtcdHelper: helper,
KubeletClient: client.FakeKubeletClient{},
EnableLogsSupport: false,
Expand Down Expand Up @@ -712,7 +707,6 @@ func TestNamespaceAuthorization(t *testing.T) {
defer s.Close()

m = master.New(&master.Config{
Client: client.NewOrDie(&client.Config{Host: s.URL}),
EtcdHelper: helper,
KubeletClient: client.FakeKubeletClient{},
EnableLogsSupport: false,
Expand Down Expand Up @@ -827,7 +821,6 @@ func TestKindAuthorization(t *testing.T) {
defer s.Close()

m = master.New(&master.Config{
Client: client.NewOrDie(&client.Config{Host: s.URL}),
EtcdHelper: helper,
KubeletClient: client.FakeKubeletClient{},
EnableLogsSupport: false,
Expand Down Expand Up @@ -930,7 +923,6 @@ func TestReadOnlyAuthorization(t *testing.T) {
defer s.Close()

m = master.New(&master.Config{
Client: client.NewOrDie(&client.Config{Host: s.URL}),
EtcdHelper: helper,
KubeletClient: client.FakeKubeletClient{},
EnableLogsSupport: false,
Expand Down
1 change: 0 additions & 1 deletion test/integration/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func TestClient(t *testing.T) {
defer s.Close()

m = master.New(&master.Config{
Client: client.NewOrDie(&client.Config{Host: s.URL}),
EtcdHelper: helper,
KubeletClient: client.FakeKubeletClient{},
EnableLogsSupport: false,
Expand Down

0 comments on commit 7e36bba

Please sign in to comment.