Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
767fa691
Commit
767fa691
authored
Apr 21, 2016
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #24118 from smarterclayton/proxy_args
Automatic merge from submit-queue Allow Proxy to be initialized with store
parents
09adffb3
a5152a40
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
19 deletions
+32
-19
api.go
pkg/proxy/config/api.go
+30
-17
api_test.go
pkg/proxy/config/api_test.go
+2
-2
No files found.
pkg/proxy/config/api.go
View file @
767fa691
...
@@ -21,41 +21,54 @@ import (
...
@@ -21,41 +21,54 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/client/cache"
"k8s.io/kubernetes/pkg/client/cache"
client
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/fields"
)
)
// NewSourceAPI creates config source that watches for changes to the services and endpoints.
// NewSourceAPI creates config source that watches for changes to the services and endpoints.
func
NewSourceAPI
(
c
*
client
.
Client
,
period
time
.
Duration
,
servicesChan
chan
<-
ServiceUpdate
,
endpointsChan
chan
<-
EndpointsUpdate
)
{
func
NewSourceAPI
(
c
cache
.
Getter
,
period
time
.
Duration
,
servicesChan
chan
<-
ServiceUpdate
,
endpointsChan
chan
<-
EndpointsUpdate
)
{
servicesLW
:=
cache
.
NewListWatchFromClient
(
c
,
"services"
,
api
.
NamespaceAll
,
fields
.
Everything
())
servicesLW
:=
cache
.
NewListWatchFromClient
(
c
,
"services"
,
api
.
NamespaceAll
,
fields
.
Everything
())
endpointsLW
:=
cache
.
NewListWatchFromClient
(
c
,
"endpoints"
,
api
.
NamespaceAll
,
fields
.
Everything
()
)
cache
.
NewReflector
(
servicesLW
,
&
api
.
Service
{},
NewServiceStore
(
nil
,
servicesChan
),
period
)
.
Run
(
)
newServicesSourceApiFromLW
(
servicesLW
,
period
,
servicesChan
)
endpointsLW
:=
cache
.
NewListWatchFromClient
(
c
,
"endpoints"
,
api
.
NamespaceAll
,
fields
.
Everything
()
)
newEndpointsSourceApiFromLW
(
endpointsLW
,
period
,
endpointsChan
)
cache
.
NewReflector
(
endpointsLW
,
&
api
.
Endpoints
{},
NewEndpointsStore
(
nil
,
endpointsChan
),
period
)
.
Run
(
)
}
}
func
newServicesSourceApiFromLW
(
servicesLW
cache
.
ListerWatcher
,
period
time
.
Duration
,
servicesChan
chan
<-
ServiceUpdate
)
{
// NewServiceStore creates an undelta store that expands updates to the store into
servicesPush
:=
func
(
objs
[]
interface
{})
{
// ServiceUpdate events on the channel. If no store is passed, a default store will
// be initialized. Allows reuse of a cache store across multiple components.
func
NewServiceStore
(
store
cache
.
Store
,
ch
chan
<-
ServiceUpdate
)
cache
.
Store
{
fn
:=
func
(
objs
[]
interface
{})
{
var
services
[]
api
.
Service
var
services
[]
api
.
Service
for
_
,
o
:=
range
objs
{
for
_
,
o
:=
range
objs
{
services
=
append
(
services
,
*
(
o
.
(
*
api
.
Service
)))
services
=
append
(
services
,
*
(
o
.
(
*
api
.
Service
)))
}
}
servicesChan
<-
ServiceUpdate
{
Op
:
SET
,
Services
:
services
}
ch
<-
ServiceUpdate
{
Op
:
SET
,
Services
:
services
}
}
if
store
==
nil
{
store
=
cache
.
NewStore
(
cache
.
MetaNamespaceKeyFunc
)
}
return
&
cache
.
UndeltaStore
{
Store
:
store
,
PushFunc
:
fn
,
}
}
serviceQueue
:=
cache
.
NewUndeltaStore
(
servicesPush
,
cache
.
MetaNamespaceKeyFunc
)
cache
.
NewReflector
(
servicesLW
,
&
api
.
Service
{},
serviceQueue
,
period
)
.
Run
()
}
}
func
newEndpointsSourceApiFromLW
(
endpointsLW
cache
.
ListerWatcher
,
period
time
.
Duration
,
endpointsChan
chan
<-
EndpointsUpdate
)
{
// NewEndpointsStore creates an undelta store that expands updates to the store into
endpointsPush
:=
func
(
objs
[]
interface
{})
{
// EndpointsUpdate events on the channel. If no store is passed, a default store will
// be initialized. Allows reuse of a cache store across multiple components.
func
NewEndpointsStore
(
store
cache
.
Store
,
ch
chan
<-
EndpointsUpdate
)
cache
.
Store
{
fn
:=
func
(
objs
[]
interface
{})
{
var
endpoints
[]
api
.
Endpoints
var
endpoints
[]
api
.
Endpoints
for
_
,
o
:=
range
objs
{
for
_
,
o
:=
range
objs
{
endpoints
=
append
(
endpoints
,
*
(
o
.
(
*
api
.
Endpoints
)))
endpoints
=
append
(
endpoints
,
*
(
o
.
(
*
api
.
Endpoints
)))
}
}
endpointsChan
<-
EndpointsUpdate
{
Op
:
SET
,
Endpoints
:
endpoints
}
ch
<-
EndpointsUpdate
{
Op
:
SET
,
Endpoints
:
endpoints
}
}
if
store
==
nil
{
store
=
cache
.
NewStore
(
cache
.
MetaNamespaceKeyFunc
)
}
return
&
cache
.
UndeltaStore
{
Store
:
store
,
PushFunc
:
fn
,
}
}
endpointQueue
:=
cache
.
NewUndeltaStore
(
endpointsPush
,
cache
.
MetaNamespaceKeyFunc
)
cache
.
NewReflector
(
endpointsLW
,
&
api
.
Endpoints
{},
endpointQueue
,
period
)
.
Run
()
}
}
pkg/proxy/config/api_test.go
View file @
767fa691
...
@@ -61,7 +61,7 @@ func TestNewServicesSourceApi_UpdatesAndMultipleServices(t *testing.T) {
...
@@ -61,7 +61,7 @@ func TestNewServicesSourceApi_UpdatesAndMultipleServices(t *testing.T) {
ch
:=
make
(
chan
ServiceUpdate
)
ch
:=
make
(
chan
ServiceUpdate
)
newServicesSourceApiFromLW
(
lw
,
30
*
time
.
Second
,
ch
)
cache
.
NewReflector
(
lw
,
&
api
.
Service
{},
NewServiceStore
(
nil
,
ch
),
30
*
time
.
Second
)
.
Run
(
)
got
,
ok
:=
<-
ch
got
,
ok
:=
<-
ch
if
!
ok
{
if
!
ok
{
...
@@ -172,7 +172,7 @@ func TestNewEndpointsSourceApi_UpdatesAndMultipleEndpoints(t *testing.T) {
...
@@ -172,7 +172,7 @@ func TestNewEndpointsSourceApi_UpdatesAndMultipleEndpoints(t *testing.T) {
ch
:=
make
(
chan
EndpointsUpdate
)
ch
:=
make
(
chan
EndpointsUpdate
)
newEndpointsSourceApiFromLW
(
lw
,
30
*
time
.
Second
,
ch
)
cache
.
NewReflector
(
lw
,
&
api
.
Endpoints
{},
NewEndpointsStore
(
nil
,
ch
),
30
*
time
.
Second
)
.
Run
(
)
got
,
ok
:=
<-
ch
got
,
ok
:=
<-
ch
if
!
ok
{
if
!
ok
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment