Commit a2651bfc authored by Deyuan Deng's avatar Deyuan Deng

Rename minioncontroller to nodecontroller

parent 7bff03fb
...@@ -37,7 +37,7 @@ import ( ...@@ -37,7 +37,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver" "github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/client"
minionControllerPkg "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/controller" nodeControllerPkg "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/controller"
replicationControllerPkg "github.com/GoogleCloudPlatform/kubernetes/pkg/controller" replicationControllerPkg "github.com/GoogleCloudPlatform/kubernetes/pkg/controller"
"github.com/GoogleCloudPlatform/kubernetes/pkg/health" "github.com/GoogleCloudPlatform/kubernetes/pkg/health"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools"
...@@ -188,8 +188,8 @@ func startComponents(manifestURL string) (apiServerURL string) { ...@@ -188,8 +188,8 @@ func startComponents(manifestURL string) (apiServerURL string) {
controllerManager.Run(10 * time.Minute) controllerManager.Run(10 * time.Minute)
nodeResources := &api.NodeResources{} nodeResources := &api.NodeResources{}
minionController := minionControllerPkg.NewMinionController(nil, "", machineList, nodeResources, cl) nodeController := nodeControllerPkg.NewNodeController(nil, "", machineList, nodeResources, cl)
minionController.Run(10 * time.Second) nodeController.Run(10 * time.Second)
// Kubelet (localhost) // Kubelet (localhost)
standalone.SimpleRunKubelet(cl, etcdClient, &fakeDocker1, machineList[0], testRootDir, manifestURL, "127.0.0.1", 10250) standalone.SimpleRunKubelet(cl, etcdClient, &fakeDocker1, machineList[0], testRootDir, manifestURL, "127.0.0.1", 10250)
......
...@@ -31,7 +31,7 @@ import ( ...@@ -31,7 +31,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider" "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
minionControllerPkg "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/controller" nodeControllerPkg "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/controller"
replicationControllerPkg "github.com/GoogleCloudPlatform/kubernetes/pkg/controller" replicationControllerPkg "github.com/GoogleCloudPlatform/kubernetes/pkg/controller"
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/healthz" _ "github.com/GoogleCloudPlatform/kubernetes/pkg/healthz"
"github.com/GoogleCloudPlatform/kubernetes/pkg/master/ports" "github.com/GoogleCloudPlatform/kubernetes/pkg/master/ports"
...@@ -105,8 +105,8 @@ func main() { ...@@ -105,8 +105,8 @@ func main() {
api.ResourceMemory: *nodeMemory, api.ResourceMemory: *nodeMemory,
}, },
} }
minionController := minionControllerPkg.NewMinionController(cloud, *minionRegexp, machineList, nodeResources, kubeClient) nodeController := nodeControllerPkg.NewNodeController(cloud, *minionRegexp, machineList, nodeResources, kubeClient)
minionController.Run(10 * time.Second) nodeController.Run(10 * time.Second)
select {} select {}
} }
...@@ -27,32 +27,32 @@ import ( ...@@ -27,32 +27,32 @@ import (
"github.com/golang/glog" "github.com/golang/glog"
) )
type MinionController struct { type NodeController struct {
cloud cloudprovider.Interface cloud cloudprovider.Interface
matchRE string matchRE string
staticResources *api.NodeResources staticResources *api.NodeResources
minions []string nodes []string
kubeClient client.Interface kubeClient client.Interface
} }
// NewMinionController returns a new minion controller to sync instances from cloudprovider. // NewNodeController returns a new node controller to sync instances from cloudprovider.
func NewMinionController( func NewNodeController(
cloud cloudprovider.Interface, cloud cloudprovider.Interface,
matchRE string, matchRE string,
minions []string, nodes []string,
staticResources *api.NodeResources, staticResources *api.NodeResources,
kubeClient client.Interface) *MinionController { kubeClient client.Interface) *NodeController {
return &MinionController{ return &NodeController{
cloud: cloud, cloud: cloud,
matchRE: matchRE, matchRE: matchRE,
minions: minions, nodes: nodes,
staticResources: staticResources, staticResources: staticResources,
kubeClient: kubeClient, kubeClient: kubeClient,
} }
} }
// Run starts syncing instances from cloudprovider periodically, or create initial minion list. // Run starts syncing instances from cloudprovider periodically, or create initial node list.
func (s *MinionController) Run(period time.Duration) { func (s *NodeController) Run(period time.Duration) {
if s.cloud != nil && len(s.matchRE) > 0 { if s.cloud != nil && len(s.matchRE) > 0 {
go util.Forever(func() { go util.Forever(func() {
if err := s.SyncCloud(); err != nil { if err := s.SyncCloud(); err != nil {
...@@ -66,24 +66,24 @@ func (s *MinionController) Run(period time.Duration) { ...@@ -66,24 +66,24 @@ func (s *MinionController) Run(period time.Duration) {
// SyncStatic registers list of machines from command line flag. It returns after successful // SyncStatic registers list of machines from command line flag. It returns after successful
// registration of all machines. // registration of all machines.
func (s *MinionController) SyncStatic(period time.Duration) error { func (s *NodeController) SyncStatic(period time.Duration) error {
registered := util.NewStringSet() registered := util.NewStringSet()
for { for {
for _, minionID := range s.minions { for _, nodeID := range s.nodes {
if registered.Has(minionID) { if registered.Has(nodeID) {
continue continue
} }
_, err := s.kubeClient.Nodes().Create(&api.Node{ _, err := s.kubeClient.Nodes().Create(&api.Node{
ObjectMeta: api.ObjectMeta{Name: minionID}, ObjectMeta: api.ObjectMeta{Name: nodeID},
Spec: api.NodeSpec{ Spec: api.NodeSpec{
Capacity: s.staticResources.Capacity, Capacity: s.staticResources.Capacity,
}, },
}) })
if err == nil { if err == nil {
registered.Insert(minionID) registered.Insert(nodeID)
} }
} }
if registered.Len() == len(s.minions) { if registered.Len() == len(s.nodes) {
return nil return nil
} }
time.Sleep(period) time.Sleep(period)
...@@ -91,44 +91,44 @@ func (s *MinionController) SyncStatic(period time.Duration) error { ...@@ -91,44 +91,44 @@ func (s *MinionController) SyncStatic(period time.Duration) error {
} }
// SyncCloud syncs list of instances from cloudprovider to master etcd registry. // SyncCloud syncs list of instances from cloudprovider to master etcd registry.
func (s *MinionController) SyncCloud() error { func (s *NodeController) SyncCloud() error {
matches, err := s.cloudMinions() matches, err := s.cloudNodes()
if err != nil { if err != nil {
return err return err
} }
minions, err := s.kubeClient.Nodes().List() nodes, err := s.kubeClient.Nodes().List()
if err != nil { if err != nil {
return err return err
} }
minionMap := make(map[string]*api.Node) nodeMap := make(map[string]*api.Node)
for _, minion := range minions.Items { for _, node := range nodes.Items {
minionMap[minion.Name] = &minion nodeMap[node.Name] = &node
} }
// Create or delete minions from registry. // Create or delete nodes from registry.
for _, minion := range matches.Items { for _, node := range matches.Items {
if _, ok := minionMap[minion.Name]; !ok { if _, ok := nodeMap[node.Name]; !ok {
glog.Infof("Create minion in registry: %s", minion.Name) glog.Infof("Create node in registry: %s", node.Name)
_, err = s.kubeClient.Nodes().Create(&minion) _, err = s.kubeClient.Nodes().Create(&node)
if err != nil { if err != nil {
glog.Errorf("Create minion error: %s", minion.Name) glog.Errorf("Create node error: %s", node.Name)
} }
} }
delete(minionMap, minion.Name) delete(nodeMap, node.Name)
} }
for minionID := range minionMap { for nodeID := range nodeMap {
glog.Infof("Delete minion from registry: %s", minionID) glog.Infof("Delete node from registry: %s", nodeID)
err = s.kubeClient.Nodes().Delete(minionID) err = s.kubeClient.Nodes().Delete(nodeID)
if err != nil { if err != nil {
glog.Errorf("Delete minion error: %s", minionID) glog.Errorf("Delete node error: %s", nodeID)
} }
} }
return nil return nil
} }
// cloudMinions constructs and returns api.NodeList from cloudprovider. // cloudNodes constructs and returns api.NodeList from cloudprovider.
func (s *MinionController) cloudMinions() (*api.NodeList, error) { func (s *NodeController) cloudNodes() (*api.NodeList, error) {
instances, ok := s.cloud.Instances() instances, ok := s.cloud.Instances()
if !ok { if !ok {
return nil, fmt.Errorf("cloud doesn't support instances") return nil, fmt.Errorf("cloud doesn't support instances")
......
...@@ -26,8 +26,9 @@ import ( ...@@ -26,8 +26,9 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver" "github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/clientauth" "github.com/GoogleCloudPlatform/kubernetes/pkg/clientauth"
minionControllerPkg "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/controller" nodeControllerPkg "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/controller"
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller" "github.com/GoogleCloudPlatform/kubernetes/pkg/controller"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/config" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/config"
...@@ -130,8 +131,8 @@ func RunControllerManager(machineList []string, cl *client.Client, nodeMilliCPU, ...@@ -130,8 +131,8 @@ func RunControllerManager(machineList []string, cl *client.Client, nodeMilliCPU,
api.ResourceMemory: *resource.NewQuantity(nodeMemory, resource.BinarySI), api.ResourceMemory: *resource.NewQuantity(nodeMemory, resource.BinarySI),
}, },
} }
minionController := minionControllerPkg.NewMinionController(nil, "", machineList, nodeResources, cl) nodeController := nodeControllerPkg.NewNodeController(nil, "", machineList, nodeResources, cl)
minionController.Run(10 * time.Second) nodeController.Run(10 * time.Second)
endpoints := service.NewEndpointController(cl) endpoints := service.NewEndpointController(cl)
go util.Forever(func() { endpoints.SyncServiceEndpoints() }, time.Second*10) go util.Forever(func() { endpoints.SyncServiceEndpoints() }, time.Second*10)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment