mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-12 12:48:51 +00:00
Create MinionController to sync minions from cloudprovider (pkg cloudprovider/controller).
This commit is contained in:
@@ -27,6 +27,7 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
|
||||
cloudcontroller "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/controller"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/binding"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/controller"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/endpoint"
|
||||
@@ -39,7 +40,6 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
@@ -100,56 +100,50 @@ func New(c *Config) *Master {
|
||||
minionRegistry: minionRegistry,
|
||||
client: c.Client,
|
||||
}
|
||||
m.init(c.Cloud, c.PodInfoGetter)
|
||||
m.init(c)
|
||||
return m
|
||||
}
|
||||
|
||||
func makeMinionRegistry(c *Config) minion.Registry {
|
||||
var minionRegistry minion.Registry
|
||||
if c.Cloud != nil && len(c.MinionRegexp) > 0 {
|
||||
var err error
|
||||
minionRegistry, err = minion.NewCloudRegistry(c.Cloud, c.MinionRegexp, &c.NodeResources)
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to initalize cloud minion registry reverting to static registry (%#v)", err)
|
||||
}
|
||||
var minionRegistry minion.Registry = etcd.NewRegistry(c.EtcdHelper, nil)
|
||||
if c.HealthCheckMinions {
|
||||
minionRegistry = minion.NewHealthyRegistry(minionRegistry, &http.Client{})
|
||||
}
|
||||
if minionRegistry == nil {
|
||||
minionRegistry = etcd.NewRegistry(c.EtcdHelper, nil)
|
||||
return minionRegistry
|
||||
}
|
||||
|
||||
// init initializes master.
|
||||
func (m *Master) init(c *Config) {
|
||||
podCache := NewPodCache(c.PodInfoGetter, m.podRegistry)
|
||||
go util.Forever(func() { podCache.UpdateAllContainers() }, time.Second*30)
|
||||
|
||||
if c.Cloud != nil && len(c.MinionRegexp) > 0 {
|
||||
// TODO: Move minion controller to its own code.
|
||||
minionController, err := cloudcontroller.NewMinionController(c.Cloud, c.MinionRegexp, &c.NodeResources, m.minionRegistry)
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to initalize minion controller (%#v)", err)
|
||||
}
|
||||
// TODO: Create a Run() method on controller to invoke Sync().
|
||||
go util.OnceAndForever(func() { minionController.Sync() }, c.MinionCacheTTL)
|
||||
} else {
|
||||
for _, minionID := range c.Minions {
|
||||
minionRegistry.CreateMinion(nil, &api.Minion{
|
||||
m.minionRegistry.CreateMinion(nil, &api.Minion{
|
||||
TypeMeta: api.TypeMeta{ID: minionID},
|
||||
NodeResources: c.NodeResources,
|
||||
})
|
||||
}
|
||||
}
|
||||
if c.HealthCheckMinions {
|
||||
minionRegistry = minion.NewHealthyRegistry(minionRegistry, &http.Client{})
|
||||
}
|
||||
if c.MinionCacheTTL > 0 {
|
||||
cachingMinionRegistry, err := minion.NewCachingRegistry(minionRegistry, c.MinionCacheTTL)
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to initialize caching layer, ignoring cache.")
|
||||
} else {
|
||||
minionRegistry = cachingMinionRegistry
|
||||
}
|
||||
}
|
||||
return minionRegistry
|
||||
}
|
||||
|
||||
func (m *Master) init(cloud cloudprovider.Interface, podInfoGetter client.PodInfoGetter) {
|
||||
podCache := NewPodCache(podInfoGetter, m.podRegistry)
|
||||
go util.Forever(func() { podCache.UpdateAllContainers() }, time.Second*30)
|
||||
|
||||
m.storage = map[string]apiserver.RESTStorage{
|
||||
"pods": pod.NewREST(&pod.RESTConfig{
|
||||
CloudProvider: cloud,
|
||||
CloudProvider: c.Cloud,
|
||||
PodCache: podCache,
|
||||
PodInfoGetter: podInfoGetter,
|
||||
PodInfoGetter: c.PodInfoGetter,
|
||||
Registry: m.podRegistry,
|
||||
Minions: m.client,
|
||||
}),
|
||||
"replicationControllers": controller.NewREST(m.controllerRegistry, m.podRegistry),
|
||||
"services": service.NewREST(m.serviceRegistry, cloud, m.minionRegistry),
|
||||
"services": service.NewREST(m.serviceRegistry, c.Cloud, m.minionRegistry),
|
||||
"endpoints": endpoint.NewREST(m.endpointRegistry),
|
||||
"minions": minion.NewREST(m.minionRegistry),
|
||||
"events": event.NewREST(m.eventRegistry),
|
||||
|
Reference in New Issue
Block a user