Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
0689ec60
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看板
未验证
提交
0689ec60
编写于
9月 21, 2020
作者:
Z
Zhengyi Lai
提交者:
GitHub
9月 21, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2976 from stoneshi-yunify/fix1109
fix: add nil check for storage class name
上级
6f12f72d
7fe78e48
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
110 addition
and
1 deletion
+110
-1
pkg/models/resources/v1alpha2/storageclass/storageclasses.go
pkg/models/resources/v1alpha2/storageclass/storageclasses.go
+1
-1
pkg/models/resources/v1alpha2/storageclass/storageclasses_test.go
...ls/resources/v1alpha2/storageclass/storageclasses_test.go
+109
-0
未找到文件。
pkg/models/resources/v1alpha2/storageclass/storageclasses.go
浏览文件 @
0689ec60
...
...
@@ -107,7 +107,7 @@ func (s *storageClassesSearcher) countPersistentVolumeClaims(name string) int {
var
count
int
for
_
,
pvc
:=
range
pvcs
{
if
*
pvc
.
Spec
.
StorageClassName
==
name
||
(
pvc
.
Annotations
!=
nil
&&
pvc
.
Annotations
[
corev1
.
BetaStorageClassAnnotation
]
==
name
)
{
if
(
pvc
.
Spec
.
StorageClassName
!=
nil
&&
*
pvc
.
Spec
.
StorageClassName
==
name
)
||
(
pvc
.
Annotations
!=
nil
&&
pvc
.
Annotations
[
corev1
.
BetaStorageClassAnnotation
]
==
name
)
{
count
++
}
}
...
...
pkg/models/resources/v1alpha2/storageclass/storageclasses_test.go
0 → 100644
浏览文件 @
0689ec60
package
storageclass
import
(
"github.com/google/go-cmp/cmp"
corev1
"k8s.io/api/core/v1"
v1
"k8s.io/api/storage/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes/fake"
"k8s.io/utils/pointer"
"kubesphere.io/kubesphere/pkg/models/resources/v1alpha2"
"kubesphere.io/kubesphere/pkg/server/params"
"testing"
)
var
(
sc1
=
&
v1
.
StorageClass
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"sc1"
,
},
}
scs
=
[]
interface
{}{
sc1
}
pvc1
=
&
corev1
.
PersistentVolumeClaim
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"pvc1"
,
Namespace
:
"default"
,
},
Spec
:
corev1
.
PersistentVolumeClaimSpec
{
VolumeName
:
"pvc1-volume"
,
StorageClassName
:
pointer
.
StringPtr
(
"sc1"
),
},
}
pvc2
=
&
corev1
.
PersistentVolumeClaim
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"pvc2"
,
Namespace
:
"default"
,
},
Spec
:
corev1
.
PersistentVolumeClaimSpec
{
VolumeName
:
"pvc2-volume"
,
},
}
pvcs
=
[]
interface
{}{
pvc1
,
pvc2
}
)
func
prepare
()
(
v1alpha2
.
Interface
,
error
)
{
client
:=
fake
.
NewSimpleClientset
()
informer
:=
informers
.
NewSharedInformerFactory
(
client
,
0
)
for
_
,
sc
:=
range
scs
{
err
:=
informer
.
Storage
()
.
V1
()
.
StorageClasses
()
.
Informer
()
.
GetIndexer
()
.
Add
(
sc
)
if
err
!=
nil
{
return
nil
,
err
}
}
for
_
,
pvc
:=
range
pvcs
{
err
:=
informer
.
Core
()
.
V1
()
.
PersistentVolumeClaims
()
.
Informer
()
.
GetIndexer
()
.
Add
(
pvc
)
if
err
!=
nil
{
return
nil
,
err
}
}
return
NewStorageClassesSearcher
(
informer
,
nil
),
nil
}
func
TestSearch
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
namespace
string
name
string
conditions
*
params
.
Conditions
orderBy
string
reverse
bool
expected
interface
{}
expectedErr
error
}{
{
namespace
:
"default"
,
name
:
sc1
.
Name
,
conditions
:
&
params
.
Conditions
{},
orderBy
:
"name"
,
reverse
:
true
,
expected
:
scs
,
expectedErr
:
nil
,
},
}
searcher
,
err
:=
prepare
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
for
_
,
test
:=
range
tests
{
got
,
err
:=
searcher
.
Search
(
test
.
namespace
,
test
.
conditions
,
test
.
orderBy
,
test
.
reverse
)
if
test
.
expectedErr
!=
nil
&&
err
!=
test
.
expectedErr
{
t
.
Errorf
(
"expected error, got nothing"
)
}
else
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
diff
:=
cmp
.
Diff
(
got
,
test
.
expected
);
diff
!=
""
{
t
.
Errorf
(
"%T differ (-got, +want): %s"
,
test
.
expected
,
diff
)
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录