mirror of https://github.com/k3s-io/k3s
integrate minion health checking and caching.
parent
aaf0180ef4
commit
6c734b1c55
|
@ -23,6 +23,7 @@ import (
|
|||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
|
||||
|
@ -38,6 +39,8 @@ var (
|
|||
cloudProvider = flag.String("cloud_provider", "", "The provider for cloud services. Empty string for no provider.")
|
||||
minionRegexp = flag.String("minion_regexp", "", "If non empty, and -cloud_provider is specified, a regular expression for matching minion VMs")
|
||||
minionPort = flag.Uint("minion_port", 10250, "The port at which kubelet will be listening on the minions.")
|
||||
healthCheckMinions = flag.Bool("health_check_minions", true, "If true, health check minions and filter unhealthy ones. [default true]")
|
||||
minionCacheTTL = flag.Duration("minion_cache_ttl", 30*time.Second, "Duration of time to cache minion information. [default 30 seconds]")
|
||||
etcdServerList, machineList util.StringList
|
||||
)
|
||||
|
||||
|
@ -80,7 +83,7 @@ func main() {
|
|||
|
||||
var m *master.Master
|
||||
if len(etcdServerList) > 0 {
|
||||
m = master.New(etcdServerList, machineList, podInfoGetter, cloud, *minionRegexp, client)
|
||||
m = master.New(etcdServerList, machineList, podInfoGetter, cloud, *minionRegexp, client, *healthCheckMinions, *minionCacheTTL)
|
||||
} else {
|
||||
m = master.NewMemoryServer(machineList, podInfoGetter, cloud, client)
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ func startComponents(manifestURL string) (apiServerURL string) {
|
|||
cl.Sync = true
|
||||
|
||||
// Master
|
||||
m := master.New(servers, machineList, fakePodInfoGetter{}, nil, "", cl)
|
||||
m := master.New(servers, machineList, fakePodInfoGetter{}, nil, "", cl, false, 0)
|
||||
handler.delegate = m.ConstructHandler("/api/v1beta1")
|
||||
|
||||
controllerManager := controller.MakeReplicationManager(etcdClient, cl)
|
||||
|
|
|
@ -55,9 +55,9 @@ func NewMemoryServer(minions []string, podInfoGetter client.PodInfoGetter, cloud
|
|||
}
|
||||
|
||||
// New returns a new instance of Master connected to the given etcdServer.
|
||||
func New(etcdServers, minions []string, podInfoGetter client.PodInfoGetter, cloud cloudprovider.Interface, minionRegexp string, client *client.Client) *Master {
|
||||
func New(etcdServers, minions []string, podInfoGetter client.PodInfoGetter, cloud cloudprovider.Interface, minionRegexp string, client *client.Client, healthCheckMinions bool, cacheMinionsTTL time.Duration) *Master {
|
||||
etcdClient := etcd.NewClient(etcdServers)
|
||||
minionRegistry := minionRegistryMaker(minions, cloud, minionRegexp)
|
||||
minionRegistry := minionRegistryMaker(minions, cloud, minionRegexp, healthCheckMinions, cacheMinionsTTL)
|
||||
m := &Master{
|
||||
podRegistry: registry.MakeEtcdRegistry(etcdClient, minionRegistry),
|
||||
controllerRegistry: registry.MakeEtcdRegistry(etcdClient, minionRegistry),
|
||||
|
@ -69,15 +69,30 @@ func New(etcdServers, minions []string, podInfoGetter client.PodInfoGetter, clou
|
|||
return m
|
||||
}
|
||||
|
||||
func minionRegistryMaker(minions []string, cloud cloudprovider.Interface, minionRegexp string) registry.MinionRegistry {
|
||||
func minionRegistryMaker(minions []string, cloud cloudprovider.Interface, minionRegexp string, healthCheck bool, cacheTTL time.Duration) registry.MinionRegistry {
|
||||
var minionRegistry registry.MinionRegistry
|
||||
if cloud != nil && len(minionRegexp) > 0 {
|
||||
minionRegistry, err := registry.MakeCloudMinionRegistry(cloud, minionRegexp)
|
||||
var err error
|
||||
minionRegistry, err = registry.MakeCloudMinionRegistry(cloud, minionRegexp)
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to initalize cloud minion registry reverting to static registry (%#v)", err)
|
||||
}
|
||||
return minionRegistry
|
||||
}
|
||||
return registry.MakeMinionRegistry(minions)
|
||||
if minionRegistry == nil {
|
||||
minionRegistry = registry.MakeMinionRegistry(minions)
|
||||
}
|
||||
if healthCheck {
|
||||
minionRegistry = registry.NewHealthyMinionRegistry(minionRegistry, &http.Client{})
|
||||
}
|
||||
if cacheTTL > 0 {
|
||||
cachingMinionRegistry, err := registry.NewCachingMinionRegistry(minionRegistry, cacheTTL)
|
||||
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) {
|
||||
|
|
Loading…
Reference in New Issue