Skip to content

Commit

Permalink
Post hostip for static machines
Browse files Browse the repository at this point in the history
  • Loading branch information
ddysher committed Jan 10, 2015
1 parent 2a2cef8 commit 0e13a24
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
19 changes: 17 additions & 2 deletions pkg/cloudprovider/controller/nodecontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package controller

import (
"fmt"
"net"
"time"

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
Expand Down Expand Up @@ -73,12 +74,26 @@ func (s *NodeController) SyncStatic(period time.Duration) error {
if registered.Has(nodeID) {
continue
}
_, err := s.kubeClient.Nodes().Create(&api.Node{
node := &api.Node{
ObjectMeta: api.ObjectMeta{Name: nodeID},
Spec: api.NodeSpec{
Capacity: s.staticResources.Capacity,
},
})
}
addr := net.ParseIP(nodeID)
if addr != nil {
node.Status.HostIP = nodeID
} else {
addrs, err := net.LookupIP(nodeID)
if err != nil {
glog.Errorf("Can't get ip address of node %v", nodeID)
} else if len(addrs) == 0 {
glog.Errorf("No ip address for node %v", nodeID)
} else {
node.Status.HostIP = addrs[0].String()
}
}
_, err := s.kubeClient.Nodes().Create(node)
if err == nil {
registered.Insert(nodeID)
}
Expand Down
19 changes: 19 additions & 0 deletions pkg/cloudprovider/controller/nodecontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,25 @@ func TestSyncStaticCreateNode(t *testing.T) {
}
}

func TestSyncStaticCreateNodeWithHostIP(t *testing.T) {
fakeNodeHandler := &FakeNodeHandler{
CreateHook: func(fake *FakeNodeHandler, node *api.Node) bool {
return true
},
}
nodeController := NewNodeController(nil, ".*", []string{"10.0.0.1"}, &api.NodeResources{}, fakeNodeHandler)
if err := nodeController.SyncStatic(time.Millisecond); err != nil {
t.Errorf("unexpected error: %v", err)
}

if fakeNodeHandler.CreatedNodes[0].Name != "10.0.0.1" {
t.Errorf("unexpect node %v created", fakeNodeHandler.CreatedNodes[0].Name)
}
if fakeNodeHandler.CreatedNodes[0].Status.HostIP != "10.0.0.1" {
t.Errorf("unexpect nil node HostIP for node %v", fakeNodeHandler.CreatedNodes[0].Name)
}
}

func TestSyncStaticCreateNodeWithError(t *testing.T) {
fakeNodeHandler := &FakeNodeHandler{
CreateHook: func(fake *FakeNodeHandler, node *api.Node) bool {
Expand Down

0 comments on commit 0e13a24

Please sign in to comment.