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
96eede60
Commit
96eede60
authored
Dec 19, 2014
by
Brendan Burns
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3047 from lavalamp/optimize
Remove an unneeded trip over the network when getting/listing pods.
parents
bcf87843
a63bd1bd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
96 additions
and
3 deletions
+96
-3
master.go
pkg/master/master.go
+11
-3
rest_to_nodes.go
pkg/master/rest_to_nodes.go
+85
-0
No files found.
pkg/master/master.go
View file @
96eede60
...
...
@@ -325,6 +325,8 @@ func (m *Master) init(c *Config) {
var
userContexts
=
handlers
.
NewUserRequestContext
()
var
authenticator
=
c
.
Authenticator
nodeRESTStorage
:=
minion
.
NewREST
(
m
.
minionRegistry
)
// TODO: Factor out the core API registration
m
.
storage
=
map
[
string
]
apiserver
.
RESTStorage
{
"pods"
:
pod
.
NewREST
(
&
pod
.
RESTConfig
{
...
...
@@ -332,13 +334,19 @@ func (m *Master) init(c *Config) {
PodCache
:
podCache
,
PodInfoGetter
:
c
.
KubeletClient
,
Registry
:
m
.
podRegistry
,
Nodes
:
m
.
client
.
Nodes
(),
// Note: this allows the pod rest object to directly call
// the node rest object without going through the network &
// apiserver. This arrangement should be temporary, nodes
// shouldn't really need this at all. Once we add more auth in,
// we need to consider carefully if this sort of shortcut is a
// good idea.
Nodes
:
RESTStorageToNodes
(
nodeRESTStorage
)
.
Nodes
(),
}),
"replicationControllers"
:
controller
.
NewREST
(
m
.
controllerRegistry
,
m
.
podRegistry
),
"services"
:
service
.
NewREST
(
m
.
serviceRegistry
,
c
.
Cloud
,
m
.
minionRegistry
,
m
.
portalNet
),
"endpoints"
:
endpoint
.
NewREST
(
m
.
endpointRegistry
),
"minions"
:
minion
.
NewREST
(
m
.
minionRegistry
)
,
"nodes"
:
minion
.
NewREST
(
m
.
minionRegistry
)
,
"minions"
:
nodeRESTStorage
,
"nodes"
:
nodeRESTStorage
,
"events"
:
event
.
NewREST
(
m
.
eventRegistry
),
// TODO: should appear only in scheduler API group.
...
...
pkg/master/rest_to_nodes.go
0 → 100644
View file @
96eede60
/*
Copyright 2014 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
master
import
(
"errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
)
// RESTStorageToNodes will take a RESTStorage object and return a client interface
// which will work for any use expecting a client.Nodes() interface. The advantage
// of doing this in server code is that it doesn't require an actual trip through
// the network.
//
// TODO: considering that the only difference between the various client types
// and RESTStorage type is the type of the arguments, maybe use "go generate" to
// write a specialized adaptor for every client type?
func
RESTStorageToNodes
(
storage
apiserver
.
RESTStorage
)
client
.
NodesInterface
{
return
&
nodeAdaptor
{
storage
}
}
type
nodeAdaptor
struct
{
storage
apiserver
.
RESTStorage
}
func
(
n
*
nodeAdaptor
)
Nodes
()
client
.
NodeInterface
{
return
n
}
// Create creates a new minion.
func
(
n
*
nodeAdaptor
)
Create
(
minion
*
api
.
Node
)
(
*
api
.
Node
,
error
)
{
return
nil
,
errors
.
New
(
"direct creation not implemented"
)
// TODO: apiserver should expose newOperation to make this easier.
// the actual code that should go here would start like this:
//
// ctx := api.NewDefaultContext()
// out, err := n.storage.Create(ctx, minion)
// if err != nil {
// return nil, err
// }
}
// List lists all the nodes in the cluster.
func
(
n
*
nodeAdaptor
)
List
()
(
*
api
.
NodeList
,
error
)
{
ctx
:=
api
.
NewContext
()
obj
,
err
:=
n
.
storage
.
List
(
ctx
,
labels
.
Everything
(),
labels
.
Everything
())
if
err
!=
nil
{
return
nil
,
err
}
return
obj
.
(
*
api
.
NodeList
),
nil
}
// Get gets an existing minion
func
(
n
*
nodeAdaptor
)
Get
(
name
string
)
(
*
api
.
Node
,
error
)
{
ctx
:=
api
.
NewContext
()
obj
,
err
:=
n
.
storage
.
Get
(
ctx
,
name
)
if
err
!=
nil
{
return
nil
,
err
}
return
obj
.
(
*
api
.
Node
),
nil
}
// Delete deletes an existing minion.
// TODO: implement
func
(
n
*
nodeAdaptor
)
Delete
(
name
string
)
error
{
return
errors
.
New
(
"direct deletion not implemented"
)
}
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