diff --git a/pkg/cloudprovider/controller/nodecontroller.go b/pkg/cloudprovider/controller/nodecontroller.go index 4d106cca28956..6d4cfa8553915 100644 --- a/pkg/cloudprovider/controller/nodecontroller.go +++ b/pkg/cloudprovider/controller/nodecontroller.go @@ -26,6 +26,7 @@ import ( "time" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" + apierrors "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors" "github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider" "github.com/GoogleCloudPlatform/kubernetes/pkg/probe" @@ -121,14 +122,14 @@ func (s *NodeController) RegisterNodes(nodes *api.NodeList, retryCount int, retr continue } _, err := s.kubeClient.Nodes().Create(&node) - if err == nil { + if err == nil || apierrors.IsAlreadyExists(err) { registered.Insert(node.Name) glog.Infof("Registered node in registry: %s", node.Name) } else { - glog.Errorf("Error registrying node %s, retrying: %s", node.Name, err) + glog.Errorf("Error registering node %s, retrying: %s", node.Name, err) } if registered.Len() == len(nodes.Items) { - glog.Infof("Successfully Registered all nodes") + glog.Infof("Successfully registered all nodes") return nil } } diff --git a/pkg/cloudprovider/controller/nodecontroller_test.go b/pkg/cloudprovider/controller/nodecontroller_test.go index b8269df5cd6f4..86ee4efce0c13 100644 --- a/pkg/cloudprovider/controller/nodecontroller_test.go +++ b/pkg/cloudprovider/controller/nodecontroller_test.go @@ -25,6 +25,7 @@ import ( "time" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" + apierrors "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource" "github.com/GoogleCloudPlatform/kubernetes/pkg/client" fake_cloud "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/fake" @@ -54,6 +55,11 @@ func (c *FakeNodeHandler) Nodes() client.NodeInterface { func (m *FakeNodeHandler) Create(node *api.Node) (*api.Node, error) { defer func() { m.RequestCount++ }() + for _, n := range m.Existing { + if n.Name == node.Name { + return nil, apierrors.NewAlreadyExists("Minion", node.Name) + } + } if m.CreateHook == nil || m.CreateHook(m, node) { nodeCopy := *node m.CreatedNodes = append(m.CreatedNodes, &nodeCopy) @@ -178,6 +184,23 @@ func TestRegisterNodes(t *testing.T) { expectedCreateCount: 2, expectedFail: false, }, + { + // One node already exists + machines: []string{"node0", "node1"}, + fakeNodeHandler: &FakeNodeHandler{ + Existing: []*api.Node{ + { + ObjectMeta: api.ObjectMeta{ + Name: "node1", + }, + }, + }, + }, + retryCount: 10, + expectedRequestCount: 2, + expectedCreateCount: 1, + expectedFail: false, + }, { // The first node always fails. machines: []string{"node0", "node1"},