Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
7f688317
K
kubesphere
项目概览
水淹萌龙
/
kubesphere
与 Fork 源项目一致
Fork自
KubeSphere / kubesphere
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kubesphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
7f688317
编写于
12月 02, 2018
作者:
J
jeff
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Signed-off-by: jeff <jeffzhang@yunify.com>
refactor component status Signed-off-by:
N
jeff
<
jeffzhang@yunify.com
>
上级
0dd78409
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
62 addition
and
26 deletion
+62
-26
pkg/models/components.go
pkg/models/components.go
+51
-26
pkg/models/controllers/run.go
pkg/models/controllers/run.go
+11
-0
未找到文件。
pkg/models/components.go
浏览文件 @
7f688317
...
...
@@ -19,6 +19,10 @@ package models
import
(
"time"
v12
"k8s.io/client-go/listers/core/v1"
"kubesphere.io/kubesphere/pkg/models/controllers"
"k8s.io/apimachinery/pkg/labels"
"github.com/golang/glog"
...
...
@@ -43,12 +47,28 @@ type Component struct {
func
GetComponentStatus
(
namespace
string
,
componentName
string
)
(
interface
{},
error
)
{
k8sClient
:=
client
.
NewK8sClient
()
if
service
,
err
:=
k8sClient
.
CoreV1
()
.
Services
(
namespace
)
.
Get
(
componentName
,
meta_v1
.
GetOptions
{});
err
!=
nil
{
service
,
err
:=
k8sClient
.
CoreV1
()
.
Services
(
namespace
)
.
Get
(
componentName
,
meta_v1
.
GetOptions
{})
if
err
!=
nil
{
glog
.
Error
(
err
)
return
nil
,
err
}
else
{
set
:=
labels
.
Set
(
service
.
Spec
.
Selector
)
}
lister
,
err
:=
controllers
.
GetLister
(
controllers
.
Pods
)
if
err
!=
nil
{
glog
.
Errorln
(
err
)
return
nil
,
err
}
podLister
:=
lister
.
(
v12
.
PodLister
)
set
:=
labels
.
Set
(
service
.
Spec
.
Selector
)
pods
,
err
:=
podLister
.
Pods
(
namespace
)
.
List
(
set
.
AsSelector
())
if
err
!=
nil
{
glog
.
Errorln
(
err
)
return
nil
,
err
}
else
{
component
:=
Component
{
Name
:
service
.
Name
,
Namespace
:
service
.
Namespace
,
...
...
@@ -59,18 +79,13 @@ func GetComponentStatus(namespace string, componentName string) (interface{}, er
TotalBackends
:
0
,
}
if
pods
,
err
:=
k8sClient
.
CoreV1
()
.
Pods
(
namespace
)
.
List
(
meta_v1
.
ListOptions
{
LabelSelector
:
set
.
AsSelector
()
.
String
()});
err
!=
nil
{
glog
.
Error
(
err
)
return
nil
,
err
}
else
{
for
_
,
v
:=
range
pods
.
Items
{
component
.
TotalBackends
++
component
.
HealthyBackends
++
for
_
,
c
:=
range
v
.
Status
.
ContainerStatuses
{
if
!
c
.
Ready
{
component
.
HealthyBackends
--
break
}
for
_
,
v
:=
range
pods
{
component
.
TotalBackends
++
component
.
HealthyBackends
++
for
_
,
c
:=
range
v
.
Status
.
ContainerStatuses
{
if
!
c
.
Ready
{
component
.
HealthyBackends
--
break
}
}
}
...
...
@@ -87,6 +102,15 @@ func GetAllComponentsStatus() (map[string]interface{}, error) {
k8sClient
:=
client
.
NewK8sClient
()
lister
,
err
:=
controllers
.
GetLister
(
controllers
.
Pods
)
if
err
!=
nil
{
glog
.
Errorln
(
err
)
return
nil
,
err
}
podLister
:=
lister
.
(
v12
.
PodLister
)
for
_
,
ns
:=
range
SYSTEM_NAMESPACES
{
nsStatus
:=
make
(
map
[
string
]
interface
{})
...
...
@@ -115,18 +139,19 @@ func GetAllComponentsStatus() (map[string]interface{}, error) {
TotalBackends
:
0
,
}
if
pods
,
err
:=
k8sClient
.
CoreV1
()
.
Pods
(
ns
)
.
List
(
meta_v1
.
ListOptions
{
LabelSelector
:
set
.
AsSelector
()
.
String
()});
err
!=
nil
{
glog
.
Error
(
err
)
pods
,
err
:=
podLister
.
Pods
(
ns
)
.
List
(
set
.
AsSelector
())
if
err
!=
nil
{
glog
.
Errorln
(
err
)
continue
}
else
{
for
_
,
v
:=
range
pods
.
Items
{
component
.
TotalBackends
++
component
.
Healthy
Backends
++
for
_
,
c
:=
range
v
.
Status
.
ContainerStatuses
{
if
!
c
.
Ready
{
component
.
HealthyBackends
--
break
}
}
for
_
,
pod
:=
range
pods
{
component
.
Total
Backends
++
component
.
HealthyBackends
++
for
_
,
c
:=
range
pod
.
Status
.
ContainerStatuses
{
if
!
c
.
Ready
{
component
.
HealthyBackends
--
break
}
}
}
...
...
pkg/models/controllers/run.go
浏览文件 @
7f688317
...
...
@@ -17,6 +17,8 @@ limitations under the License.
package
controllers
import
(
"errors"
"fmt"
"time"
"github.com/golang/glog"
...
...
@@ -143,3 +145,12 @@ func Run(stopChan chan struct{}, wg *sync.WaitGroup) {
}
}
}
func
GetLister
(
controller
string
)
(
interface
{},
error
)
{
if
ctl
,
ok
:=
ResourceControllers
.
Controllers
[
controller
];
ok
{
if
ctl
.
Lister
()
!=
nil
{
return
ctl
.
Lister
(),
nil
}
}
return
nil
,
errors
.
New
(
fmt
.
Sprintf
(
"lister of %s not alive"
,
controller
))
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录