Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
4f3007c1
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看板
提交
4f3007c1
编写于
7月 16, 2020
作者:
H
hongming
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: node status filter
Signed-off-by:
N
hongming
<
talonwan@yunify.com
>
上级
de5f4c36
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
161 addition
and
8 deletion
+161
-8
pkg/models/resources/v1alpha3/node/nodes.go
pkg/models/resources/v1alpha3/node/nodes.go
+48
-8
pkg/models/resources/v1alpha3/node/nodes_test.go
pkg/models/resources/v1alpha3/node/nodes_test.go
+113
-0
未找到文件。
pkg/models/resources/v1alpha3/node/nodes.go
浏览文件 @
4f3007c1
...
...
@@ -31,14 +31,19 @@ import (
// Those annotations were added to node only for display purposes
const
(
nodeCPURequests
=
"node.kubesphere.io/cpu-requests"
nodeMemoryRequests
=
"node.kubesphere.io/memory-requests"
nodeCPULimits
=
"node.kubesphere.io/cpu-limits"
nodeMemoryLimits
=
"node.kubesphere.io/memory-limits"
nodeCPURequestsFraction
=
"node.kubesphere.io/cpu-requests-fraction"
nodeCPULimitsFraction
=
"node.kubesphere.io/cpu-limits-fraction"
nodeMemoryRequestsFraction
=
"node.kubesphere.io/memory-requests-fraction"
nodeMemoryLimitsFraction
=
"node.kubesphere.io/memory-limits-fraction"
nodeCPURequests
=
"node.kubesphere.io/cpu-requests"
nodeMemoryRequests
=
"node.kubesphere.io/memory-requests"
nodeCPULimits
=
"node.kubesphere.io/cpu-limits"
nodeMemoryLimits
=
"node.kubesphere.io/memory-limits"
nodeCPURequestsFraction
=
"node.kubesphere.io/cpu-requests-fraction"
nodeCPULimitsFraction
=
"node.kubesphere.io/cpu-limits-fraction"
nodeMemoryRequestsFraction
=
"node.kubesphere.io/memory-requests-fraction"
nodeMemoryLimitsFraction
=
"node.kubesphere.io/memory-limits-fraction"
nodeConfigOK
v1
.
NodeConditionType
=
"ConfigOK"
nodeKubeletReady
v1
.
NodeConditionType
=
"KubeletReady"
statusRunning
=
"running"
statusWarning
=
"warning"
statusUnschedulable
=
"unschedulable"
)
type
nodesGetter
struct
{
...
...
@@ -107,6 +112,10 @@ func (c nodesGetter) filter(object runtime.Object, filter query.Filter) bool {
if
!
ok
{
return
false
}
switch
filter
.
Field
{
case
query
.
FieldStatus
:
return
getNodeStatus
(
node
)
==
string
(
filter
.
Value
)
}
return
v1alpha3
.
DefaultObjectMetaFilter
(
node
.
ObjectMeta
,
filter
)
}
...
...
@@ -177,3 +186,34 @@ func (c nodesGetter) getPodsTotalRequestAndLimits(pods []*v1.Pod) (reqs map[v1.R
}
return
}
func
getNodeStatus
(
node
*
v1
.
Node
)
string
{
if
node
.
Spec
.
Unschedulable
{
return
statusUnschedulable
}
for
_
,
condition
:=
range
node
.
Status
.
Conditions
{
if
isUnhealthyStatus
(
condition
)
{
return
statusWarning
}
}
return
statusRunning
}
var
expectedConditions
=
map
[
v1
.
NodeConditionType
]
v1
.
ConditionStatus
{
v1
.
NodeMemoryPressure
:
v1
.
ConditionFalse
,
v1
.
NodeDiskPressure
:
v1
.
ConditionFalse
,
v1
.
NodePIDPressure
:
v1
.
ConditionFalse
,
v1
.
NodeNetworkUnavailable
:
v1
.
ConditionFalse
,
nodeConfigOK
:
v1
.
ConditionTrue
,
nodeKubeletReady
:
v1
.
ConditionTrue
,
v1
.
NodeReady
:
v1
.
ConditionTrue
,
}
func
isUnhealthyStatus
(
condition
v1
.
NodeCondition
)
bool
{
expectedStatus
:=
expectedConditions
[
condition
.
Type
]
if
expectedStatus
!=
""
&&
condition
.
Status
!=
expectedStatus
{
return
true
}
return
false
}
pkg/models/resources/v1alpha3/node/nodes_test.go
浏览文件 @
4f3007c1
...
...
@@ -23,6 +23,10 @@ import (
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes/fake"
"kubesphere.io/kubesphere/pkg/api"
"kubesphere.io/kubesphere/pkg/apiserver/query"
"kubesphere.io/kubesphere/pkg/models/resources/v1alpha3"
"strconv"
"testing"
)
...
...
@@ -144,3 +148,112 @@ func TestNodesGetterGet(t *testing.T) {
}
}
func
TestListNodes
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
query
*
query
.
Query
expected
*
api
.
ListResult
}{
{
&
query
.
Query
{
Pagination
:
&
query
.
Pagination
{
Limit
:
1
,
Offset
:
0
,
},
SortBy
:
query
.
FieldName
,
Ascending
:
false
,
Filters
:
map
[
query
.
Field
]
query
.
Value
{
query
.
FieldName
:
query
.
Value
(
node2
.
Name
)},
},
&
api
.
ListResult
{
Items
:
[]
interface
{}{
node2
,
},
TotalItems
:
1
,
},
},
{
&
query
.
Query
{
Pagination
:
&
query
.
Pagination
{
Limit
:
1
,
Offset
:
0
,
},
SortBy
:
query
.
FieldName
,
Ascending
:
false
,
Filters
:
map
[
query
.
Field
]
query
.
Value
{
query
.
FieldStatus
:
query
.
Value
(
statusUnschedulable
)},
},
&
api
.
ListResult
{
Items
:
[]
interface
{}{
node1
,
},
TotalItems
:
1
,
},
},
{
&
query
.
Query
{
Pagination
:
&
query
.
Pagination
{
Limit
:
1
,
Offset
:
0
,
},
SortBy
:
query
.
FieldName
,
Ascending
:
false
,
Filters
:
map
[
query
.
Field
]
query
.
Value
{
query
.
FieldStatus
:
query
.
Value
(
statusRunning
)},
},
&
api
.
ListResult
{
Items
:
[]
interface
{}{
node2
,
},
TotalItems
:
1
,
},
},
}
getter
:=
prepare
()
for
index
,
test
:=
range
tests
{
t
.
Run
(
strconv
.
Itoa
(
index
),
func
(
t
*
testing
.
T
)
{
got
,
err
:=
getter
.
List
(
""
,
test
.
query
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
if
diff
:=
cmp
.
Diff
(
got
,
test
.
expected
);
diff
!=
""
{
t
.
Errorf
(
"%T differ (-got, +want): %s"
,
test
.
expected
,
diff
)
}
})
}
}
var
(
node1
=
&
corev1
.
Node
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"node1"
,
},
Spec
:
corev1
.
NodeSpec
{
Unschedulable
:
true
,
},
}
node2
=
&
corev1
.
Node
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"node2"
,
},
Spec
:
corev1
.
NodeSpec
{
Unschedulable
:
false
,
},
}
nodes
=
[]
*
corev1
.
Node
{
node1
,
node2
}
)
func
prepare
()
v1alpha3
.
Interface
{
fake
:=
fake
.
NewSimpleClientset
(
node1
,
node2
)
informer
:=
informers
.
NewSharedInformerFactory
(
fake
,
0
)
for
_
,
node
:=
range
nodes
{
informer
.
Core
()
.
V1
()
.
Nodes
()
.
Informer
()
.
GetIndexer
()
.
Add
(
node
)
}
return
New
(
informer
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录