mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 07:27:21 +00:00
Simplify proxy config for Endpoints by removing Mux.
This commit is contained in:
@@ -166,68 +166,40 @@ func TestNewEndpointsSourceApi_UpdatesAndMultipleEndpoints(t *testing.T) {
|
||||
watchResp: fakeWatch,
|
||||
}
|
||||
|
||||
ch := make(chan EndpointsUpdate)
|
||||
stopCh := make(chan struct{})
|
||||
defer close(stopCh)
|
||||
|
||||
endpointsController := NewEndpointsController(lw, 30*time.Second, ch)
|
||||
go endpointsController.Run(wait.NeverStop)
|
||||
ch := make(chan struct{})
|
||||
handler := newEpsHandler(t, nil, func() { ch <- struct{}{} })
|
||||
|
||||
endpointsConfig := newEndpointsConfig(lw, time.Minute)
|
||||
endpointsConfig.RegisterHandler(handler)
|
||||
go endpointsConfig.Run(stopCh)
|
||||
|
||||
// Add the first endpoints
|
||||
handler.expected = []*api.Endpoints{endpoints1v1}
|
||||
fakeWatch.Add(endpoints1v1)
|
||||
got, ok := <-ch
|
||||
if !ok {
|
||||
t.Errorf("Unable to read from channel when expected")
|
||||
}
|
||||
expected := EndpointsUpdate{Op: ADD, Endpoints: endpoints1v1}
|
||||
if !apiequality.Semantic.DeepEqual(expected, got) {
|
||||
t.Errorf("Expected %#v; Got %#v", expected, got)
|
||||
}
|
||||
<-ch
|
||||
|
||||
// Add another endpoints
|
||||
handler.expected = []*api.Endpoints{endpoints1v1, endpoints2}
|
||||
fakeWatch.Add(endpoints2)
|
||||
got, ok = <-ch
|
||||
if !ok {
|
||||
t.Errorf("Unable to read from channel when expected")
|
||||
}
|
||||
// Could be sorted either of these two ways:
|
||||
expected = EndpointsUpdate{Op: ADD, Endpoints: endpoints2}
|
||||
|
||||
if !apiequality.Semantic.DeepEqual(expected, got) {
|
||||
t.Errorf("Expected %#v, Got %#v", expected, got)
|
||||
}
|
||||
<-ch
|
||||
|
||||
// Modify endpoints1
|
||||
handler.expected = []*api.Endpoints{endpoints1v2, endpoints2}
|
||||
fakeWatch.Modify(endpoints1v2)
|
||||
got, ok = <-ch
|
||||
if !ok {
|
||||
t.Errorf("Unable to read from channel when expected")
|
||||
}
|
||||
expected = EndpointsUpdate{Op: UPDATE, Endpoints: endpoints1v2}
|
||||
|
||||
if !apiequality.Semantic.DeepEqual(expected, got) {
|
||||
t.Errorf("Expected %#v, Got %#v", expected, got)
|
||||
}
|
||||
<-ch
|
||||
|
||||
// Delete endpoints1
|
||||
handler.expected = []*api.Endpoints{endpoints2}
|
||||
fakeWatch.Delete(endpoints1v2)
|
||||
got, ok = <-ch
|
||||
if !ok {
|
||||
t.Errorf("Unable to read from channel when expected")
|
||||
}
|
||||
expected = EndpointsUpdate{Op: REMOVE, Endpoints: endpoints1v2}
|
||||
if !apiequality.Semantic.DeepEqual(expected, got) {
|
||||
t.Errorf("Expected %#v, Got %#v", expected, got)
|
||||
}
|
||||
<-ch
|
||||
|
||||
// Delete endpoints2
|
||||
handler.expected = []*api.Endpoints{}
|
||||
fakeWatch.Delete(endpoints2)
|
||||
got, ok = <-ch
|
||||
if !ok {
|
||||
t.Errorf("Unable to read from channel when expected")
|
||||
}
|
||||
expected = EndpointsUpdate{Op: REMOVE, Endpoints: endpoints2}
|
||||
if !apiequality.Semantic.DeepEqual(expected, got) {
|
||||
t.Errorf("Expected %#v, Got %#v", expected, got)
|
||||
}
|
||||
<-ch
|
||||
}
|
||||
|
||||
type svcHandler struct {
|
||||
@@ -286,13 +258,6 @@ func TestInitialSync(t *testing.T) {
|
||||
// Wait for both services and endpoints handler.
|
||||
wg.Add(2)
|
||||
|
||||
svcConfig := NewServiceConfig()
|
||||
epsConfig := NewEndpointsConfig()
|
||||
svcHandler := newSvcHandler(t, []api.Service{*svc2, *svc1}, wg.Done)
|
||||
svcConfig.RegisterHandler(svcHandler)
|
||||
epsHandler := newEpsHandler(t, []*api.Endpoints{eps2, eps1}, wg.Done)
|
||||
epsConfig.RegisterHandler(epsHandler)
|
||||
|
||||
// Setup fake api client.
|
||||
fakeSvcWatch := watch.NewFake()
|
||||
svcLW := fakeLW{
|
||||
@@ -305,8 +270,16 @@ func TestInitialSync(t *testing.T) {
|
||||
watchResp: fakeEpsWatch,
|
||||
}
|
||||
|
||||
svcConfig := NewServiceConfig()
|
||||
epsConfig := newEndpointsConfig(epsLW, time.Minute)
|
||||
svcHandler := newSvcHandler(t, []api.Service{*svc2, *svc1}, wg.Done)
|
||||
svcConfig.RegisterHandler(svcHandler)
|
||||
epsHandler := newEpsHandler(t, []*api.Endpoints{eps2, eps1}, wg.Done)
|
||||
epsConfig.RegisterHandler(epsHandler)
|
||||
|
||||
stopCh := make(chan struct{})
|
||||
defer close(stopCh)
|
||||
newSourceAPI(svcLW, epsLW, time.Minute, svcConfig.Channel("one"), epsConfig.Channel("two"), stopCh)
|
||||
go epsConfig.Run(stopCh)
|
||||
newSourceAPI(svcLW, time.Minute, svcConfig.Channel("one"), stopCh)
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user