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
92d95df0
Commit
92d95df0
authored
Nov 15, 2018
by
Haowei Cai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable aggregator apiserver resyncing openapi spec
from delegation apiservers
parent
076adbf4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
0 deletions
+36
-0
aggregator.go
....io/kube-aggregator/pkg/controllers/openapi/aggregator.go
+21
-0
controller.go
....io/kube-aggregator/pkg/controllers/openapi/controller.go
+15
-0
No files found.
staging/src/k8s.io/kube-aggregator/pkg/controllers/openapi/aggregator.go
View file @
92d95df0
...
@@ -53,12 +53,19 @@ type specAggregator struct {
...
@@ -53,12 +53,19 @@ type specAggregator struct {
// provided for dynamic OpenAPI spec
// provided for dynamic OpenAPI spec
openAPIService
*
handler
.
OpenAPIService
openAPIService
*
handler
.
OpenAPIService
openAPIVersionedService
*
handler
.
OpenAPIService
openAPIVersionedService
*
handler
.
OpenAPIService
// initialized is set to be true at the end of startup. All local specs
// must be registered before initialized is set, we panic otherwise.
initialized
bool
}
}
var
_
AggregationManager
=
&
specAggregator
{}
var
_
AggregationManager
=
&
specAggregator
{}
// This function is not thread safe as it only being called on startup.
// This function is not thread safe as it only being called on startup.
func
(
s
*
specAggregator
)
addLocalSpec
(
spec
*
spec
.
Swagger
,
localHandler
http
.
Handler
,
name
,
etag
string
)
{
func
(
s
*
specAggregator
)
addLocalSpec
(
spec
*
spec
.
Swagger
,
localHandler
http
.
Handler
,
name
,
etag
string
)
{
if
s
.
initialized
{
panic
(
"Local spec must not be added after startup"
)
}
localAPIService
:=
apiregistration
.
APIService
{}
localAPIService
:=
apiregistration
.
APIService
{}
localAPIService
.
Name
=
name
localAPIService
.
Name
=
name
s
.
openAPISpecs
[
name
]
=
&
openAPISpecInfo
{
s
.
openAPISpecs
[
name
]
=
&
openAPISpecInfo
{
...
@@ -69,6 +76,17 @@ func (s *specAggregator) addLocalSpec(spec *spec.Swagger, localHandler http.Hand
...
@@ -69,6 +76,17 @@ func (s *specAggregator) addLocalSpec(spec *spec.Swagger, localHandler http.Hand
}
}
}
}
// GetAPIServicesName returns the names of APIServices recorded in specAggregator.openAPISpecs.
// We use this function to pass the names of local APIServices to the controller in this package,
// so that the controller can periodically sync the OpenAPI spec from delegation API servers.
func
(
s
*
specAggregator
)
GetAPIServiceNames
()
[]
string
{
names
:=
make
([]
string
,
len
(
s
.
openAPISpecs
))
for
key
:=
range
s
.
openAPISpecs
{
names
=
append
(
names
,
key
)
}
return
names
}
// BuildAndRegisterAggregator registered OpenAPI aggregator handler. This function is not thread safe as it only being called on startup.
// BuildAndRegisterAggregator registered OpenAPI aggregator handler. This function is not thread safe as it only being called on startup.
func
BuildAndRegisterAggregator
(
downloader
*
Downloader
,
delegationTarget
server
.
DelegationTarget
,
webServices
[]
*
restful
.
WebService
,
func
BuildAndRegisterAggregator
(
downloader
*
Downloader
,
delegationTarget
server
.
DelegationTarget
,
webServices
[]
*
restful
.
WebService
,
config
*
common
.
Config
,
pathHandler
common
.
PathHandler
)
(
AggregationManager
,
error
)
{
config
*
common
.
Config
,
pathHandler
common
.
PathHandler
)
(
AggregationManager
,
error
)
{
...
@@ -124,6 +142,9 @@ func BuildAndRegisterAggregator(downloader *Downloader, delegationTarget server.
...
@@ -124,6 +142,9 @@ func BuildAndRegisterAggregator(downloader *Downloader, delegationTarget server.
return
nil
,
err
return
nil
,
err
}
}
// We set initialized to be true to forbid any future local spec addition
s
.
initialized
=
true
return
s
,
nil
return
s
,
nil
}
}
...
...
staging/src/k8s.io/kube-aggregator/pkg/controllers/openapi/controller.go
View file @
92d95df0
...
@@ -49,6 +49,9 @@ type AggregationManager interface {
...
@@ -49,6 +49,9 @@ type AggregationManager interface {
UpdateAPIServiceSpec
(
apiServiceName
string
,
spec
*
spec
.
Swagger
,
etag
string
)
error
UpdateAPIServiceSpec
(
apiServiceName
string
,
spec
*
spec
.
Swagger
,
etag
string
)
error
RemoveAPIServiceSpec
(
apiServiceName
string
)
error
RemoveAPIServiceSpec
(
apiServiceName
string
)
error
GetAPIServiceInfo
(
apiServiceName
string
)
(
handler
http
.
Handler
,
etag
string
,
exists
bool
)
GetAPIServiceInfo
(
apiServiceName
string
)
(
handler
http
.
Handler
,
etag
string
,
exists
bool
)
// GetAPIServicesName returns the names of APIServices recorded in AggregationManager.
GetAPIServiceNames
()
[]
string
}
}
// AggregationController periodically check for changes in OpenAPI specs of APIServices and update/remove
// AggregationController periodically check for changes in OpenAPI specs of APIServices and update/remove
...
@@ -72,6 +75,18 @@ func NewAggregationController(downloader *Downloader, openAPIAggregationManager
...
@@ -72,6 +75,18 @@ func NewAggregationController(downloader *Downloader, openAPIAggregationManager
}
}
c
.
syncHandler
=
c
.
sync
c
.
syncHandler
=
c
.
sync
// During initialization, openAPIAggregationManager only has record of local APIServices. There must be
// no aggregated APIService recorded, because aggregated APIServices only get added to openAPIAggregationManager
// by calling AggregationController.AddAPIService or AggregationController.UpdateAPIService after the
// controller is initialized.
// Here we add delegation target API services to queue, to periodically sync dynamic OpenAPI spec from
// delegation target.
// NOTE: openAPIAggregationManager.GetAPIServiceNames() will also return the APIService of non-name spec
// for aggregator, which has no http.Handler. The first time sync (when popping off from queue) for
// this APIService will be a no-op, and the controller will drop the APIService from queue.
for
_
,
name
:=
range
openAPIAggregationManager
.
GetAPIServiceNames
()
{
c
.
queue
.
AddAfter
(
name
,
time
.
Second
)
}
return
c
return
c
}
}
...
...
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