Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
1e744d0a
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
1e744d0a
编写于
6月 08, 2018
作者:
W
Wiley Wang
提交者:
GitHub
6月 08, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #70 from wnxn/master
fix using nil pointer bug
上级
fc86b2e4
e75c5ffa
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
18 addition
and
8 deletion
+18
-8
pkg/apis/v1alpha/storage/storage_handler.go
pkg/apis/v1alpha/storage/storage_handler.go
+2
-2
pkg/apis/v1alpha/volumes/volumes_handler.go
pkg/apis/v1alpha/volumes/volumes_handler.go
+1
-1
pkg/models/storage.go
pkg/models/storage.go
+13
-4
pkg/models/volumes.go
pkg/models/volumes.go
+2
-1
未找到文件。
pkg/apis/v1alpha/storage/storage_handler.go
浏览文件 @
1e744d0a
...
...
@@ -22,7 +22,7 @@ func Register(ws *restful.WebService, subPath string) {
}
// List all PersistentVolumeClaims of a specific StorageClass
// Extended API URL: "GET /api/v1alpha/storage/storageclasses/{name}/persistentvolumeclaims"
// Extended API URL: "GET /api/v1alpha
1
/storage/storageclasses/{name}/persistentvolumeclaims"
func
GetPvcListBySc
(
request
*
restful
.
Request
,
response
*
restful
.
Response
)
{
scName
:=
request
.
PathParameter
(
"storageclass"
)
claims
,
err
:=
models
.
GetPvcListBySc
(
scName
)
...
...
@@ -35,7 +35,7 @@ func GetPvcListBySc(request *restful.Request, response *restful.Response) {
}
// Get metrics of a specific StorageClass
// Extended API URL: "GET /api/v1alpha/storage/storageclasses/{name}/metrics"
// Extended API URL: "GET /api/v1alpha
1
/storage/storageclasses/{name}/metrics"
func
GetScMetrics
(
request
*
restful
.
Request
,
response
*
restful
.
Response
)
{
scName
:=
request
.
PathParameter
(
"storageclass"
)
metrics
,
err
:=
models
.
GetScMetrics
(
scName
)
...
...
pkg/apis/v1alpha/volumes/volumes_handler.go
浏览文件 @
1e744d0a
...
...
@@ -17,7 +17,7 @@ func Register(ws *restful.WebService, subPath string) {
}
// List all pods of a specific PVC
// Extended API URL: "GET /api/v1alpha/volumes/namespaces/{namespace}/persistentvolumeclaims/{name}/pods"
// Extended API URL: "GET /api/v1alpha
1
/volumes/namespaces/{namespace}/persistentvolumeclaims/{name}/pods"
func
GetPodListByPvc
(
request
*
restful
.
Request
,
response
*
restful
.
Response
)
{
pvcName
:=
request
.
PathParameter
(
"pvc"
)
nsName
:=
request
.
PathParameter
(
"namespace"
)
...
...
pkg/models/storage.go
浏览文件 @
1e744d0a
...
...
@@ -23,31 +23,40 @@ type StorageMetrics struct {
Usage
string
`json:"usage,omitempty"`
}
// List persistent volume claims of a specific storage class
func
GetPvcListBySc
(
storageclass
string
)
(
res
[]
v12
.
PersistentVolumeClaim
,
err
error
)
{
// Create Kubernetes client
cli
:=
client
.
NewK8sClient
()
// Get all persistent volume claims
claimList
,
err
:=
cli
.
CoreV1
()
.
PersistentVolumeClaims
(
""
)
.
List
(
v1
.
ListOptions
{})
if
err
!=
nil
{
return
nil
,
err
}
// Select persistent volume claims which
// storage class name is equal to the specific storage class.
for
_
,
claim
:=
range
claimList
.
Items
{
if
*
claim
.
Spec
.
StorageClassName
!=
storageclass
{
if
claim
.
Spec
.
StorageClassName
!=
nil
&&
*
claim
.
Spec
.
StorageClassName
==
storageclass
{
res
=
append
(
res
,
claim
)
}
else
{
continue
}
res
=
append
(
res
,
claim
)
}
return
res
,
nil
}
// Get metrics of a specific storage class
func
GetScMetrics
(
storageclass
string
)
(
res
StorageMetrics
,
err
error
)
{
// Create Kubernetes client
cli
:=
client
.
NewK8sClient
()
// Get persistent volumes
pvList
,
err
:=
cli
.
CoreV1
()
.
PersistentVolumes
()
.
List
(
v1
.
ListOptions
{})
if
err
!=
nil
{
return
StorageMetrics
{},
err
}
var
total
resource
.
Quantity
// Gathering metrics of a specific storage class
for
_
,
volume
:=
range
pvList
.
Items
{
if
volume
.
Spec
.
StorageClassName
!=
storageclass
{
continue
...
...
pkg/models/volumes.go
浏览文件 @
1e744d0a
...
...
@@ -13,13 +13,13 @@ type PodListByPvc struct {
Pods
[]
v12
.
Pod
`json:"pods"`
}
// List pods of a specific persistent volume claims
func
GetPodListByPvc
(
pvc
string
,
ns
string
)
(
res
[]
v12
.
Pod
,
err
error
)
{
cli
:=
client
.
NewK8sClient
()
podList
,
err
:=
cli
.
CoreV1
()
.
Pods
(
ns
)
.
List
(
v1
.
ListOptions
{})
if
err
!=
nil
{
return
nil
,
err
}
for
_
,
pod
:=
range
podList
.
Items
{
if
IsPvcInPod
(
pod
,
pvc
)
==
true
{
res
=
append
(
res
,
pod
)
...
...
@@ -28,6 +28,7 @@ func GetPodListByPvc(pvc string, ns string) (res []v12.Pod, err error) {
return
res
,
nil
}
// Check if the persistent volume claim is related to the pod
func
IsPvcInPod
(
pod
v12
.
Pod
,
pvcname
string
)
bool
{
for
_
,
v
:=
range
pod
.
Spec
.
Volumes
{
if
v
.
VolumeSource
.
PersistentVolumeClaim
!=
nil
&&
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录