2014-11-02 20:52:31 +00:00
|
|
|
/*
|
2015-05-01 16:19:44 +00:00
|
|
|
Copyright 2014 The Kubernetes Authors All rights reserved.
|
2014-11-02 20:52:31 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package master
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
2015-07-29 23:15:24 +00:00
|
|
|
explatest "github.com/GoogleCloudPlatform/kubernetes/pkg/expapi/latest"
|
2014-11-02 20:52:31 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
|
2015-07-30 11:27:18 +00:00
|
|
|
etcdstorage "github.com/GoogleCloudPlatform/kubernetes/pkg/storage/etcd"
|
2014-11-02 20:52:31 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
|
2015-03-11 17:10:09 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools/etcdtest"
|
2014-11-02 20:52:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetServersToValidate(t *testing.T) {
|
|
|
|
master := Master{}
|
|
|
|
config := Config{}
|
|
|
|
fakeClient := tools.NewFakeEtcdClient(t)
|
|
|
|
fakeClient.Machines = []string{"http://machine1:4001", "http://machine2", "http://machine3:4003"}
|
2015-07-30 11:27:18 +00:00
|
|
|
config.DatabaseStorage = etcdstorage.NewEtcdStorage(fakeClient, latest.Codec, etcdtest.PathPrefix())
|
2015-07-29 23:15:24 +00:00
|
|
|
config.ExpDatabaseStorage = etcdstorage.NewEtcdStorage(fakeClient, explatest.Codec, etcdtest.PathPrefix())
|
2014-11-02 20:52:31 +00:00
|
|
|
|
2015-02-12 00:07:54 +00:00
|
|
|
master.nodeRegistry = registrytest.NewMinionRegistry([]string{"node1", "node2"}, api.NodeResources{})
|
2014-11-02 20:52:31 +00:00
|
|
|
|
2015-05-14 00:29:25 +00:00
|
|
|
servers := master.getServersToValidate(&config)
|
2015-05-04 21:17:35 +00:00
|
|
|
|
|
|
|
if len(servers) != 5 {
|
|
|
|
t.Errorf("unexpected server list: %#v", servers)
|
|
|
|
}
|
|
|
|
for _, server := range []string{"scheduler", "controller-manager", "etcd-0", "etcd-1", "etcd-2"} {
|
|
|
|
if _, ok := servers[server]; !ok {
|
|
|
|
t.Errorf("server list missing: %s", server)
|
|
|
|
}
|
|
|
|
}
|
2014-11-02 20:52:31 +00:00
|
|
|
}
|
2015-07-28 08:10:48 +00:00
|
|
|
|
|
|
|
func TestFindExternalAddress(t *testing.T) {
|
|
|
|
expectedIP := "172.0.0.1"
|
|
|
|
|
|
|
|
nodes := []*api.Node{new(api.Node), new(api.Node), new(api.Node)}
|
|
|
|
nodes[0].Status.Addresses = []api.NodeAddress{{"ExternalIP", expectedIP}}
|
|
|
|
nodes[1].Status.Addresses = []api.NodeAddress{{"LegacyHostIP", expectedIP}}
|
|
|
|
nodes[2].Status.Addresses = []api.NodeAddress{{"ExternalIP", expectedIP}, {"LegacyHostIP", "172.0.0.2"}}
|
|
|
|
|
|
|
|
for _, node := range nodes {
|
|
|
|
ip, err := findExternalAddress(node)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("error getting node external address: %s", err)
|
|
|
|
}
|
|
|
|
if ip != expectedIP {
|
|
|
|
t.Errorf("expected ip to be %s, but was %s", expectedIP, ip)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := findExternalAddress(new(api.Node))
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("expected findExternalAddress to fail on a node with missing ip information")
|
|
|
|
}
|
|
|
|
}
|