Skip to content

Commit

Permalink
Merge pull request kubernetes#4165 from smarterclayton/ignore_already…
Browse files Browse the repository at this point in the history
…_exists_errors_on_create_node

NodeController should tolerate when nodes already exist
  • Loading branch information
ddysher committed Feb 9, 2015
2 parents c0d7e58 + 8c1206c commit 91b43a4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/cloudprovider/controller/nodecontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
}
Expand Down
23 changes: 23 additions & 0 deletions pkg/cloudprovider/controller/nodecontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"},
Expand Down

0 comments on commit 91b43a4

Please sign in to comment.