Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
bd4121d6
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,发现更多精彩内容 >>
提交
bd4121d6
编写于
6月 17, 2018
作者:
R
richardxz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add default rolebinding, and provide a workaround to process nil object when use k8s watch
上级
00883256
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
55 addition
and
32 deletion
+55
-32
pkg/models/controllers/clusterRoles.go
pkg/models/controllers/clusterRoles.go
+1
-1
pkg/models/controllers/daemonsets.go
pkg/models/controllers/daemonsets.go
+4
-4
pkg/models/controllers/deployments.go
pkg/models/controllers/deployments.go
+6
-5
pkg/models/controllers/ingresses.go
pkg/models/controllers/ingresses.go
+1
-1
pkg/models/controllers/namespaces.go
pkg/models/controllers/namespaces.go
+33
-13
pkg/models/controllers/pods.go
pkg/models/controllers/pods.go
+1
-1
pkg/models/controllers/pvcs.go
pkg/models/controllers/pvcs.go
+1
-1
pkg/models/controllers/roles.go
pkg/models/controllers/roles.go
+2
-2
pkg/models/controllers/services.go
pkg/models/controllers/services.go
+4
-2
pkg/models/controllers/statefulsets.go
pkg/models/controllers/statefulsets.go
+1
-1
pkg/models/controllers/storageclasses.go
pkg/models/controllers/storageclasses.go
+1
-1
未找到文件。
pkg/models/controllers/clusterRoles.go
浏览文件 @
bd4121d6
...
...
@@ -91,7 +91,7 @@ func (ctl *ClusterRoleCtl) listAndWatch() {
case
event
:=
<-
clusterRoleWatcher
.
ResultChan
()
:
var
role
ClusterRole
if
event
.
Object
==
nil
{
break
panic
(
"watch timeout, restart clusterRole controller"
)
}
object
:=
event
.
Object
.
(
*
v1
.
ClusterRole
)
if
event
.
Type
==
watch
.
Deleted
{
...
...
pkg/models/controllers/daemonsets.go
浏览文件 @
bd4121d6
...
...
@@ -22,7 +22,7 @@ import (
"github.com/golang/glog"
"k8s.io/api/apps/v1beta2"
meta
_v
1
"k8s.io/apimachinery/pkg/apis/meta/v1"
meta
V
1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
"kubesphere.io/kubesphere/pkg/client"
...
...
@@ -87,7 +87,7 @@ func (ctl *DaemonsetCtl) listAndWatch() {
db
=
db
.
CreateTable
(
&
Daemonset
{})
k8sClient
:=
client
.
NewK8sClient
()
deoloyList
,
err
:=
k8sClient
.
AppsV1beta2
()
.
DaemonSets
(
""
)
.
List
(
meta
_v
1
.
ListOptions
{})
deoloyList
,
err
:=
k8sClient
.
AppsV1beta2
()
.
DaemonSets
(
""
)
.
List
(
meta
V
1
.
ListOptions
{})
if
err
!=
nil
{
glog
.
Error
(
err
)
return
...
...
@@ -98,7 +98,7 @@ func (ctl *DaemonsetCtl) listAndWatch() {
db
.
Create
(
obj
)
}
watcher
,
err
:=
k8sClient
.
AppsV1beta2
()
.
DaemonSets
(
""
)
.
Watch
(
meta
_v
1
.
ListOptions
{})
watcher
,
err
:=
k8sClient
.
AppsV1beta2
()
.
DaemonSets
(
""
)
.
Watch
(
meta
V
1
.
ListOptions
{})
if
err
!=
nil
{
glog
.
Error
(
err
)
return
...
...
@@ -111,7 +111,7 @@ func (ctl *DaemonsetCtl) listAndWatch() {
case
event
:=
<-
watcher
.
ResultChan
()
:
var
ss
Daemonset
if
event
.
Object
==
nil
{
break
panic
(
"watch timeout, restart daemonset controller"
)
}
object
:=
event
.
Object
.
(
*
v1beta2
.
DaemonSet
)
if
event
.
Type
==
watch
.
Deleted
{
...
...
pkg/models/controllers/deployments.go
浏览文件 @
bd4121d6
...
...
@@ -24,8 +24,6 @@ import (
"k8s.io/api/apps/v1beta2"
metaV1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
"kubesphere.io/kubesphere/pkg/client"
)
func
(
ctl
*
DeploymentCtl
)
generateObject
(
item
v1beta2
.
Deployment
)
*
Deployment
{
...
...
@@ -46,7 +44,7 @@ func (ctl *DeploymentCtl) generateObject(item v1beta2.Deployment) *Deployment {
}
for
_
,
conditon
:=
range
item
.
Status
.
Conditions
{
if
conditon
.
Type
==
"
Progressing
"
{
if
conditon
.
Type
==
"
Available
"
{
updateTime
=
conditon
.
LastUpdateTime
.
Time
}
}
...
...
@@ -86,7 +84,7 @@ func (ctl *DeploymentCtl) listAndWatch() {
db
=
db
.
CreateTable
(
&
Deployment
{})
k8sClient
:=
c
lient
.
NewK8sClient
()
k8sClient
:=
c
tl
.
K8sClient
deoloyList
,
err
:=
k8sClient
.
AppsV1beta2
()
.
Deployments
(
""
)
.
List
(
metaV1
.
ListOptions
{})
if
err
!=
nil
{
glog
.
Error
(
err
)
...
...
@@ -96,6 +94,7 @@ func (ctl *DeploymentCtl) listAndWatch() {
for
_
,
item
:=
range
deoloyList
.
Items
{
obj
:=
ctl
.
generateObject
(
item
)
db
.
Create
(
obj
)
}
watcher
,
err
:=
k8sClient
.
AppsV1beta2
()
.
Deployments
(
""
)
.
Watch
(
metaV1
.
ListOptions
{})
...
...
@@ -105,13 +104,14 @@ func (ctl *DeploymentCtl) listAndWatch() {
}
for
{
glog
.
Error
(
"here"
)
select
{
case
<-
ctl
.
stopChan
:
return
case
event
:=
<-
watcher
.
ResultChan
()
:
var
deploy
Deployment
if
event
.
Object
==
nil
{
break
panic
(
"watch timeout, restart deployment controller"
)
}
object
:=
event
.
Object
.
(
*
v1beta2
.
Deployment
)
if
event
.
Type
==
watch
.
Deleted
{
...
...
@@ -123,6 +123,7 @@ func (ctl *DeploymentCtl) listAndWatch() {
db
.
Save
(
obj
)
}
}
}
func
(
ctl
*
DeploymentCtl
)
CountWithConditions
(
conditions
string
)
int
{
...
...
pkg/models/controllers/ingresses.go
浏览文件 @
bd4121d6
...
...
@@ -98,7 +98,7 @@ func (ctl *IngressCtl) listAndWatch() {
case
event
:=
<-
watcher
.
ResultChan
()
:
var
ing
Ingress
if
event
.
Object
==
nil
{
break
panic
(
"watch timeout, restart ingress controller"
)
}
object
:=
event
.
Object
.
(
*
v1beta1
.
Ingress
)
if
event
.
Type
==
watch
.
Deleted
{
...
...
pkg/models/controllers/namespaces.go
浏览文件 @
bd4121d6
...
...
@@ -35,12 +35,13 @@ import (
)
const
(
provider
=
"kubernetes"
admin
=
"admin"
normal
=
"normal"
view
=
"view"
kubectlNamespace
=
"kubesphere"
kubectlConfigKey
=
"config"
provider
=
"kubernetes"
admin
=
"admin"
normal
=
"normal"
view
=
"view"
kubectlNamespace
=
"kubesphere"
kubectlConfigKey
=
"config"
openpitrix_runtime
=
"openpitrix_runtime"
)
var
adminRules
=
[]
rbac
.
PolicyRule
{
rbac
.
PolicyRule
{
Verbs
:
[]
string
{
"*"
},
APIGroups
:
[]
string
{
"*"
},
Resources
:
[]
string
{
"*"
}}}
...
...
@@ -132,13 +133,26 @@ func (ctl *NamespaceCtl) createOpRuntime(namespace, user string) ([]byte, error)
return
makeHttpRequest
(
"POST"
,
url
,
string
(
body
))
}
func
(
ctl
*
NamespaceCtl
)
createDefaultRole
(
ns
string
)
error
{
defer
func
()
{
if
err
:=
recover
();
err
!=
nil
{
func
(
ctl
*
NamespaceCtl
)
createDefaultRoleBinding
(
ns
,
user
string
)
error
{
rolebinding
,
_
:=
ctl
.
K8sClient
.
RbacV1
()
.
RoleBindings
(
ns
)
.
Get
(
admin
,
metaV1
.
GetOptions
{})
if
rolebinding
.
Name
!=
admin
{
roleBinding
:=
&
rbac
.
RoleBinding
{
ObjectMeta
:
metaV1
.
ObjectMeta
{
Name
:
admin
,
Namespace
:
ns
},
Subjects
:
[]
rbac
.
Subject
{{
Name
:
user
,
Kind
:
rbac
.
UserKind
}},
RoleRef
:
rbac
.
RoleRef
{
Kind
:
"Role"
,
Name
:
admin
}}
_
,
err
:=
ctl
.
K8sClient
.
RbacV1
()
.
RoleBindings
(
ns
)
.
Create
(
roleBinding
)
if
err
!=
nil
{
glog
.
Error
(
err
)
return
err
}
}
()
}
return
nil
}
func
(
ctl
*
NamespaceCtl
)
createDefaultRole
(
ns
string
)
error
{
adminRole
:=
&
rbac
.
Role
{
ObjectMeta
:
metaV1
.
ObjectMeta
{
Name
:
admin
,
Namespace
:
ns
},
Rules
:
adminRules
}
normalRole
:=
&
rbac
.
Role
{
ObjectMeta
:
metaV1
.
ObjectMeta
{
Name
:
normal
,
Namespace
:
ns
},
Rules
:
normalRules
}
viewRole
:=
&
rbac
.
Role
{
ObjectMeta
:
metaV1
.
ObjectMeta
{
Name
:
view
,
Namespace
:
ns
},
Rules
:
viewRules
}
...
...
@@ -178,11 +192,17 @@ func (ctl *NamespaceCtl) createDefaultRole(ns string) error {
func
(
ctl
*
NamespaceCtl
)
createRoleAndRuntime
(
item
v1
.
Namespace
)
{
user
:=
item
.
Annotations
[
"creator"
]
ns
:=
item
.
Name
if
len
(
user
)
>
0
&&
len
(
item
.
Annotations
[
"openpitrix_runtime"
])
==
0
{
if
len
(
user
)
>
0
&&
len
(
item
.
Annotations
[
openpitrix_runtime
])
==
0
{
err
:=
ctl
.
createDefaultRole
(
ns
)
if
err
!=
nil
{
return
}
err
=
ctl
.
createDefaultRoleBinding
(
ns
,
user
)
if
err
!=
nil
{
return
}
resp
,
err
:=
ctl
.
createOpRuntime
(
ns
,
user
)
if
err
!=
nil
{
return
...
...
@@ -194,7 +214,7 @@ func (ctl *NamespaceCtl) createRoleAndRuntime(item v1.Namespace) {
return
}
item
.
Annotations
[
"openpitrix_runtime"
]
=
runtime
.
RuntimeId
item
.
Annotations
[
openpitrix_runtime
]
=
runtime
.
RuntimeId
ctl
.
K8sClient
.
CoreV1
()
.
Namespaces
()
.
Update
(
&
item
)
}
}
...
...
@@ -259,7 +279,7 @@ func (ctl *NamespaceCtl) listAndWatch() {
case
event
:=
<-
watcher
.
ResultChan
()
:
var
ns
Namespace
if
event
.
Object
==
nil
{
break
panic
(
"watch timeout, restart namespace controller"
)
}
object
:=
event
.
Object
.
(
*
v1
.
Namespace
)
if
event
.
Type
==
watch
.
Deleted
{
...
...
pkg/models/controllers/pods.go
浏览文件 @
bd4121d6
...
...
@@ -106,7 +106,7 @@ func (ctl *PodCtl) listAndWatch() {
case
event
:=
<-
watcher
.
ResultChan
()
:
var
po
Pod
if
event
.
Object
==
nil
{
break
panic
(
"watch timeout, restart pod controller"
)
}
object
:=
event
.
Object
.
(
*
v1
.
Pod
)
if
event
.
Type
==
watch
.
Deleted
{
...
...
pkg/models/controllers/pvcs.go
浏览文件 @
bd4121d6
...
...
@@ -111,7 +111,7 @@ func (ctl *PvcCtl) listAndWatch() {
case
event
:=
<-
watcher
.
ResultChan
()
:
var
pvc
Pvc
if
event
.
Object
==
nil
{
break
panic
(
"watch timeout, restart pvc controller"
)
}
object
:=
event
.
Object
.
(
*
v1
.
PersistentVolumeClaim
)
if
event
.
Type
==
watch
.
Deleted
{
...
...
pkg/models/controllers/roles.go
浏览文件 @
bd4121d6
...
...
@@ -92,10 +92,10 @@ func (ctl *RoleCtl) listAndWatch() {
return
case
event
:=
<-
roleWatcher
.
ResultChan
()
:
var
role
Role
object
:=
event
.
Object
.
(
*
v1
.
Role
)
if
event
.
Object
==
nil
{
break
panic
(
"watch timeout, restart role controller"
)
}
object
:=
event
.
Object
.
(
*
v1
.
Role
)
if
event
.
Type
==
watch
.
Deleted
{
db
.
Where
(
"name=? And namespace=?"
,
object
.
Name
,
object
.
Namespace
)
.
Find
(
&
role
)
db
.
Delete
(
role
)
...
...
pkg/models/controllers/services.go
浏览文件 @
bd4121d6
...
...
@@ -167,10 +167,12 @@ func (ctl *ServiceCtl) listAndWatch() {
return
case
event
:=
<-
watcher
.
ResultChan
()
:
var
svc
Service
object
:=
event
.
Object
.
(
*
v1
.
Service
)
if
event
.
Object
==
nil
{
break
panic
(
"watch timeout, restart service controller"
)
}
object
:=
event
.
Object
.
(
*
v1
.
Service
)
if
event
.
Type
==
watch
.
Deleted
{
db
.
Where
(
"name=? And namespace=?"
,
object
.
Name
,
object
.
Namespace
)
.
Find
(
&
svc
)
db
.
Delete
(
svc
)
...
...
pkg/models/controllers/statefulsets.go
浏览文件 @
bd4121d6
...
...
@@ -106,7 +106,7 @@ func (ctl *StatefulsetCtl) listAndWatch() {
case
event
:=
<-
watcher
.
ResultChan
()
:
var
tmp
Statefulset
if
event
.
Object
==
nil
{
break
panic
(
"watch timeout, restart statefulset controller"
)
}
object
:=
event
.
Object
.
(
*
v1beta2
.
StatefulSet
)
if
event
.
Type
==
watch
.
Deleted
{
...
...
pkg/models/controllers/storageclasses.go
浏览文件 @
bd4121d6
...
...
@@ -90,7 +90,7 @@ func (ctl *StorageClassCtl) listAndWatch() {
case
event
:=
<-
watcher
.
ResultChan
()
:
var
sc
StorageClass
if
event
.
Object
==
nil
{
break
panic
(
"watch timeout, restart storageClass controller"
)
}
object
:=
event
.
Object
.
(
*
v1beta1
.
StorageClass
)
if
event
.
Type
==
watch
.
Deleted
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录