Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract interface for master endpoints reconciler. #26915

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 43 additions & 13 deletions pkg/master/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ import (
type Controller struct {
NamespaceRegistry namespace.Registry
ServiceRegistry service.Registry
// TODO: MasterCount is yucky
MasterCount int

ServiceClusterIPRegistry service.RangeRegistry
ServiceClusterIPInterval time.Duration
Expand All @@ -55,8 +53,8 @@ type Controller struct {
ServiceNodePortInterval time.Duration
ServiceNodePortRange utilnet.PortRange

EndpointRegistry endpoint.Registry
EndpointInterval time.Duration
EndpointReconciler EndpointReconciler
EndpointInterval time.Duration

SystemNamespaces []string
SystemNamespacesInterval time.Duration
Expand Down Expand Up @@ -140,7 +138,7 @@ func (c *Controller) UpdateKubernetesService(reconcile bool) error {
return err
}
endpointPorts := createEndpointPortSpec(c.PublicServicePort, "https", c.ExtraEndpointPorts)
if err := c.ReconcileEndpoints("kubernetes", c.PublicIP, endpointPorts, reconcile); err != nil {
if err := c.EndpointReconciler.ReconcileEndpoints("kubernetes", c.PublicIP, endpointPorts, reconcile); err != nil {
return err
}
}
Expand Down Expand Up @@ -240,6 +238,39 @@ func (c *Controller) CreateOrUpdateMasterServiceIfNeeded(serviceName string, ser
return err
}

// EndpointReconciler knows how to reconcile the endpoints for the apiserver service.
type EndpointReconciler interface {
// ReconcileEndpoints sets the endpoints for the given apiserver service (ro or rw).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: add some indication of what the IP in the arguments is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DirectXMan12 In your original PR, the IP argument was changed to an array -- does the new interface need to have that signature change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change if needed. Lmk

On Monday, June 6, 2016, Paul Morie notifications@github.com wrote:

In pkg/master/controller.go
#26915 (comment)
:

@@ -240,6 +238,39 @@ func (c *Controller) CreateOrUpdateMasterServiceIfNeeded(serviceName string, ser
return err
}

+// EndpointReconciler knows how to reconcile the endpoints for the apiserver service.
+type EndpointReconciler interface {

  • // ReconcileEndpoints sets the endpoints for the given apiserver service (ro or rw).

@DirectXMan12 https://github.com/DirectXMan12 In your original PR, the
IP argument was changed to an array -- does the new interface need to have
that signature change?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/kubernetes/kubernetes/pull/26915/files/04ce042ff9cfb32b2c776f755cc7abc886b8a441#r65979052,
or mute the thread
https://github.com/notifications/unsubscribe/AAABYv-P3P-iMyxTA_NRAMrpDefj00w-ks5qJJs3gaJpZM4IvXB4
.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does seem to be documenting the implementation and not the interface.
If you want to amend it, I would focus on fixing that :)

On Mon, Jun 6, 2016 at 4:33 PM, Andy Goldstein notifications@github.com
wrote:

In pkg/master/controller.go
#26915 (comment)
:

@@ -240,6 +238,39 @@ func (c *Controller) CreateOrUpdateMasterServiceIfNeeded(serviceName string, ser
return err
}

+// EndpointReconciler knows how to reconcile the endpoints for the apiserver service.
+type EndpointReconciler interface {

  • // ReconcileEndpoints sets the endpoints for the given apiserver service (ro or rw).

Will change if needed. Lmk
… <#m_1155649936887638275_>
On Monday, June 6, 2016, Paul Morie _@_.***> wrote: In
pkg/master/controller.go <#26915 (comment)
https://github.com/kubernetes/kubernetes/pull/26915#discussion_r65979052>
: > @@ -240,6 +238,39 @@ func (c *Controller)
CreateOrUpdateMasterServiceIfNeeded(serviceName string, ser > return err >
} > > +// EndpointReconciler knows how to reconcile the endpoints for the
apiserver service. > +type EndpointReconciler interface { > + //
ReconcileEndpoints sets the endpoints for the given apiserver service (ro
or rw). @DirectXMan12 https://github.com/DirectXMan12 <
https://github.com/DirectXMan12> In your original PR, the IP argument was
changed to an array -- does the new interface need to have that signature
change? — You are receiving this because you authored the thread. Reply to
this email directly, view it on GitHub <
https://github.com/kubernetes/kubernetes/pull/26915/files/04ce042ff9cfb32b2c776f755cc7abc886b8a441#r65979052>,
or mute the thread <
https://github.com/notifications/unsubscribe/AAABYv-P3P-iMyxTA_NRAMrpDefj00w-ks5qJJs3gaJpZM4IvXB4>
.


You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
https://github.com/kubernetes/kubernetes/pull/26915/files/04ce042ff9cfb32b2c776f755cc7abc886b8a441#r65988045,
or mute the thread
https://github.com/notifications/unsubscribe/AAnglu-6KfZZU1mmVTL0xgLKQ8DNCIP-ks5qJK5XgaJpZM4IvXB4
.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pmorie I don't see the array change in the original PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lavalamp follow-up PR for that? Or at least I'm not getting to it today - I'm exhausted.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine with me.

// ReconcileEndpoints expects that the endpoints objects it manages will all be
// managed only by ReconcileEndpoints; therefore, to understand this, you need only
// understand the requirements.
//
// Requirements:
// * All apiservers MUST use the same ports for their {rw, ro} services.
// * All apiservers MUST use ReconcileEndpoints and only ReconcileEndpoints to manage the
// endpoints for their {rw, ro} services.
// * ReconcileEndpoints is called periodically from all apiservers.
ReconcileEndpoints(serviceName string, ip net.IP, endpointPorts []api.EndpointPort, reconcilePorts bool) error
}

// masterCountEndpointReconciler reconciles endpoints based on a specified expected number of
// masters. masterCountEndpointReconciler implements EndpointReconciler.
type masterCountEndpointReconciler struct {
masterCount int
endpointRegistry endpoint.Registry
}

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 {
return &masterCountEndpointReconciler{
masterCount: masterCount,
endpointRegistry: endpointRegistry,
}
}

// ReconcileEndpoints sets the endpoints for the given apiserver service (ro or rw).
// ReconcileEndpoints expects that the endpoints objects it manages will all be
// managed only by ReconcileEndpoints; therefore, to understand this, you need only
Expand All @@ -252,10 +283,9 @@ func (c *Controller) CreateOrUpdateMasterServiceIfNeeded(serviceName string, ser
// * All apiservers MUST know and agree on the number of apiservers expected
// to be running (c.masterCount).
// * ReconcileEndpoints is called periodically from all apiservers.
//
func (c *Controller) ReconcileEndpoints(serviceName string, ip net.IP, endpointPorts []api.EndpointPort, reconcilePorts bool) error {
func (r *masterCountEndpointReconciler) ReconcileEndpoints(serviceName string, ip net.IP, endpointPorts []api.EndpointPort, reconcilePorts bool) error {
ctx := api.NewDefaultContext()
e, err := c.EndpointRegistry.GetEndpoints(ctx, serviceName)
e, err := r.endpointRegistry.GetEndpoints(ctx, serviceName)
if err != nil {
e = &api.Endpoints{
ObjectMeta: api.ObjectMeta{
Expand All @@ -267,15 +297,15 @@ func (c *Controller) ReconcileEndpoints(serviceName string, ip net.IP, endpointP

// First, determine if the endpoint is in the format we expect (one
// subset, ports matching endpointPorts, N IP addresses).
formatCorrect, ipCorrect, portsCorrect := checkEndpointSubsetFormat(e, ip.String(), endpointPorts, c.MasterCount, reconcilePorts)
formatCorrect, ipCorrect, portsCorrect := checkEndpointSubsetFormat(e, ip.String(), endpointPorts, r.masterCount, reconcilePorts)
if !formatCorrect {
// Something is egregiously wrong, just re-make the endpoints record.
e.Subsets = []api.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: ip.String()}},
Ports: endpointPorts,
}}
glog.Warningf("Resetting endpoints for master service %q to %v", serviceName, e)
return c.EndpointRegistry.UpdateEndpoints(ctx, e)
return r.endpointRegistry.UpdateEndpoints(ctx, e)
}
if ipCorrect && portsCorrect {
return nil
Expand All @@ -291,11 +321,11 @@ func (c *Controller) ReconcileEndpoints(serviceName string, ip net.IP, endpointP
// own IP address. Given the requirements stated at the top of
// this function, this should cause the list of IP addresses to
// become eventually correct.
if addrs := &e.Subsets[0].Addresses; len(*addrs) > c.MasterCount {
if addrs := &e.Subsets[0].Addresses; len(*addrs) > r.masterCount {
// addrs is a pointer because we're going to mutate it.
for i, addr := range *addrs {
if addr.IP == ip.String() {
for len(*addrs) > c.MasterCount {
for len(*addrs) > r.masterCount {
// wrap around if necessary.
remove := (i + 1) % len(*addrs)
*addrs = append((*addrs)[:remove], (*addrs)[remove+1:]...)
Expand All @@ -310,7 +340,7 @@ func (c *Controller) ReconcileEndpoints(serviceName string, ip net.IP, endpointP
e.Subsets[0].Ports = endpointPorts
}
glog.Warningf("Resetting endpoints for master service %q to %v", serviceName, e)
return c.EndpointRegistry.UpdateEndpoints(ctx, e)
return r.endpointRegistry.UpdateEndpoints(ctx, e)
}

// Determine if the endpoint is in the format ReconcileEndpoints expects.
Expand Down
16 changes: 7 additions & 9 deletions pkg/master/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,11 @@ func TestReconcileEndpoints(t *testing.T) {
},
}
for _, test := range reconcile_tests {
master := Controller{MasterCount: test.additionalMasters + 1}
registry := &registrytest.EndpointRegistry{
Endpoints: test.endpoints,
}
master.EndpointRegistry = registry
err := master.ReconcileEndpoints(test.serviceName, net.ParseIP(test.ip), test.endpointPorts, true)
reconciler := NewMasterCountEndpointReconciler(test.additionalMasters+1, registry)
err := reconciler.ReconcileEndpoints(test.serviceName, net.ParseIP(test.ip), test.endpointPorts, true)
if err != nil {
t.Errorf("case %q: unexpected error: %v", test.testName, err)
}
Expand Down Expand Up @@ -461,12 +460,11 @@ func TestReconcileEndpoints(t *testing.T) {
},
}
for _, test := range non_reconcile_tests {
master := Controller{MasterCount: test.additionalMasters + 1}
registry := &registrytest.EndpointRegistry{
Endpoints: test.endpoints,
}
master.EndpointRegistry = registry
err := master.ReconcileEndpoints(test.serviceName, net.ParseIP(test.ip), test.endpointPorts, false)
reconciler := NewMasterCountEndpointReconciler(test.additionalMasters+1, registry)
err := reconciler.ReconcileEndpoints(test.serviceName, net.ParseIP(test.ip), test.endpointPorts, false)
if err != nil {
t.Errorf("case %q: unexpected error: %v", test.testName, err)
}
Expand Down Expand Up @@ -519,7 +517,7 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
},
}
for _, test := range create_tests {
master := Controller{MasterCount: 1}
master := Controller{}
registry := &registrytest.ServiceRegistry{
Err: errors.New("unable to get svc"),
}
Expand Down Expand Up @@ -794,7 +792,7 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
},
}
for _, test := range reconcile_tests {
master := Controller{MasterCount: 1}
master := Controller{}
registry := &registrytest.ServiceRegistry{
Service: test.service,
}
Expand Down Expand Up @@ -846,7 +844,7 @@ func TestCreateOrUpdateMasterService(t *testing.T) {
},
}
for _, test := range non_reconcile_tests {
master := Controller{MasterCount: 1}
master := Controller{}
registry := &registrytest.ServiceRegistry{
Service: test.service,
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/master/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,9 @@ func (m *Master) NewBootstrapController() *Controller {
return &Controller{
NamespaceRegistry: m.namespaceRegistry,
ServiceRegistry: m.serviceRegistry,
MasterCount: m.MasterCount,

EndpointRegistry: m.endpointRegistry,
EndpointInterval: 10 * time.Second,
EndpointReconciler: NewMasterCountEndpointReconciler(m.MasterCount, m.endpointRegistry),
EndpointInterval: 10 * time.Second,

SystemNamespaces: []string{api.NamespaceSystem},
SystemNamespacesInterval: 1 * time.Minute,
Expand Down
3 changes: 1 addition & 2 deletions pkg/master/master_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,9 @@ func TestNewBootstrapController(t *testing.T) {
controller := master.NewBootstrapController()

assert.Equal(controller.NamespaceRegistry, master.namespaceRegistry)
assert.Equal(controller.EndpointRegistry, master.endpointRegistry)
assert.Equal(controller.EndpointReconciler, NewMasterCountEndpointReconciler(master.MasterCount, master.endpointRegistry))
assert.Equal(controller.ServiceRegistry, master.serviceRegistry)
assert.Equal(controller.ServiceNodePortRange, portRange)
assert.Equal(controller.MasterCount, master.MasterCount)
assert.Equal(controller.ServicePort, master.ServiceReadWritePort)
assert.Equal(controller.PublicServicePort, master.PublicReadWritePort)
}
Expand Down