Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
ba920915
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看板
未验证
提交
ba920915
编写于
11月 21, 2018
作者:
Z
zryfish
提交者:
GitHub
11月 21, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #209 from wansir/master
fix bug:db init failed,clusterrolebinding sync error
上级
f79ae414
49d40f48
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
60 addition
and
29 deletion
+60
-29
pkg/apis/v1alpha/workspaces/workspaces.go
pkg/apis/v1alpha/workspaces/workspaces.go
+16
-2
pkg/app/app.go
pkg/app/app.go
+25
-18
pkg/models/controllers/clusterrole_bindings.go
pkg/models/controllers/clusterrole_bindings.go
+1
-1
pkg/models/workspaces/types.go
pkg/models/workspaces/types.go
+2
-3
pkg/models/workspaces/workspaces.go
pkg/models/workspaces/workspaces.go
+16
-5
未找到文件。
pkg/apis/v1alpha/workspaces/workspaces.go
浏览文件 @
ba920915
...
...
@@ -15,6 +15,8 @@ import (
"regexp"
"sort"
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/models/iam"
"kubesphere.io/kubesphere/pkg/models/metrics"
...
...
@@ -452,14 +454,26 @@ func UserWorkspaceListHandler(req *restful.Request, resp *restful.Response) {
keyword
:=
req
.
QueryParameter
(
"keyword"
)
username
:=
req
.
HeaderParameter
(
UserNameHeader
)
list
,
err
:=
workspaces
.
ListWorkspaceByUser
(
username
,
keyword
)
ws
,
err
:=
workspaces
.
ListWorkspaceByUser
(
username
,
keyword
)
if
err
!=
nil
{
resp
.
WriteHeaderAndEntity
(
http
.
StatusInternalServerError
,
constants
.
MessageResponse
{
Message
:
err
.
Error
()})
return
}
resp
.
WriteEntity
(
list
)
sort
.
Slice
(
ws
,
func
(
i
,
j
int
)
bool
{
t1
,
err
:=
ws
[
i
]
.
GetCreateTime
()
if
err
!=
nil
{
return
false
}
t2
,
err
:=
ws
[
j
]
.
GetCreateTime
()
if
err
!=
nil
{
return
true
}
return
t1
.
After
(
t2
)
})
resp
.
WriteEntity
(
ws
)
}
func
UserNamespaceListHandler
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
...
...
pkg/app/app.go
浏览文件 @
ba920915
...
...
@@ -22,7 +22,6 @@ import (
"github.com/emicklei/go-restful"
"github.com/golang/glog"
"k8s.io/api/core/v1"
metaV1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"net"
...
...
@@ -38,6 +37,8 @@ import (
"sync"
"syscall"
"k8s.io/api/core/v1"
_
"kubesphere.io/kubesphere/pkg/apis/v1alpha"
"kubesphere.io/kubesphere/pkg/client"
"kubesphere.io/kubesphere/pkg/constants"
...
...
@@ -74,36 +75,42 @@ func newKubeSphereServer(options *options.ServerRunOptions) *kubeSphereServer {
func
preCheck
()
error
{
k8sClient
:=
client
.
NewK8sClient
()
_
,
err
:=
k8sClient
.
CoreV1
()
.
Namespaces
()
.
Get
(
constants
.
KubeSphereControlNamespace
,
metaV1
.
GetOptions
{})
if
err
!=
nil
&&
!
errors
.
IsNotFound
(
err
)
{
return
err
}
if
errors
.
IsNotFound
(
err
)
{
namespace
:=
v1
.
Namespace
{
ObjectMeta
:
metaV1
.
ObjectMeta
{
Name
:
constants
.
KubeSphereControlNamespace
}}
_
,
err
=
k8sClient
.
CoreV1
()
.
Namespaces
()
.
Create
(
&
namespace
)
if
err
!=
nil
{
if
err
!=
nil
{
if
errors
.
IsNotFound
(
err
)
{
_
,
err
=
k8sClient
.
CoreV1
()
.
Namespaces
()
.
Create
(
&
v1
.
Namespace
{
ObjectMeta
:
metaV1
.
ObjectMeta
{
Name
:
constants
.
KubeSphereControlNamespace
}})
if
err
!=
nil
{
return
err
}
}
else
{
return
err
}
}
_
,
err
=
k8sClient
.
AppsV1
()
.
Deployments
(
constants
.
KubeSphereControlNamespace
)
.
Get
(
constants
.
AdminUserName
,
metaV1
.
GetOptions
{})
if
errors
.
IsNotFound
(
err
)
{
models
.
CreateKubeConfig
(
constants
.
AdminUserName
)
models
.
CreateKubectlDeploy
(
constants
.
AdminUserName
)
return
nil
if
err
!=
nil
{
if
errors
.
IsNotFound
(
err
)
{
if
err
=
models
.
CreateKubeConfig
(
constants
.
AdminUserName
);
err
!=
nil
{
return
err
}
if
err
=
models
.
CreateKubectlDeploy
(
constants
.
AdminUserName
);
err
!=
nil
{
return
err
}
}
else
{
return
err
}
}
db
:=
client
.
NewSharedDBClient
()
defer
db
.
Close
()
if
!
db
.
HasTable
(
&
workspaces
.
WorkspaceNSBinding
{})
{
db
.
CreateTable
(
&
workspaces
.
WorkspaceNSBinding
{})
}
if
!
db
.
HasTable
(
&
workspaces
.
WorkspaceDPBinding
{})
{
db
.
CreateTable
(
&
workspaces
.
WorkspaceDPBinding
{})
if
err
:=
db
.
CreateTable
(
&
workspaces
.
WorkspaceDPBinding
{})
.
Error
;
err
!=
nil
{
return
err
}
}
return
err
return
nil
}
func
registerSwagger
()
{
...
...
pkg/models/controllers/clusterrole_bindings.go
浏览文件 @
ba920915
...
...
@@ -50,7 +50,7 @@ func (ctl *ClusterRoleBindingCtl) total() int {
}
func
(
ctl
*
ClusterRoleBindingCtl
)
handleWorkspaceRoleChange
(
clusterRole
*
rbac
.
ClusterRoleBinding
)
{
if
groups
:=
regexp
.
MustCompile
(
"^system:(
\\
w+):(admin|operator|viewer)$"
)
.
FindStringSubmatch
(
clusterRole
.
Name
);
len
(
groups
)
==
3
{
if
groups
:=
regexp
.
MustCompile
(
`^system:(\S+):(admin|operator|viewer)$`
)
.
FindStringSubmatch
(
clusterRole
.
Name
);
len
(
groups
)
==
3
{
workspace
:=
groups
[
1
]
go
ctl
.
restNamespaceRoleBinding
(
workspace
)
}
...
...
pkg/models/workspaces/types.go
浏览文件 @
ba920915
...
...
@@ -26,9 +26,8 @@ type Group struct {
Description
string
`json:"description"`
}
type
WorkspaceNSBinding
struct
{
Workspace
string
`gorm:"primary_key"`
Namespace
string
`gorm:"primary_key"`
func
(
g
Group
)
GetCreateTime
()
(
time
.
Time
,
error
)
{
return
time
.
Parse
(
"2006-01-02T15:04:05Z"
,
g
.
CreateTime
)
}
type
WorkspaceDPBinding
struct
{
...
...
pkg/models/workspaces/workspaces.go
浏览文件 @
ba920915
...
...
@@ -119,7 +119,7 @@ func createDefaultDevopsRoleBinding(workspace string, project DevopsProject) {
admins
:=
iam
.
GetWorkspaceUsers
(
workspace
,
"admin"
)
for
_
,
admin
:=
range
admins
{
createDevopsRoleBinding
(
workspace
,
*
project
.
ProjectId
,
admin
,
"
maintai
ner"
)
createDevopsRoleBinding
(
workspace
,
*
project
.
ProjectId
,
admin
,
"
ow
ner"
)
}
viewers
:=
iam
.
GetWorkspaceUsers
(
workspace
,
"viewer"
)
...
...
@@ -402,7 +402,11 @@ func Create(workspace *Workspace) (*Workspace, error) {
created
.
Namespaces
=
make
([]
string
,
0
)
created
.
DevopsProjects
=
make
([]
string
,
0
)
go
WorkspaceRoleInit
(
workspace
)
err
=
WorkspaceRoleInit
(
workspace
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
created
,
nil
}
...
...
@@ -512,7 +516,7 @@ func ListWorkspaceByUser(username string, keyword string) ([]*Workspace, error)
}
else
{
workspaceNames
:=
make
([]
string
,
0
)
for
_
,
clusterRole
:=
range
clusterRoles
{
if
groups
:=
regexp
.
MustCompile
(
`^system:(\
w
+):(admin|operator|viewer)$`
)
.
FindStringSubmatch
(
clusterRole
.
Name
);
len
(
groups
)
==
3
{
if
groups
:=
regexp
.
MustCompile
(
`^system:(\
S
+):(admin|operator|viewer)$`
)
.
FindStringSubmatch
(
clusterRole
.
Name
);
len
(
groups
)
==
3
{
if
!
slice
.
ContainsString
(
workspaceNames
,
groups
[
1
],
nil
)
{
workspaceNames
=
append
(
workspaceNames
,
groups
[
1
])
}
...
...
@@ -710,7 +714,14 @@ func convertGroupToWorkspace(db *gorm.DB, group Group) (*Workspace, error) {
}
func
CreateNamespace
(
namespace
*
core
.
Namespace
)
(
*
core
.
Namespace
,
error
)
{
return
client
.
NewK8sClient
()
.
CoreV1
()
.
Namespaces
()
.
Create
(
namespace
)
ns
,
err
:=
client
.
NewK8sClient
()
.
CoreV1
()
.
Namespaces
()
.
Create
(
namespace
)
if
err
!=
nil
{
return
nil
,
err
}
return
ns
,
nil
}
func
Invite
(
workspaceName
string
,
users
[]
UserInvite
)
error
{
...
...
@@ -1157,7 +1168,7 @@ func CreateWorkspaceRoleBinding(workspace *Workspace, username string, role stri
modify
=
true
roleBinding
.
Subjects
=
append
(
roleBinding
.
Subjects
,
v1
.
Subject
{
Kind
:
v1
.
UserKind
,
Name
:
username
})
if
roleName
==
"admin"
{
go
createDevopsRoleBinding
(
workspace
.
Name
,
""
,
username
,
"
maintai
ner"
)
go
createDevopsRoleBinding
(
workspace
.
Name
,
""
,
username
,
"
ow
ner"
)
}
else
if
roleName
==
"viewer"
{
go
createDevopsRoleBinding
(
workspace
.
Name
,
""
,
username
,
"reporter"
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录