Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
凌波微步_大先生
dashboard
提交
f9a064be
D
dashboard
项目概览
凌波微步_大先生
/
dashboard
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dashboard
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
f9a064be
编写于
4月 22, 2016
作者:
P
Piotr Bryk
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #667 from bryk/async-lists
Move RC list to resource channels framework
上级
0d42e2a3
80d1465e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
231 addition
and
20 deletion
+231
-20
src/app/backend/replicationcontrollerlist.go
src/app/backend/replicationcontrollerlist.go
+33
-20
src/app/backend/resourcechannels.go
src/app/backend/resourcechannels.go
+198
-0
未找到文件。
src/app/backend/replicationcontrollerlist.go
浏览文件 @
f9a064be
...
@@ -15,13 +15,12 @@
...
@@ -15,13 +15,12 @@
package
main
package
main
import
(
import
(
"errors"
"log"
"log"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
)
)
// GetPodsEventWarningsFunc is a callback function used to get the pod status errors.
// GetPodsEventWarningsFunc is a callback function used to get the pod status errors.
...
@@ -71,35 +70,44 @@ type ReplicationController struct {
...
@@ -71,35 +70,44 @@ type ReplicationController struct {
func
GetReplicationControllerList
(
client
*
client
.
Client
)
(
*
ReplicationControllerList
,
error
)
{
func
GetReplicationControllerList
(
client
*
client
.
Client
)
(
*
ReplicationControllerList
,
error
)
{
log
.
Printf
(
"Getting list of all replication controllers in the cluster"
)
log
.
Printf
(
"Getting list of all replication controllers in the cluster"
)
listEverything
:=
api
.
ListOptions
{
channels
:=
&
ResourceChannels
{
LabelSelector
:
labels
.
Everything
(),
ReplicationControllerList
:
getReplicationControllerListChannel
(
client
,
1
),
FieldSelector
:
fields
.
Everything
(),
ServiceList
:
getServiceListChannel
(
client
,
1
),
PodList
:
getPodListChannel
(
client
,
1
),
EventList
:
getEventListChannel
(
client
,
1
),
NodeList
:
getNodeListChannel
(
client
,
1
),
}
}
replicationControllers
,
err
:=
client
.
ReplicationControllers
(
api
.
NamespaceAll
)
.
List
(
listEverything
)
return
GetReplicationControllerListFromChannels
(
channels
)
}
if
err
!=
nil
{
// GetReplicationControllerList returns a list of all Replication Controllers in the cluster
// reading required resource list once from the channels.
func
GetReplicationControllerListFromChannels
(
channels
*
ResourceChannels
)
(
*
ReplicationControllerList
,
error
)
{
replicationControllers
:=
<-
channels
.
ReplicationControllerList
.
List
if
err
:=
<-
channels
.
ReplicationControllerList
.
Error
;
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
services
,
err
:=
client
.
Services
(
api
.
NamespaceAll
)
.
List
(
listEverything
)
services
:=
<-
channels
.
ServiceList
.
List
if
err
:=
<-
channels
.
ServiceList
.
Error
;
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
pods
,
err
:=
client
.
Pods
(
api
.
NamespaceAll
)
.
List
(
listEverything
)
pods
:=
<-
channels
.
PodList
.
List
if
err
:=
<-
channels
.
PodList
.
Error
;
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
events
List
,
err
:=
client
.
Events
(
api
.
NamespaceAll
)
.
List
(
api
.
ListOptions
{
events
:=
<-
channels
.
EventList
.
List
LabelSelector
:
labels
.
Everything
(),
if
err
:=
<-
channels
.
EventList
.
Error
;
err
!=
nil
{
FieldSelector
:
fields
.
Everything
(),
return
nil
,
err
}
)
}
if
err
!=
nil
{
nodes
:=
<-
channels
.
NodeList
.
List
if
err
:=
<-
channels
.
NodeList
.
Error
;
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -107,12 +115,17 @@ func GetReplicationControllerList(client *client.Client) (*ReplicationController
...
@@ -107,12 +115,17 @@ func GetReplicationControllerList(client *client.Client) (*ReplicationController
// Function fulfils GetPodsEventWarningsFunc type contract.
// Function fulfils GetPodsEventWarningsFunc type contract.
// Based on list of api pods returns list of pod related warning events
// Based on list of api pods returns list of pod related warning events
getPodsEventWarningsFn
:=
func
(
pods
[]
api
.
Pod
)
[]
Event
{
getPodsEventWarningsFn
:=
func
(
pods
[]
api
.
Pod
)
[]
Event
{
return
GetPodsEventWarnings
(
events
List
,
pods
)
return
GetPodsEventWarnings
(
events
,
pods
)
}
}
// Anonymous callback function to get nodes by their names.
// Anonymous callback function to get nodes by their names.
getNodeFn
:=
func
(
nodeName
string
)
(
*
api
.
Node
,
error
)
{
getNodeFn
:=
func
(
nodeName
string
)
(
*
api
.
Node
,
error
)
{
return
client
.
Nodes
()
.
Get
(
nodeName
)
for
_
,
node
:=
range
nodes
.
Items
{
if
node
.
ObjectMeta
.
Name
==
nodeName
{
return
&
node
,
nil
}
}
return
nil
,
errors
.
New
(
"Cannot find node "
+
nodeName
)
}
}
result
,
err
:=
getReplicationControllerList
(
replicationControllers
.
Items
,
services
.
Items
,
result
,
err
:=
getReplicationControllerList
(
replicationControllers
.
Items
,
services
.
Items
,
...
...
src/app/backend/resourcechannels.go
0 → 100644
浏览文件 @
f9a064be
package
main
import
(
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/apis/extensions"
client
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
)
// ResourceChannels struct holds channels to resource lists. Each list channel is paired with
// an error channel which *must* be read sequentially: first read the list channel and then
// the error channel.
//
// This struct can be used when there are multiple clients that want to process, e.g., a
// list of pods. With this helper, the list can be read only once from the backend and
// distributed asynchronously to clients that need it.
//
// When a channel is nil, it means that no resource list is available for getting.
//
// Each channel pair can be read up to N times. N is specified upon creation of the channels.
type
ResourceChannels
struct
{
// List and error channels to Replication Controllers.
ReplicationControllerList
ReplicationControllerListChannel
// List and error channels to Replica Sets.
ReplicaSetList
ReplicaSetListChannel
// List and error channels to Services.
ServiceList
ServiceListChannel
// List and error channels to Pods.
PodList
PodListChannel
// List and error channels to Events.
EventList
EventListChannel
// List and error channels to Nodes.
NodeList
NodeListChannel
}
// List and error channels to Services.
type
ServiceListChannel
struct
{
List
chan
*
api
.
ServiceList
Error
chan
error
}
var
listEverything
api
.
ListOptions
=
api
.
ListOptions
{
LabelSelector
:
labels
.
Everything
(),
FieldSelector
:
fields
.
Everything
(),
}
// Returns a pair of channels to a Service list and errors that both must be read
// numReads times.
func
getServiceListChannel
(
client
*
client
.
Client
,
numReads
int
)
ServiceListChannel
{
channel
:=
ServiceListChannel
{
List
:
make
(
chan
*
api
.
ServiceList
,
numReads
),
Error
:
make
(
chan
error
,
numReads
),
}
go
func
()
{
services
,
err
:=
client
.
Services
(
api
.
NamespaceAll
)
.
List
(
listEverything
)
for
i
:=
0
;
i
<
numReads
;
i
++
{
channel
.
List
<-
services
channel
.
Error
<-
err
}
}()
return
channel
}
// List and error channels to Nodes.
type
NodeListChannel
struct
{
List
chan
*
api
.
NodeList
Error
chan
error
}
// Returns a pair of channels to a Node list and errors that both must be read
// numReads times.
func
getNodeListChannel
(
client
*
client
.
Client
,
numReads
int
)
NodeListChannel
{
channel
:=
NodeListChannel
{
List
:
make
(
chan
*
api
.
NodeList
,
numReads
),
Error
:
make
(
chan
error
,
numReads
),
}
go
func
()
{
nodes
,
err
:=
client
.
Nodes
()
.
List
(
listEverything
)
for
i
:=
0
;
i
<
numReads
;
i
++
{
channel
.
List
<-
nodes
channel
.
Error
<-
err
}
}()
return
channel
}
// List and error channels to Nodes.
type
EventListChannel
struct
{
List
chan
*
api
.
EventList
Error
chan
error
}
// Returns a pair of channels to an Event list and errors that both must be read
// numReads times.
func
getEventListChannel
(
client
*
client
.
Client
,
numReads
int
)
EventListChannel
{
channel
:=
EventListChannel
{
List
:
make
(
chan
*
api
.
EventList
,
numReads
),
Error
:
make
(
chan
error
,
numReads
),
}
go
func
()
{
events
,
err
:=
client
.
Events
(
api
.
NamespaceAll
)
.
List
(
listEverything
)
for
i
:=
0
;
i
<
numReads
;
i
++
{
channel
.
List
<-
events
channel
.
Error
<-
err
}
}()
return
channel
}
// List and error channels to Nodes.
type
PodListChannel
struct
{
List
chan
*
api
.
PodList
Error
chan
error
}
// Returns a pair of channels to a Pod list and errors that both must be read
// numReads times.
func
getPodListChannel
(
client
*
client
.
Client
,
numReads
int
)
PodListChannel
{
channel
:=
PodListChannel
{
List
:
make
(
chan
*
api
.
PodList
,
numReads
),
Error
:
make
(
chan
error
,
numReads
),
}
go
func
()
{
pods
,
err
:=
client
.
Pods
(
api
.
NamespaceAll
)
.
List
(
listEverything
)
for
i
:=
0
;
i
<
numReads
;
i
++
{
channel
.
List
<-
pods
channel
.
Error
<-
err
}
}()
return
channel
}
// List and error channels to Nodes.
type
ReplicationControllerListChannel
struct
{
List
chan
*
api
.
ReplicationControllerList
Error
chan
error
}
// Returns a pair of channels to a Replication Controller list and errors that both must be read
// numReads times.
func
getReplicationControllerListChannel
(
client
*
client
.
Client
,
numReads
int
)
ReplicationControllerListChannel
{
channel
:=
ReplicationControllerListChannel
{
List
:
make
(
chan
*
api
.
ReplicationControllerList
,
numReads
),
Error
:
make
(
chan
error
,
numReads
),
}
go
func
()
{
rcs
,
err
:=
client
.
ReplicationControllers
(
api
.
NamespaceAll
)
.
List
(
listEverything
)
for
i
:=
0
;
i
<
numReads
;
i
++
{
channel
.
List
<-
rcs
channel
.
Error
<-
err
}
}()
return
channel
}
// List and error channels to Nodes.
type
ReplicaSetListChannel
struct
{
List
chan
*
extensions
.
ReplicaSetList
Error
chan
error
}
// Returns a pair of channels to a ReplicaSet list and errors that both must be read
// numReads times.
func
getReplicaSetListChannel
(
client
*
client
.
Client
,
numReads
int
)
ReplicaSetListChannel
{
channel
:=
ReplicaSetListChannel
{
List
:
make
(
chan
*
extensions
.
ReplicaSetList
,
numReads
),
Error
:
make
(
chan
error
,
numReads
),
}
go
func
()
{
rcs
,
err
:=
client
.
ReplicaSets
(
api
.
NamespaceAll
)
.
List
(
listEverything
)
for
i
:=
0
;
i
<
numReads
;
i
++
{
channel
.
List
<-
rcs
channel
.
Error
<-
err
}
}()
return
channel
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录