mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 02:09:56 +00:00
make minion registry not intolerably slow
This commit is contained in:
parent
f0b5fba988
commit
3e75195ff3
@ -125,6 +125,7 @@ type Master struct {
|
|||||||
admissionControl admission.Interface
|
admissionControl admission.Interface
|
||||||
masterCount int
|
masterCount int
|
||||||
v1beta3 bool
|
v1beta3 bool
|
||||||
|
nodeIPCache IPGetter
|
||||||
|
|
||||||
readOnlyServer string
|
readOnlyServer string
|
||||||
readWriteServer string
|
readWriteServer string
|
||||||
@ -256,6 +257,7 @@ func New(c *Config) *Master {
|
|||||||
authorizer: c.Authorizer,
|
authorizer: c.Authorizer,
|
||||||
admissionControl: c.AdmissionControl,
|
admissionControl: c.AdmissionControl,
|
||||||
v1beta3: c.EnableV1Beta3,
|
v1beta3: c.EnableV1Beta3,
|
||||||
|
nodeIPCache: NewIPCache(c.Cloud, util.RealClock{}, 30*time.Second),
|
||||||
|
|
||||||
masterCount: c.MasterCount,
|
masterCount: c.MasterCount,
|
||||||
readOnlyServer: net.JoinHostPort(c.PublicAddress, strconv.Itoa(int(c.ReadOnlyPort))),
|
readOnlyServer: net.JoinHostPort(c.PublicAddress, strconv.Itoa(int(c.ReadOnlyPort))),
|
||||||
@ -319,8 +321,9 @@ func logStackOnRecover(panicReason interface{}, httpWriter http.ResponseWriter)
|
|||||||
|
|
||||||
func makeMinionRegistry(c *Config) minion.Registry {
|
func makeMinionRegistry(c *Config) minion.Registry {
|
||||||
var minionRegistry minion.Registry = etcd.NewRegistry(c.EtcdHelper, nil)
|
var minionRegistry minion.Registry = etcd.NewRegistry(c.EtcdHelper, nil)
|
||||||
|
// TODO: plumb in nodeIPCache here
|
||||||
if c.HealthCheckMinions {
|
if c.HealthCheckMinions {
|
||||||
minionRegistry = minion.NewHealthyRegistry(minionRegistry, c.KubeletClient)
|
minionRegistry = minion.NewHealthyRegistry(minionRegistry, c.KubeletClient, util.RealClock{}, 20*time.Second)
|
||||||
}
|
}
|
||||||
return minionRegistry
|
return minionRegistry
|
||||||
}
|
}
|
||||||
@ -331,9 +334,8 @@ func (m *Master) init(c *Config) {
|
|||||||
var authenticator = c.Authenticator
|
var authenticator = c.Authenticator
|
||||||
|
|
||||||
nodeRESTStorage := minion.NewREST(m.minionRegistry)
|
nodeRESTStorage := minion.NewREST(m.minionRegistry)
|
||||||
ipCache := NewIPCache(c.Cloud, util.RealClock{}, 30*time.Second)
|
|
||||||
podCache := NewPodCache(
|
podCache := NewPodCache(
|
||||||
ipCache,
|
m.nodeIPCache,
|
||||||
c.KubeletClient,
|
c.KubeletClient,
|
||||||
RESTStorageToNodes(nodeRESTStorage).Nodes(),
|
RESTStorageToNodes(nodeRESTStorage).Nodes(),
|
||||||
m.podRegistry,
|
m.podRegistry,
|
||||||
|
@ -17,23 +17,30 @@ limitations under the License.
|
|||||||
package minion
|
package minion
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/health"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/health"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
||||||
)
|
)
|
||||||
|
|
||||||
type HealthyRegistry struct {
|
type HealthyRegistry struct {
|
||||||
delegate Registry
|
delegate Registry
|
||||||
client client.KubeletHealthChecker
|
client client.KubeletHealthChecker
|
||||||
|
cache util.TimeCache
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHealthyRegistry(delegate Registry, client client.KubeletHealthChecker) Registry {
|
func NewHealthyRegistry(delegate Registry, client client.KubeletHealthChecker, clock util.Clock, ttl time.Duration) Registry {
|
||||||
return &HealthyRegistry{
|
h := &HealthyRegistry{
|
||||||
delegate: delegate,
|
delegate: delegate,
|
||||||
client: client,
|
client: client,
|
||||||
}
|
}
|
||||||
|
h.cache = util.NewTimeCache(clock, ttl, h.doCheck)
|
||||||
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *HealthyRegistry) GetMinion(ctx api.Context, minionID string) (*api.Node, error) {
|
func (r *HealthyRegistry) GetMinion(ctx api.Context, minionID string) (*api.Node, error) {
|
||||||
@ -61,9 +68,17 @@ func (r *HealthyRegistry) ListMinions(ctx api.Context) (currentMinions *api.Node
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// In case the cache is empty, health check in parallel instead of serially.
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
wg.Add(len(list.Items))
|
||||||
for i := range list.Items {
|
for i := range list.Items {
|
||||||
list.Items[i] = *r.checkMinion(&list.Items[i])
|
go func(i int) {
|
||||||
|
list.Items[i] = *r.checkMinion(&list.Items[i])
|
||||||
|
wg.Done()
|
||||||
|
}(i)
|
||||||
}
|
}
|
||||||
|
wg.Wait()
|
||||||
return list, nil
|
return list, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,13 +96,7 @@ func (r *HealthyRegistry) WatchMinions(ctx api.Context, label, field labels.Sele
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *HealthyRegistry) checkMinion(node *api.Node) *api.Node {
|
func (r *HealthyRegistry) checkMinion(node *api.Node) *api.Node {
|
||||||
condition := api.ConditionFull
|
condition := r.cache.Get(node.Name).(api.NodeConditionStatus)
|
||||||
switch status, err := r.client.HealthCheck(node.Name); {
|
|
||||||
case err != nil:
|
|
||||||
condition = api.ConditionUnknown
|
|
||||||
case status == health.Unhealthy:
|
|
||||||
condition = api.ConditionNone
|
|
||||||
}
|
|
||||||
// TODO: distinguish other conditions like Reachable/Live, and begin storing this
|
// TODO: distinguish other conditions like Reachable/Live, and begin storing this
|
||||||
// data on nodes directly via sync loops.
|
// data on nodes directly via sync loops.
|
||||||
node.Status.Conditions = append(node.Status.Conditions, api.NodeCondition{
|
node.Status.Conditions = append(node.Status.Conditions, api.NodeCondition{
|
||||||
@ -96,3 +105,15 @@ func (r *HealthyRegistry) checkMinion(node *api.Node) *api.Node {
|
|||||||
})
|
})
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is called to fill the cache.
|
||||||
|
func (r *HealthyRegistry) doCheck(key string) util.T {
|
||||||
|
switch status, err := r.client.HealthCheck(key); {
|
||||||
|
case err != nil:
|
||||||
|
return api.ConditionUnknown
|
||||||
|
case status == health.Unhealthy:
|
||||||
|
return api.ConditionNone
|
||||||
|
default:
|
||||||
|
return api.ConditionFull
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -19,10 +19,12 @@ package minion
|
|||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/health"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/health"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type alwaysYes struct{}
|
type alwaysYes struct{}
|
||||||
@ -34,10 +36,12 @@ func (alwaysYes) HealthCheck(host string) (health.Status, error) {
|
|||||||
func TestBasicDelegation(t *testing.T) {
|
func TestBasicDelegation(t *testing.T) {
|
||||||
ctx := api.NewContext()
|
ctx := api.NewContext()
|
||||||
mockMinionRegistry := registrytest.NewMinionRegistry([]string{"m1", "m2", "m3"}, api.NodeResources{})
|
mockMinionRegistry := registrytest.NewMinionRegistry([]string{"m1", "m2", "m3"}, api.NodeResources{})
|
||||||
healthy := HealthyRegistry{
|
healthy := NewHealthyRegistry(
|
||||||
delegate: mockMinionRegistry,
|
mockMinionRegistry,
|
||||||
client: alwaysYes{},
|
alwaysYes{},
|
||||||
}
|
&util.FakeClock{},
|
||||||
|
60*time.Second,
|
||||||
|
)
|
||||||
list, err := healthy.ListMinions(ctx)
|
list, err := healthy.ListMinions(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
@ -82,10 +86,12 @@ func (n *notMinion) HealthCheck(host string) (health.Status, error) {
|
|||||||
func TestFiltering(t *testing.T) {
|
func TestFiltering(t *testing.T) {
|
||||||
ctx := api.NewContext()
|
ctx := api.NewContext()
|
||||||
mockMinionRegistry := registrytest.NewMinionRegistry([]string{"m1", "m2", "m3"}, api.NodeResources{})
|
mockMinionRegistry := registrytest.NewMinionRegistry([]string{"m1", "m2", "m3"}, api.NodeResources{})
|
||||||
healthy := HealthyRegistry{
|
healthy := NewHealthyRegistry(
|
||||||
delegate: mockMinionRegistry,
|
mockMinionRegistry,
|
||||||
client: ¬Minion{minion: "m1"},
|
¬Minion{minion: "m1"},
|
||||||
}
|
&util.FakeClock{},
|
||||||
|
60*time.Second,
|
||||||
|
)
|
||||||
expected := []string{"m1", "m2", "m3"}
|
expected := []string{"m1", "m2", "m3"}
|
||||||
list, err := healthy.ListMinions(ctx)
|
list, err := healthy.ListMinions(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -18,11 +18,13 @@ package minion
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMinionRegistryREST(t *testing.T) {
|
func TestMinionRegistryREST(t *testing.T) {
|
||||||
@ -89,12 +91,14 @@ func TestMinionRegistryREST(t *testing.T) {
|
|||||||
|
|
||||||
func TestMinionRegistryHealthCheck(t *testing.T) {
|
func TestMinionRegistryHealthCheck(t *testing.T) {
|
||||||
minionRegistry := registrytest.NewMinionRegistry([]string{}, api.NodeResources{})
|
minionRegistry := registrytest.NewMinionRegistry([]string{}, api.NodeResources{})
|
||||||
minionHealthRegistry := HealthyRegistry{
|
minionHealthRegistry := NewHealthyRegistry(
|
||||||
delegate: minionRegistry,
|
minionRegistry,
|
||||||
client: ¬Minion{minion: "m1"},
|
¬Minion{minion: "m1"},
|
||||||
}
|
&util.FakeClock{},
|
||||||
|
60*time.Second,
|
||||||
|
)
|
||||||
|
|
||||||
ms := NewREST(&minionHealthRegistry)
|
ms := NewREST(minionHealthRegistry)
|
||||||
ctx := api.NewContext()
|
ctx := api.NewContext()
|
||||||
|
|
||||||
c, err := ms.Create(ctx, &api.Node{ObjectMeta: api.ObjectMeta{Name: "m1"}})
|
c, err := ms.Create(ctx, &api.Node{ObjectMeta: api.ObjectMeta{Name: "m1"}})
|
||||||
|
Loading…
Reference in New Issue
Block a user