Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
0dd78409
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看板
未验证
提交
0dd78409
编写于
11月 30, 2018
作者:
Z
zryfish
提交者:
GitHub
11月 30, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #220 from zryfish/refactor_resource_interface
refactor resource interface
上级
92427183
f54dd2cf
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
78 addition
and
53 deletion
+78
-53
pkg/filter/container/logFilter.go
pkg/filter/container/logFilter.go
+4
-1
pkg/models/controllers/pods.go
pkg/models/controllers/pods.go
+12
-39
pkg/models/controllers/types.go
pkg/models/controllers/types.go
+62
-13
未找到文件。
pkg/filter/container/logFilter.go
浏览文件 @
0dd78409
...
...
@@ -18,6 +18,7 @@ package container
import
(
"strings"
"time"
"github.com/emicklei/go-restful"
"github.com/golang/glog"
...
...
@@ -25,14 +26,16 @@ import (
func
logFilter
()
restful
.
FilterFunction
{
return
func
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
,
chain
*
restful
.
FilterChain
)
{
start
:=
time
.
Now
()
chain
.
ProcessFilter
(
req
,
resp
)
glog
.
Infof
(
"%s -
\"
%s %s %s
\"
%d %d"
,
glog
.
Infof
(
"%s -
\"
%s %s %s
\"
%d %d
in %dms
"
,
strings
.
Split
(
req
.
Request
.
RemoteAddr
,
":"
)[
0
],
req
.
Request
.
Method
,
req
.
Request
.
URL
.
RequestURI
(),
req
.
Request
.
Proto
,
resp
.
StatusCode
(),
resp
.
ContentLength
(),
time
.
Since
(
start
)
/
time
.
Millisecond
,
)
}
}
pkg/models/controllers/pods.go
浏览文件 @
0dd78409
...
...
@@ -166,15 +166,7 @@ func getStatusAndRestartCount(pod v1.Pod) (string, int) {
}
func
(
ctl
*
PodCtl
)
generateObject
(
item
v1
.
Pod
)
*
Pod
{
name
:=
item
.
Name
namespace
:=
item
.
Namespace
podIp
:=
item
.
Status
.
PodIP
nodeName
:=
item
.
Spec
.
NodeName
nodeIp
:=
item
.
Status
.
HostIP
status
,
restartCount
:=
getStatusAndRestartCount
(
item
)
createTime
:=
item
.
CreationTimestamp
.
Time
containerStatus
:=
item
.
Status
.
ContainerStatuses
containerSpecs
:=
item
.
Spec
.
Containers
var
ownerKind
,
ownerName
string
// For ReplicaSet,ReplicaController,DaemonSet,StatefulSet,Job,CronJob, k8s will automatically
...
...
@@ -184,37 +176,18 @@ func (ctl *PodCtl) generateObject(item v1.Pod) *Pod {
ownerName
=
item
.
OwnerReferences
[
0
]
.
Name
}
var
containers
Containers
for
_
,
containerSpec
:=
range
containerSpecs
{
var
container
Container
container
.
Name
=
containerSpec
.
Name
container
.
Image
=
containerSpec
.
Image
container
.
Ports
=
containerSpec
.
Ports
container
.
Resources
=
containerSpec
.
Resources
for
_
,
status
:=
range
containerStatus
{
if
container
.
Name
==
status
.
Name
{
container
.
Ready
=
status
.
Ready
}
}
containers
=
append
(
containers
,
container
)
}
object
:=
&
Pod
{
Namespace
:
namespace
,
Name
:
name
,
Node
:
nodeName
,
PodIp
:
podIp
,
Status
:
status
,
NodeIp
:
nodeIp
,
CreateTime
:
createTime
,
Annotation
:
MapString
{
item
.
Annotations
},
Containers
:
containers
,
RestartCount
:
restartCount
,
OwnerKind
:
ownerKind
,
OwnerName
:
ownerName
,
Labels
:
MapString
{
item
.
Labels
},
Namespace
:
item
.
Namespace
,
Name
:
item
.
Name
,
Node
:
item
.
Spec
.
NodeName
,
Status
:
item
.
Status
,
CreateTime
:
item
.
CreationTimestamp
.
Time
,
OwnerKind
:
ownerKind
,
OwnerName
:
ownerName
,
Spec
:
item
.
Spec
,
Metadata
:
item
.
ObjectMeta
,
Kind
:
item
.
TypeMeta
.
Kind
,
APIVersion
:
item
.
TypeMeta
.
APIVersion
,
}
return
object
...
...
pkg/models/controllers/types.go
浏览文件 @
0dd78409
...
...
@@ -19,6 +19,9 @@ package controllers
import
(
"time"
"github.com/golang/glog"
v12
"k8s.io/apimachinery/pkg/apis/meta/v1"
"database/sql/driver"
"encoding/json"
"errors"
...
...
@@ -210,19 +213,65 @@ type Ingress struct {
}
type
Pod
struct
{
Name
string
`gorm:"primary_key" json:"name"`
Namespace
string
`gorm:"primary_key" json:"namespace"`
Status
string
`json:"status,omitempty"`
Node
string
`json:"node,omitempty"`
NodeIp
string
`gorm:"column:nodeIp" json:"nodeIp,omitempty"`
PodIp
string
`gorm:"column:podIp" json:"podIp,omitempty"`
Containers
Containers
`gorm:"type:text" json:"containers,omitempty"`
Annotation
MapString
`json:"annotations"`
Labels
MapString
`json:"labels"`
OwnerKind
string
`gorm:"column:ownerKind" json:"ownerKind,omitempty"`
OwnerName
string
`gorm:"column:ownerName" json:"ownerName,omitempty"`
RestartCount
int
`json:"restartCount"`
CreateTime
time
.
Time
`gorm:"column:createTime" json:"createTime,omitempty"`
// search and sort field, not seen in response
Name
string
`gorm:"primary_key" json:"-"`
Namespace
string
`gorm:"primary_key" json:"-"`
Node
string
`json:"-"`
OwnerKind
string
`gorm:"column:ownerKind" json:"-"`
OwnerName
string
`gorm:"column:ownerName" json:"-"`
CreateTime
time
.
Time
`gorm:"column:createTime" json:"-"`
// Kubernetes Standard Pod Specification
Kind
string
`json:"kind,omitempty"`
APIVersion
string
`gorm:"column:apiVersion" json:"apiVersion,omitempty"`
Spec
v1
.
PodSpec
`sql:"-" json:"spec,omitempty"`
Metadata
v12
.
ObjectMeta
`sql:"-" json:"metadata,omitempty"`
Status
v1
.
PodStatus
`sql:"-" json:"status,omitempty"`
// shadow field, used only for database
MetadataString
string
`gorm:"column:metadata;type:text" json:"-"`
SpecString
string
`gorm:"column:podSpec;type:text" json:"-"`
StatusString
string
`gorm:"column:status;type:text" json:"-"`
}
func
(
pod
*
Pod
)
AfterFind
(
scope
*
gorm
.
Scope
)
(
err
error
)
{
if
err
=
json
.
Unmarshal
([]
byte
(
pod
.
SpecString
),
&
pod
.
Spec
);
err
!=
nil
{
glog
.
Errorln
(
err
)
}
if
err
=
json
.
Unmarshal
([]
byte
(
pod
.
MetadataString
),
&
pod
.
Metadata
);
err
!=
nil
{
glog
.
Errorln
(
err
)
}
if
err
=
json
.
Unmarshal
([]
byte
(
pod
.
StatusString
),
&
pod
.
Status
);
err
!=
nil
{
glog
.
Errorln
(
err
)
}
return
nil
}
func
(
pod
*
Pod
)
BeforeSave
(
scope
*
gorm
.
Scope
)
(
err
error
)
{
if
bytes
,
err
:=
json
.
Marshal
(
pod
.
Spec
);
err
==
nil
{
pod
.
SpecString
=
string
(
bytes
)
}
else
{
glog
.
Errorln
(
err
)
}
if
bytes
,
err
:=
json
.
Marshal
(
pod
.
Metadata
);
err
==
nil
{
pod
.
MetadataString
=
string
(
bytes
)
}
else
{
glog
.
Errorln
(
err
)
}
if
bytes
,
err
:=
json
.
Marshal
(
pod
.
Status
);
err
==
nil
{
pod
.
StatusString
=
string
(
bytes
)
}
else
{
glog
.
Errorln
(
err
)
}
return
nil
}
type
Container
struct
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录