mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-10 21:50:05 +00:00
Services and Endpoints weren't properly sync'ing
They need incremental changes and a resync on start.
This commit is contained in:
@@ -24,6 +24,7 @@ import (
|
||||
|
||||
// Registry is an interface for things that know how to store endpoints.
|
||||
type Registry interface {
|
||||
ListEndpoints() (*api.EndpointsList, error)
|
||||
GetEndpoints(name string) (*api.Endpoints, error)
|
||||
WatchEndpoints(labels, fields labels.Selector, resourceVersion uint64) (watch.Interface, error)
|
||||
UpdateEndpoints(e api.Endpoints) error
|
||||
|
@@ -37,14 +37,17 @@ func NewStorage(registry Registry) apiserver.RESTStorage {
|
||||
}
|
||||
}
|
||||
|
||||
// Get satisfies the RESTStorage interface but is unimplemented.
|
||||
// Get satisfies the RESTStorage interface.
|
||||
func (rs *Storage) Get(id string) (interface{}, error) {
|
||||
return rs.registry.GetEndpoints(id)
|
||||
}
|
||||
|
||||
// List satisfies the RESTStorage interface but is unimplemented.
|
||||
// List satisfies the RESTStorage interface.
|
||||
func (rs *Storage) List(selector labels.Selector) (interface{}, error) {
|
||||
return nil, errors.New("unimplemented")
|
||||
if !selector.Empty() {
|
||||
return nil, errors.New("label selectors are not supported on endpoints")
|
||||
}
|
||||
return rs.registry.ListEndpoints()
|
||||
}
|
||||
|
||||
// Watch returns Endpoint events via a watch.Interface.
|
||||
|
@@ -22,6 +22,7 @@ import (
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
|
||||
)
|
||||
|
||||
@@ -67,3 +68,29 @@ func TestGetEndpointsMissingService(t *testing.T) {
|
||||
t.Errorf("unexpected endpoints: %#v", obj)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEndpointsRegistryList(t *testing.T) {
|
||||
registry := registrytest.NewServiceRegistry()
|
||||
storage := NewStorage(registry)
|
||||
registry.EndpointsList = api.EndpointsList{
|
||||
JSONBase: api.JSONBase{ResourceVersion: 1},
|
||||
Items: []api.Endpoints{
|
||||
{JSONBase: api.JSONBase{ID: "foo"}},
|
||||
{JSONBase: api.JSONBase{ID: "bar"}},
|
||||
},
|
||||
}
|
||||
s, _ := storage.List(labels.Everything())
|
||||
sl := s.(*api.EndpointsList)
|
||||
if len(sl.Items) != 2 {
|
||||
t.Fatalf("Expected 2 endpoints, but got %v", len(sl.Items))
|
||||
}
|
||||
if e, a := "foo", sl.Items[0].ID; e != a {
|
||||
t.Errorf("Expected %v, but got %v", e, a)
|
||||
}
|
||||
if e, a := "bar", sl.Items[1].ID; e != a {
|
||||
t.Errorf("Expected %v, but got %v", e, a)
|
||||
}
|
||||
if sl.ResourceVersion != 1 {
|
||||
t.Errorf("Unexpected resource version: %#v", sl)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user