convert bootstrap controller to posthook to tighten master.go
This commit is contained in:
@@ -26,9 +26,11 @@ import (
|
||||
"k8s.io/kubernetes/pkg/api/endpoints"
|
||||
"k8s.io/kubernetes/pkg/api/errors"
|
||||
"k8s.io/kubernetes/pkg/api/rest"
|
||||
"k8s.io/kubernetes/pkg/registry/core/endpoint"
|
||||
coreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/unversioned"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver"
|
||||
"k8s.io/kubernetes/pkg/registry/core/namespace"
|
||||
"k8s.io/kubernetes/pkg/registry/core/rangeallocation"
|
||||
corerest "k8s.io/kubernetes/pkg/registry/core/rest"
|
||||
"k8s.io/kubernetes/pkg/registry/core/service"
|
||||
servicecontroller "k8s.io/kubernetes/pkg/registry/core/service/ipallocator/controller"
|
||||
portallocatorcontroller "k8s.io/kubernetes/pkg/registry/core/service/portallocator/controller"
|
||||
@@ -72,6 +74,42 @@ type Controller struct {
|
||||
runner *async.Runner
|
||||
}
|
||||
|
||||
// NewBootstrapController returns a controller for watching the core capabilities of the master
|
||||
func (c *Config) NewBootstrapController(legacyRESTStorage corerest.LegacyRESTStorage) *Controller {
|
||||
return &Controller{
|
||||
NamespaceRegistry: legacyRESTStorage.NamespaceRegistry,
|
||||
ServiceRegistry: legacyRESTStorage.ServiceRegistry,
|
||||
|
||||
EndpointReconciler: c.EndpointReconcilerConfig.Reconciler,
|
||||
EndpointInterval: c.EndpointReconcilerConfig.Interval,
|
||||
|
||||
SystemNamespaces: []string{api.NamespaceSystem},
|
||||
SystemNamespacesInterval: 1 * time.Minute,
|
||||
|
||||
ServiceClusterIPRegistry: legacyRESTStorage.ServiceClusterIPAllocator,
|
||||
ServiceClusterIPRange: c.GenericConfig.ServiceClusterIPRange,
|
||||
ServiceClusterIPInterval: 3 * time.Minute,
|
||||
|
||||
ServiceNodePortRegistry: legacyRESTStorage.ServiceNodePortAllocator,
|
||||
ServiceNodePortRange: c.GenericConfig.ServiceNodePortRange,
|
||||
ServiceNodePortInterval: 3 * time.Minute,
|
||||
|
||||
PublicIP: c.GenericConfig.PublicAddress,
|
||||
|
||||
ServiceIP: c.GenericConfig.ServiceReadWriteIP,
|
||||
ServicePort: c.GenericConfig.ServiceReadWritePort,
|
||||
ExtraServicePorts: c.GenericConfig.ExtraServicePorts,
|
||||
ExtraEndpointPorts: c.GenericConfig.ExtraEndpointPorts,
|
||||
PublicServicePort: c.GenericConfig.ReadWritePort,
|
||||
KubernetesServiceNodePort: c.GenericConfig.KubernetesServiceNodePort,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Controller) PostStartHook(hookContext genericapiserver.PostStartHookContext) error {
|
||||
c.Start()
|
||||
return nil
|
||||
}
|
||||
|
||||
// Start begins the core controller loops that must exist for bootstrapping
|
||||
// a cluster.
|
||||
func (c *Controller) Start() {
|
||||
@@ -257,18 +295,18 @@ type EndpointReconciler interface {
|
||||
// masterCountEndpointReconciler reconciles endpoints based on a specified expected number of
|
||||
// masters. masterCountEndpointReconciler implements EndpointReconciler.
|
||||
type masterCountEndpointReconciler struct {
|
||||
masterCount int
|
||||
endpointRegistry endpoint.Registry
|
||||
masterCount int
|
||||
endpointClient coreclient.EndpointsGetter
|
||||
}
|
||||
|
||||
var _ EndpointReconciler = &masterCountEndpointReconciler{}
|
||||
|
||||
// NewMasterCountEndpointReconciler creates a new EndpointReconciler that reconciles based on a
|
||||
// specified expected number of masters.
|
||||
func NewMasterCountEndpointReconciler(masterCount int, endpointRegistry endpoint.Registry) *masterCountEndpointReconciler {
|
||||
func NewMasterCountEndpointReconciler(masterCount int, endpointClient coreclient.EndpointsGetter) *masterCountEndpointReconciler {
|
||||
return &masterCountEndpointReconciler{
|
||||
masterCount: masterCount,
|
||||
endpointRegistry: endpointRegistry,
|
||||
masterCount: masterCount,
|
||||
endpointClient: endpointClient,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,8 +323,7 @@ func NewMasterCountEndpointReconciler(masterCount int, endpointRegistry endpoint
|
||||
// to be running (c.masterCount).
|
||||
// * ReconcileEndpoints is called periodically from all apiservers.
|
||||
func (r *masterCountEndpointReconciler) ReconcileEndpoints(serviceName string, ip net.IP, endpointPorts []api.EndpointPort, reconcilePorts bool) error {
|
||||
ctx := api.NewDefaultContext()
|
||||
e, err := r.endpointRegistry.GetEndpoints(ctx, serviceName)
|
||||
e, err := r.endpointClient.Endpoints(api.NamespaceDefault).Get(serviceName)
|
||||
if err != nil {
|
||||
e = &api.Endpoints{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
@@ -301,7 +338,8 @@ func (r *masterCountEndpointReconciler) ReconcileEndpoints(serviceName string, i
|
||||
Addresses: []api.EndpointAddress{{IP: ip.String()}},
|
||||
Ports: endpointPorts,
|
||||
}}
|
||||
return r.endpointRegistry.UpdateEndpoints(ctx, e)
|
||||
_, err = r.endpointClient.Endpoints(api.NamespaceDefault).Create(e)
|
||||
return err
|
||||
}
|
||||
|
||||
// First, determine if the endpoint is in the format we expect (one
|
||||
@@ -314,7 +352,8 @@ func (r *masterCountEndpointReconciler) ReconcileEndpoints(serviceName string, i
|
||||
Ports: endpointPorts,
|
||||
}}
|
||||
glog.Warningf("Resetting endpoints for master service %q to %#v", serviceName, e)
|
||||
return r.endpointRegistry.UpdateEndpoints(ctx, e)
|
||||
_, err = r.endpointClient.Endpoints(api.NamespaceDefault).Update(e)
|
||||
return err
|
||||
}
|
||||
if ipCorrect && portsCorrect {
|
||||
return nil
|
||||
@@ -349,7 +388,8 @@ func (r *masterCountEndpointReconciler) ReconcileEndpoints(serviceName string, i
|
||||
e.Subsets[0].Ports = endpointPorts
|
||||
}
|
||||
glog.Warningf("Resetting endpoints for master service %q to %v", serviceName, e)
|
||||
return r.endpointRegistry.UpdateEndpoints(ctx, e)
|
||||
_, err = r.endpointClient.Endpoints(api.NamespaceDefault).Update(e)
|
||||
return err
|
||||
}
|
||||
|
||||
// Determine if the endpoint is in the format ReconcileEndpoints expects.
|
||||
|
Reference in New Issue
Block a user