Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
e06c2415
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看板
未验证
提交
e06c2415
编写于
12月 06, 2018
作者:
Z
zryfish
提交者:
GitHub
12月 06, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #230 from wansir/master
fix: data error
上级
75ba702e
7b1cbabb
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
93 addition
and
29 deletion
+93
-29
pkg/apis/v1alpha/users/user.go
pkg/apis/v1alpha/users/user.go
+3
-9
pkg/app/app.go
pkg/app/app.go
+2
-1
pkg/constants/common.go
pkg/constants/common.go
+1
-0
pkg/models/controllers/clusterrole_bindings.go
pkg/models/controllers/clusterrole_bindings.go
+66
-1
pkg/models/iam/iam.go
pkg/models/iam/iam.go
+11
-16
pkg/models/kubectl/kubectl.go
pkg/models/kubectl/kubectl.go
+1
-1
pkg/models/workspaces/workspaces.go
pkg/models/workspaces/workspaces.go
+9
-1
未找到文件。
pkg/apis/v1alpha/users/user.go
浏览文件 @
e06c2415
...
...
@@ -26,6 +26,7 @@ import (
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/models"
"kubesphere.io/kubesphere/pkg/models/kubectl"
)
func
Register
(
ws
*
restful
.
WebService
,
subPath
string
)
{
...
...
@@ -54,13 +55,6 @@ func createUser(req *restful.Request, resp *restful.Response) {
return
}
err
=
models
.
CreateKubectlDeploy
(
user
)
if
err
!=
nil
{
resp
.
WriteHeaderAndEntity
(
http
.
StatusInternalServerError
,
constants
.
MessageResponse
{
Message
:
err
.
Error
()})
return
}
resp
.
WriteEntity
(
constants
.
MessageResponse
{
Message
:
"successfully created"
})
}
...
...
@@ -68,7 +62,7 @@ func delUser(req *restful.Request, resp *restful.Response) {
user
:=
req
.
PathParameter
(
"user"
)
err
:=
models
.
DelKubectlDeploy
(
user
)
err
:=
kubectl
.
DelKubectlDeploy
(
user
)
if
err
!=
nil
&&
!
apierrors
.
IsNotFound
(
err
)
{
resp
.
WriteHeaderAndEntity
(
http
.
StatusInternalServerError
,
constants
.
MessageResponse
{
Message
:
err
.
Error
()})
...
...
@@ -89,7 +83,7 @@ func getKubectl(req *restful.Request, resp *restful.Response) {
user
:=
req
.
PathParameter
(
"user"
)
kubectlPod
,
err
:=
models
.
GetKubectlPod
(
user
)
kubectlPod
,
err
:=
kubectl
.
GetKubectlPod
(
user
)
if
err
!=
nil
{
resp
.
WriteHeaderAndEntity
(
http
.
StatusInternalServerError
,
constants
.
MessageResponse
{
Message
:
err
.
Error
()})
...
...
pkg/app/app.go
浏览文件 @
e06c2415
...
...
@@ -44,6 +44,7 @@ import (
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/models"
"kubesphere.io/kubesphere/pkg/models/controllers"
"kubesphere.io/kubesphere/pkg/models/kubectl"
"kubesphere.io/kubesphere/pkg/models/workspaces"
"kubesphere.io/kubesphere/pkg/options"
)
...
...
@@ -93,7 +94,7 @@ func preCheck() error {
if
err
=
models
.
CreateKubeConfig
(
constants
.
AdminUserName
);
err
!=
nil
{
return
err
}
if
err
=
models
.
CreateKubectlDeploy
(
constants
.
AdminUserName
);
err
!=
nil
{
if
err
=
kubectl
.
CreateKubectlDeploy
(
constants
.
AdminUserName
);
err
!=
nil
{
return
err
}
}
else
{
...
...
pkg/constants/common.go
浏览文件 @
e06c2415
...
...
@@ -46,6 +46,7 @@ const (
OpenPitrixProxyTokenEnv
=
"OPENPITRIX_PROXY_TOKEN"
WorkspaceLabelKey
=
"kubesphere.io/workspace"
WorkspaceAdmin
=
"workspace-admin"
ClusterAdmin
=
"cluster-admin"
WorkspaceRegular
=
"workspace-regular"
WorkspaceViewer
=
"workspace-viewer"
DevopsOwner
=
"owner"
...
...
pkg/models/controllers/clusterrole_bindings.go
浏览文件 @
e06c2415
...
...
@@ -33,6 +33,7 @@ import (
"k8s.io/client-go/tools/cache"
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/models/kubectl"
)
func
(
ctl
*
ClusterRoleBindingCtl
)
Name
()
string
{
...
...
@@ -80,20 +81,84 @@ func (ctl *ClusterRoleBindingCtl) initListerAndInformer() {
ctl
.
informer
=
informerFactory
.
Rbac
()
.
V1
()
.
ClusterRoleBindings
()
.
Informer
()
ctl
.
informer
.
AddEventHandler
(
cache
.
ResourceEventHandlerFuncs
{
AddFunc
:
func
(
obj
interface
{})
{
clusterRoleBinding
:=
obj
.
(
*
rbac
.
ClusterRoleBinding
)
ctl
.
handleTerminalCreate
(
clusterRoleBinding
)
},
UpdateFunc
:
func
(
old
,
new
interface
{})
{
oldValue
:=
old
.
(
*
rbac
.
ClusterRoleBinding
)
newValue
:=
new
.
(
*
rbac
.
ClusterRoleBinding
)
if
!
subjectsCompile
(
oldValue
.
Subjects
,
newValue
.
Subjects
)
{
ctl
.
handleWorkspaceRoleChange
(
newValue
)
ctl
.
handleTerminalUpdate
(
oldValue
,
newValue
)
}
},
DeleteFunc
:
func
(
obj
interface
{})
{
clusterRoleBinding
:=
obj
.
(
*
rbac
.
ClusterRoleBinding
)
ctl
.
handleTerminalDelete
(
clusterRoleBinding
)
},
})
}
func
(
ctl
*
ClusterRoleBindingCtl
)
handleTerminalCreate
(
clusterRoleBinding
*
rbac
.
ClusterRoleBinding
)
{
if
clusterRoleBinding
.
RoleRef
.
Name
==
constants
.
ClusterAdmin
{
for
_
,
subject
:=
range
clusterRoleBinding
.
Subjects
{
if
subject
.
Kind
==
rbac
.
UserKind
{
err
:=
kubectl
.
CreateKubectlDeploy
(
subject
.
Name
)
if
err
!=
nil
{
glog
.
Error
(
fmt
.
Sprintf
(
"create %s's terminal pod failed:%s"
,
subject
.
Name
,
err
))
}
}
}
}
}
func
(
ctl
*
ClusterRoleBindingCtl
)
handleTerminalUpdate
(
old
*
rbac
.
ClusterRoleBinding
,
new
*
rbac
.
ClusterRoleBinding
)
{
if
new
.
RoleRef
.
Name
==
constants
.
ClusterAdmin
{
for
_
,
newSubject
:=
range
new
.
Subjects
{
isAdded
:=
true
for
_
,
oldSubject
:=
range
old
.
Subjects
{
if
oldSubject
==
newSubject
{
isAdded
=
false
break
}
}
if
isAdded
&&
newSubject
.
Kind
==
rbac
.
UserKind
{
err
:=
kubectl
.
CreateKubectlDeploy
(
newSubject
.
Name
)
if
err
!=
nil
{
glog
.
Error
(
fmt
.
Sprintf
(
"create %s's terminal pod failed:%s"
,
newSubject
.
Name
,
err
))
}
}
}
for
_
,
oldSubject
:=
range
old
.
Subjects
{
isDeleted
:=
true
for
_
,
newSubject
:=
range
new
.
Subjects
{
if
newSubject
==
oldSubject
{
isDeleted
=
false
break
}
}
if
isDeleted
&&
oldSubject
.
Kind
==
rbac
.
UserKind
{
err
:=
kubectl
.
DelKubectlDeploy
(
oldSubject
.
Name
)
if
err
!=
nil
{
glog
.
Error
(
fmt
.
Sprintf
(
"delete %s's terminal pod failed:%s"
,
oldSubject
.
Name
,
err
))
}
}
}
}
}
func
(
ctl
*
ClusterRoleBindingCtl
)
handleTerminalDelete
(
clusterRoleBinding
*
rbac
.
ClusterRoleBinding
)
{
if
clusterRoleBinding
.
RoleRef
.
Name
==
constants
.
ClusterAdmin
{
for
_
,
subject
:=
range
clusterRoleBinding
.
Subjects
{
if
subject
.
Kind
==
rbac
.
UserKind
{
err
:=
kubectl
.
DelKubectlDeploy
(
subject
.
Name
)
if
err
!=
nil
{
glog
.
Error
(
fmt
.
Sprintf
(
"delete %s's terminal pod failed:%s"
,
subject
.
Name
,
err
))
}
}
}
}
}
func
subjectsCompile
(
s1
[]
rbac
.
Subject
,
s2
[]
rbac
.
Subject
)
bool
{
if
len
(
s1
)
!=
len
(
s2
)
{
return
false
...
...
pkg/models/iam/iam.go
浏览文件 @
e06c2415
...
...
@@ -126,15 +126,9 @@ func GetUser(name string) (*User, error) {
// Get rules
func
WorkspaceRoleRules
(
workspace
string
,
roleName
string
)
(
*
v1
.
ClusterRole
,
[]
Rule
,
error
)
{
lister
,
err
:=
controllers
.
GetLister
(
controllers
.
ClusterRoles
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
clusterRoleName
:=
fmt
.
Sprintf
(
"system:%s:%s"
,
workspace
,
roleName
)
clusterRoleLister
:=
lister
.
(
v12
.
ClusterRoleLister
)
workspaceRole
,
err
:=
clusterRoleLister
.
Get
(
fmt
.
Sprintf
(
"system:%s:%s"
,
workspace
,
roleName
))
workspaceRole
,
err
:=
GetClusterRole
(
clusterRoleName
)
if
err
!=
nil
{
return
nil
,
nil
,
err
...
...
@@ -232,7 +226,7 @@ func GetRole(namespace string, name string) (*v1.Role, error) {
if
err
!=
nil
{
return
nil
,
err
}
return
role
,
nil
return
role
.
DeepCopy
()
,
nil
}
func
GetWorkspaceUsers
(
workspace
string
,
workspaceRole
string
)
([]
string
,
error
)
{
...
...
@@ -268,7 +262,7 @@ func GetClusterRoleBindings(name string) ([]v1.ClusterRoleBinding, error) {
clusterRoleBindingLister
:=
lister
.
(
v12
.
ClusterRoleBindingLister
)
clusterRoleBinding
List
,
err
:=
clusterRoleBindingLister
.
List
(
labels
.
Everything
())
clusterRoleBinding
s
,
err
:=
clusterRoleBindingLister
.
List
(
labels
.
Everything
())
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -276,9 +270,9 @@ func GetClusterRoleBindings(name string) ([]v1.ClusterRoleBinding, error) {
items
:=
make
([]
v1
.
ClusterRoleBinding
,
0
)
for
_
,
roleBinding
:=
range
clusterRoleBindingList
{
if
r
oleBinding
.
RoleRef
.
Name
==
name
{
items
=
append
(
items
,
*
r
oleBinding
)
for
_
,
clusterRoleBinding
:=
range
clusterRoleBindings
{
if
clusterR
oleBinding
.
RoleRef
.
Name
==
name
{
items
=
append
(
items
,
*
clusterR
oleBinding
)
}
}
...
...
@@ -325,7 +319,7 @@ func GetClusterRole(name string) (*v1.ClusterRole, error) {
if
err
!=
nil
{
return
nil
,
err
}
return
role
,
nil
return
role
.
DeepCopy
()
,
nil
}
func
GetRoles
(
namespace
string
,
username
string
)
([]
v1
.
Role
,
error
)
{
...
...
@@ -381,9 +375,9 @@ func GetRoles(namespace string, username string) ([]v1.Role, error) {
}
else
{
if
subject
.
Kind
==
v1
.
UserKind
&&
subject
.
Name
==
username
{
r
u
le
,
err
:=
roleLister
.
Roles
(
roleBinding
.
Namespace
)
.
Get
(
roleBinding
.
RoleRef
.
Name
)
r
o
le
,
err
:=
roleLister
.
Roles
(
roleBinding
.
Namespace
)
.
Get
(
roleBinding
.
RoleRef
.
Name
)
if
err
==
nil
{
roles
=
append
(
roles
,
*
r
u
le
)
roles
=
append
(
roles
,
*
r
o
le
)
break
}
else
if
apierrors
.
IsNotFound
(
err
)
{
glog
.
Infoln
(
err
.
Error
())
...
...
@@ -436,6 +430,7 @@ func GetClusterRoles(username string) ([]v1.ClusterRole, error) {
if
roleBinding
.
RoleRef
.
Kind
==
ClusterRoleKind
{
role
,
err
:=
clusterRoleLister
.
Get
(
roleBinding
.
RoleRef
.
Name
)
if
err
==
nil
{
role
=
role
.
DeepCopy
()
if
role
.
Annotations
==
nil
{
role
.
Annotations
=
make
(
map
[
string
]
string
,
0
)
}
...
...
pkg/models/kubectl.go
→
pkg/models/kubectl
/kubectl
.go
浏览文件 @
e06c2415
...
...
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package
models
package
kubectl
import
(
"fmt"
...
...
pkg/models/workspaces/workspaces.go
浏览文件 @
e06c2415
...
...
@@ -280,7 +280,13 @@ func Namespaces(workspaceName string) ([]*core.Namespace, error) {
return
make
([]
*
core
.
Namespace
,
0
),
nil
}
return
namespaces
,
nil
out
:=
make
([]
*
core
.
Namespace
,
len
(
namespaces
))
for
i
,
v
:=
range
namespaces
{
out
[
i
]
=
v
.
DeepCopy
()
}
return
out
,
nil
}
func
BindingDevopsProject
(
workspace
string
,
devops
string
)
error
{
...
...
@@ -841,6 +847,8 @@ func Roles(workspace *Workspace) ([]*v1.ClusterRole, error) {
return
nil
,
err
}
clusterRole
=
clusterRole
.
DeepCopy
()
clusterRole
.
Name
=
name
roles
=
append
(
roles
,
clusterRole
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录