2014-12-19 09:27:01 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package controller
|
|
|
|
|
|
|
|
import (
|
2015-01-16 22:28:20 +00:00
|
|
|
"errors"
|
2014-12-19 09:27:01 +00:00
|
|
|
"fmt"
|
2015-01-16 22:28:20 +00:00
|
|
|
"net"
|
|
|
|
"reflect"
|
|
|
|
"sort"
|
2014-12-19 09:27:01 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
2015-01-16 22:28:20 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
|
2014-12-19 09:27:01 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
|
|
|
fake_cloud "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/fake"
|
2015-01-16 22:28:20 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/probe"
|
2014-12-19 09:27:01 +00:00
|
|
|
)
|
|
|
|
|
2015-01-16 22:28:20 +00:00
|
|
|
// FakeNodeHandler is a fake implementation of NodesInterface and NodeInterface.
|
2014-12-19 09:27:01 +00:00
|
|
|
type FakeNodeHandler struct {
|
|
|
|
client.Fake
|
|
|
|
client.FakeNodes
|
|
|
|
|
|
|
|
// Input: Hooks determine if request is valid or not
|
|
|
|
CreateHook func(*FakeNodeHandler, *api.Node) bool
|
|
|
|
Existing []*api.Node
|
|
|
|
|
|
|
|
// Output
|
|
|
|
CreatedNodes []*api.Node
|
|
|
|
DeletedNodes []*api.Node
|
2015-01-16 22:28:20 +00:00
|
|
|
UpdatedNodes []*api.Node
|
2014-12-19 09:27:01 +00:00
|
|
|
RequestCount int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *FakeNodeHandler) Nodes() client.NodeInterface {
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *FakeNodeHandler) Create(node *api.Node) (*api.Node, error) {
|
|
|
|
defer func() { m.RequestCount++ }()
|
|
|
|
if m.CreateHook == nil || m.CreateHook(m, node) {
|
2015-01-16 22:28:20 +00:00
|
|
|
nodeCopy := *node
|
|
|
|
m.CreatedNodes = append(m.CreatedNodes, &nodeCopy)
|
2014-12-19 09:27:01 +00:00
|
|
|
return node, nil
|
|
|
|
} else {
|
|
|
|
return nil, fmt.Errorf("Create error.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *FakeNodeHandler) List() (*api.NodeList, error) {
|
|
|
|
defer func() { m.RequestCount++ }()
|
2015-01-16 22:28:20 +00:00
|
|
|
var nodes []*api.Node
|
|
|
|
for i := 0; i < len(m.UpdatedNodes); i++ {
|
|
|
|
if !contains(m.UpdatedNodes[i], m.DeletedNodes) {
|
|
|
|
nodes = append(nodes, m.UpdatedNodes[i])
|
|
|
|
}
|
|
|
|
}
|
2014-12-19 09:27:01 +00:00
|
|
|
for i := 0; i < len(m.Existing); i++ {
|
2015-01-16 22:28:20 +00:00
|
|
|
if !contains(m.Existing[i], m.DeletedNodes) && !contains(m.Existing[i], nodes) {
|
|
|
|
nodes = append(nodes, m.Existing[i])
|
2014-12-19 09:27:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for i := 0; i < len(m.CreatedNodes); i++ {
|
2015-01-16 22:28:20 +00:00
|
|
|
if !contains(m.Existing[i], m.DeletedNodes) && !contains(m.CreatedNodes[i], nodes) {
|
|
|
|
nodes = append(nodes, m.CreatedNodes[i])
|
2014-12-19 09:27:01 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-16 22:28:20 +00:00
|
|
|
nodeList := &api.NodeList{}
|
|
|
|
for _, node := range nodes {
|
|
|
|
nodeList.Items = append(nodeList.Items, *node)
|
|
|
|
}
|
|
|
|
return nodeList, nil
|
2014-12-19 09:27:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *FakeNodeHandler) Delete(id string) error {
|
|
|
|
m.DeletedNodes = append(m.DeletedNodes, newNode(id))
|
|
|
|
m.RequestCount++
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-01-16 22:28:20 +00:00
|
|
|
func (m *FakeNodeHandler) Update(node *api.Node) (*api.Node, error) {
|
|
|
|
nodeCopy := *node
|
|
|
|
m.UpdatedNodes = append(m.UpdatedNodes, &nodeCopy)
|
|
|
|
m.RequestCount++
|
|
|
|
return node, nil
|
|
|
|
}
|
2014-12-19 09:27:01 +00:00
|
|
|
|
2015-01-16 22:28:20 +00:00
|
|
|
// FakeKubeletClient is a fake implementation of KubeletClient.
|
|
|
|
type FakeKubeletClient struct {
|
|
|
|
Status probe.Status
|
|
|
|
Err error
|
2014-12-19 09:27:01 +00:00
|
|
|
}
|
|
|
|
|
2015-01-16 22:28:20 +00:00
|
|
|
func (c *FakeKubeletClient) GetPodStatus(host, podNamespace, podID string) (api.PodStatusResult, error) {
|
|
|
|
return api.PodStatusResult{}, errors.New("Not Implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *FakeKubeletClient) HealthCheck(host string) (probe.Status, error) {
|
|
|
|
return c.Status, c.Err
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRegisterNodes(t *testing.T) {
|
|
|
|
table := []struct {
|
|
|
|
fakeNodeHandler *FakeNodeHandler
|
|
|
|
machines []string
|
|
|
|
retryCount int
|
|
|
|
expectedRequestCount int
|
|
|
|
expectedCreateCount int
|
|
|
|
expectedFail bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
// Register two nodes normally.
|
|
|
|
machines: []string{"node0", "node1"},
|
|
|
|
fakeNodeHandler: &FakeNodeHandler{
|
|
|
|
CreateHook: func(fake *FakeNodeHandler, node *api.Node) bool { return true },
|
|
|
|
},
|
|
|
|
retryCount: 1,
|
|
|
|
expectedRequestCount: 2,
|
|
|
|
expectedCreateCount: 2,
|
|
|
|
expectedFail: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// No machine to register.
|
|
|
|
machines: []string{},
|
|
|
|
fakeNodeHandler: &FakeNodeHandler{
|
|
|
|
CreateHook: func(fake *FakeNodeHandler, node *api.Node) bool { return true },
|
|
|
|
},
|
|
|
|
retryCount: 1,
|
|
|
|
expectedRequestCount: 0,
|
|
|
|
expectedCreateCount: 0,
|
|
|
|
expectedFail: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Fail the first two requests.
|
|
|
|
machines: []string{"node0", "node1"},
|
|
|
|
fakeNodeHandler: &FakeNodeHandler{
|
|
|
|
CreateHook: func(fake *FakeNodeHandler, node *api.Node) bool {
|
|
|
|
if fake.RequestCount == 0 || fake.RequestCount == 1 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
},
|
|
|
|
},
|
|
|
|
retryCount: 10,
|
|
|
|
expectedRequestCount: 4,
|
|
|
|
expectedCreateCount: 2,
|
|
|
|
expectedFail: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// The first node always fails.
|
|
|
|
machines: []string{"node0", "node1"},
|
|
|
|
fakeNodeHandler: &FakeNodeHandler{
|
|
|
|
CreateHook: func(fake *FakeNodeHandler, node *api.Node) bool {
|
|
|
|
if node.Name == "node0" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
},
|
|
|
|
},
|
|
|
|
retryCount: 2,
|
|
|
|
expectedRequestCount: 3, // 2 for node0, 1 for node1
|
|
|
|
expectedCreateCount: 1,
|
|
|
|
expectedFail: true,
|
2015-01-09 21:14:39 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2015-01-16 22:28:20 +00:00
|
|
|
for _, item := range table {
|
|
|
|
nodes := api.NodeList{}
|
|
|
|
for _, machine := range item.machines {
|
|
|
|
nodes.Items = append(nodes.Items, *newNode(machine))
|
|
|
|
}
|
|
|
|
nodeController := NewNodeController(nil, "", item.machines, &api.NodeResources{}, item.fakeNodeHandler, nil)
|
|
|
|
err := nodeController.RegisterNodes(&nodes, item.retryCount, time.Millisecond)
|
|
|
|
if !item.expectedFail && err != nil {
|
|
|
|
t.Errorf("unexpected error: %v", err)
|
|
|
|
}
|
|
|
|
if item.expectedFail && err == nil {
|
|
|
|
t.Errorf("unexpected non-error")
|
|
|
|
}
|
|
|
|
if item.fakeNodeHandler.RequestCount != item.expectedRequestCount {
|
|
|
|
t.Errorf("expected %v calls, but got %v.", item.expectedRequestCount, item.fakeNodeHandler.RequestCount)
|
|
|
|
}
|
|
|
|
if len(item.fakeNodeHandler.CreatedNodes) != item.expectedCreateCount {
|
|
|
|
t.Errorf("expected %v nodes, but got %v.", item.expectedCreateCount, item.fakeNodeHandler.CreatedNodes)
|
|
|
|
}
|
2015-01-09 21:14:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-16 22:28:20 +00:00
|
|
|
func TestCreateStaticNodes(t *testing.T) {
|
|
|
|
table := []struct {
|
|
|
|
machines []string
|
|
|
|
expectedNodes *api.NodeList
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
machines: []string{},
|
|
|
|
expectedNodes: &api.NodeList{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
machines: []string{"node0"},
|
|
|
|
expectedNodes: &api.NodeList{
|
|
|
|
Items: []api.Node{
|
|
|
|
{
|
|
|
|
ObjectMeta: api.ObjectMeta{Name: "node0"},
|
|
|
|
Spec: api.NodeSpec{},
|
|
|
|
Status: api.NodeStatus{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2014-12-19 09:27:01 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2015-01-16 22:28:20 +00:00
|
|
|
for _, item := range table {
|
|
|
|
nodeController := NewNodeController(nil, "", item.machines, &api.NodeResources{}, nil, nil)
|
|
|
|
nodes, err := nodeController.StaticNodes()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("unexpected error: %v", err)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(item.expectedNodes, nodes) {
|
|
|
|
t.Errorf("expected node list %+v, got %+v", item.expectedNodes, nodes)
|
|
|
|
}
|
2014-12-19 09:27:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-16 22:28:20 +00:00
|
|
|
func TestCreateCloudNodes(t *testing.T) {
|
|
|
|
resourceList := api.ResourceList{
|
|
|
|
api.ResourceCPU: *resource.NewMilliQuantity(1000, resource.DecimalSI),
|
|
|
|
api.ResourceMemory: *resource.NewQuantity(3000, resource.DecimalSI),
|
2014-12-19 09:27:01 +00:00
|
|
|
}
|
|
|
|
|
2015-01-16 22:28:20 +00:00
|
|
|
table := []struct {
|
|
|
|
fakeCloud *fake_cloud.FakeCloud
|
|
|
|
machines []string
|
|
|
|
expectedNodes *api.NodeList
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
fakeCloud: &fake_cloud.FakeCloud{},
|
|
|
|
expectedNodes: &api.NodeList{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fakeCloud: &fake_cloud.FakeCloud{
|
|
|
|
Machines: []string{"node0"},
|
|
|
|
IP: net.ParseIP("1.2.3.4"),
|
|
|
|
NodeResources: &api.NodeResources{Capacity: resourceList},
|
|
|
|
},
|
|
|
|
expectedNodes: &api.NodeList{
|
|
|
|
Items: []api.Node{
|
|
|
|
{
|
|
|
|
ObjectMeta: api.ObjectMeta{Name: "node0"},
|
|
|
|
Spec: api.NodeSpec{Capacity: resourceList},
|
|
|
|
Status: api.NodeStatus{HostIP: "1.2.3.4"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2014-12-19 09:27:01 +00:00
|
|
|
}
|
2015-01-16 22:28:20 +00:00
|
|
|
|
|
|
|
for _, item := range table {
|
|
|
|
nodeController := NewNodeController(item.fakeCloud, ".*", nil, &api.NodeResources{}, nil, nil)
|
|
|
|
nodes, err := nodeController.CloudNodes()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("unexpected error: %v", err)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(item.expectedNodes, nodes) {
|
|
|
|
t.Errorf("expected node list %+v, got %+v", item.expectedNodes, nodes)
|
|
|
|
}
|
2014-12-19 09:27:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-16 22:28:20 +00:00
|
|
|
func TestSyncCloud(t *testing.T) {
|
|
|
|
table := []struct {
|
|
|
|
fakeNodeHandler *FakeNodeHandler
|
|
|
|
fakeCloud *fake_cloud.FakeCloud
|
|
|
|
matchRE string
|
|
|
|
expectedRequestCount int
|
|
|
|
expectedCreated []string
|
|
|
|
expectedDeleted []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
fakeNodeHandler: &FakeNodeHandler{
|
|
|
|
Existing: []*api.Node{newNode("node0")},
|
|
|
|
},
|
|
|
|
fakeCloud: &fake_cloud.FakeCloud{
|
|
|
|
Machines: []string{"node0", "node1"},
|
|
|
|
},
|
|
|
|
matchRE: ".*",
|
|
|
|
expectedRequestCount: 2, // List + Create
|
|
|
|
expectedCreated: []string{"node1"},
|
|
|
|
expectedDeleted: []string{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fakeNodeHandler: &FakeNodeHandler{
|
|
|
|
Existing: []*api.Node{newNode("node0"), newNode("node1")},
|
|
|
|
},
|
|
|
|
fakeCloud: &fake_cloud.FakeCloud{
|
|
|
|
Machines: []string{"node0"},
|
|
|
|
},
|
|
|
|
matchRE: ".*",
|
|
|
|
expectedRequestCount: 2, // List + Delete
|
|
|
|
expectedCreated: []string{},
|
|
|
|
expectedDeleted: []string{"node1"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fakeNodeHandler: &FakeNodeHandler{
|
|
|
|
Existing: []*api.Node{newNode("node0")},
|
|
|
|
},
|
|
|
|
fakeCloud: &fake_cloud.FakeCloud{
|
|
|
|
Machines: []string{"node0", "node1", "fake"},
|
|
|
|
},
|
|
|
|
matchRE: "node[0-9]+",
|
|
|
|
expectedRequestCount: 2, // List + Create
|
|
|
|
expectedCreated: []string{"node1"},
|
|
|
|
expectedDeleted: []string{},
|
|
|
|
},
|
2014-12-19 09:27:01 +00:00
|
|
|
}
|
|
|
|
|
2015-01-16 22:28:20 +00:00
|
|
|
for _, item := range table {
|
|
|
|
nodeController := NewNodeController(item.fakeCloud, item.matchRE, nil, &api.NodeResources{}, item.fakeNodeHandler, nil)
|
|
|
|
if err := nodeController.SyncCloud(); err != nil {
|
|
|
|
t.Errorf("unexpected error: %v", err)
|
|
|
|
}
|
|
|
|
if item.fakeNodeHandler.RequestCount != item.expectedRequestCount {
|
|
|
|
t.Errorf("expected %v call, but got %v.", item.expectedRequestCount, item.fakeNodeHandler.RequestCount)
|
|
|
|
}
|
|
|
|
nodes := sortedNodeNames(item.fakeNodeHandler.CreatedNodes)
|
|
|
|
if !reflect.DeepEqual(item.expectedCreated, nodes) {
|
|
|
|
t.Errorf("expected node list %+v, got %+v", item.expectedCreated, nodes)
|
|
|
|
}
|
|
|
|
nodes = sortedNodeNames(item.fakeNodeHandler.DeletedNodes)
|
|
|
|
if !reflect.DeepEqual(item.expectedDeleted, nodes) {
|
|
|
|
t.Errorf("expected node list %+v, got %+v", item.expectedDeleted, nodes)
|
|
|
|
}
|
2014-12-19 09:27:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-16 22:28:20 +00:00
|
|
|
func TestHealthCheckNode(t *testing.T) {
|
|
|
|
table := []struct {
|
|
|
|
node *api.Node
|
|
|
|
fakeKubeletClient *FakeKubeletClient
|
|
|
|
expectedConditions []api.NodeCondition
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
node: newNode("node0"),
|
|
|
|
fakeKubeletClient: &FakeKubeletClient{
|
|
|
|
Status: probe.Success,
|
|
|
|
Err: nil,
|
|
|
|
},
|
|
|
|
expectedConditions: []api.NodeCondition{
|
|
|
|
{
|
|
|
|
Kind: api.NodeReady,
|
|
|
|
Status: api.ConditionFull,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
node: newNode("node0"),
|
|
|
|
fakeKubeletClient: &FakeKubeletClient{
|
|
|
|
Status: probe.Failure,
|
|
|
|
Err: nil,
|
|
|
|
},
|
|
|
|
expectedConditions: []api.NodeCondition{
|
|
|
|
{
|
|
|
|
Kind: api.NodeReady,
|
|
|
|
Status: api.ConditionNone,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
node: newNode("node1"),
|
|
|
|
fakeKubeletClient: &FakeKubeletClient{
|
|
|
|
Status: probe.Failure,
|
|
|
|
Err: errors.New("Error"),
|
|
|
|
},
|
|
|
|
expectedConditions: []api.NodeCondition{
|
|
|
|
{
|
|
|
|
Kind: api.NodeReady,
|
|
|
|
Status: api.ConditionUnknown,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2014-12-19 09:27:01 +00:00
|
|
|
}
|
2015-01-16 22:28:20 +00:00
|
|
|
|
|
|
|
for _, item := range table {
|
|
|
|
nodeController := NewNodeController(nil, "", nil, nil, nil, item.fakeKubeletClient)
|
|
|
|
conditions := nodeController.DoCheck(item.node)
|
|
|
|
if !reflect.DeepEqual(item.expectedConditions, conditions) {
|
|
|
|
t.Errorf("expected conditions %+v, got %+v", item.expectedConditions, conditions)
|
|
|
|
}
|
2014-12-19 09:27:01 +00:00
|
|
|
}
|
2015-01-16 22:28:20 +00:00
|
|
|
}
|
2014-12-19 09:27:01 +00:00
|
|
|
|
2015-01-16 22:28:20 +00:00
|
|
|
func TestSyncNodeStatus(t *testing.T) {
|
|
|
|
table := []struct {
|
|
|
|
fakeNodeHandler *FakeNodeHandler
|
|
|
|
fakeKubeletClient *FakeKubeletClient
|
|
|
|
expectedNodes []*api.Node
|
|
|
|
expectedRequestCount int
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
fakeNodeHandler: &FakeNodeHandler{
|
|
|
|
Existing: []*api.Node{newNode("node0"), newNode("node1")},
|
|
|
|
},
|
|
|
|
fakeKubeletClient: &FakeKubeletClient{
|
|
|
|
Status: probe.Success,
|
|
|
|
Err: nil,
|
|
|
|
},
|
|
|
|
expectedNodes: []*api.Node{
|
|
|
|
{
|
|
|
|
ObjectMeta: api.ObjectMeta{Name: "node0"},
|
|
|
|
Status: api.NodeStatus{Conditions: []api.NodeCondition{{Kind: api.NodeReady, Status: api.ConditionFull}}},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ObjectMeta: api.ObjectMeta{Name: "node1"},
|
|
|
|
Status: api.NodeStatus{Conditions: []api.NodeCondition{{Kind: api.NodeReady, Status: api.ConditionFull}}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectedRequestCount: 3, // List + 2xUpdate
|
|
|
|
},
|
2014-12-19 09:27:01 +00:00
|
|
|
}
|
2015-01-16 22:28:20 +00:00
|
|
|
|
|
|
|
for _, item := range table {
|
|
|
|
nodeController := NewNodeController(nil, "", nil, nil, item.fakeNodeHandler, item.fakeKubeletClient)
|
|
|
|
if err := nodeController.SyncNodeStatus(); err != nil {
|
|
|
|
t.Errorf("unexpected error: %v", err)
|
|
|
|
}
|
|
|
|
if item.fakeNodeHandler.RequestCount != item.expectedRequestCount {
|
|
|
|
t.Errorf("expected %v call, but got %v.", item.expectedRequestCount, item.fakeNodeHandler.RequestCount)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(item.expectedNodes, item.fakeNodeHandler.UpdatedNodes) {
|
|
|
|
t.Errorf("expected nodes %+v, got %+v", item.expectedNodes, item.fakeNodeHandler.UpdatedNodes)
|
|
|
|
}
|
|
|
|
item.fakeNodeHandler.RequestCount = 0
|
|
|
|
if err := nodeController.SyncNodeStatus(); err != nil {
|
|
|
|
t.Errorf("unexpected error: %v", err)
|
|
|
|
}
|
|
|
|
if item.fakeNodeHandler.RequestCount != 1 {
|
|
|
|
t.Errorf("expected one list for updating same status, but got %v.", item.fakeNodeHandler.RequestCount)
|
|
|
|
}
|
2014-12-19 09:27:01 +00:00
|
|
|
}
|
2015-01-16 22:28:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newNode(name string) *api.Node {
|
|
|
|
return &api.Node{ObjectMeta: api.ObjectMeta{Name: name}}
|
|
|
|
}
|
|
|
|
|
|
|
|
func sortedNodeNames(nodes []*api.Node) []string {
|
|
|
|
nodeNames := []string{}
|
|
|
|
for _, node := range nodes {
|
|
|
|
nodeNames = append(nodeNames, node.Name)
|
2014-12-19 09:27:01 +00:00
|
|
|
}
|
2015-01-16 22:28:20 +00:00
|
|
|
sort.Strings(nodeNames)
|
|
|
|
return nodeNames
|
2014-12-19 09:27:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func contains(node *api.Node, nodes []*api.Node) bool {
|
|
|
|
for i := 0; i < len(nodes); i++ {
|
|
|
|
if node.Name == nodes[i].Name {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|