Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
2d6b7fef
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看板
提交
2d6b7fef
编写于
1月 04, 2021
作者:
R
Roland.Ma
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cascading deletion of children groups
Signed-off-by:
N
Roland.Ma
<
rolandma@yunify.com
>
上级
078dead7
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
55 addition
and
3 deletion
+55
-3
pkg/controller/group/group_controller.go
pkg/controller/group/group_controller.go
+25
-0
pkg/controller/group/group_controller_test.go
pkg/controller/group/group_controller_test.go
+27
-0
pkg/kapis/iam/v1alpha2/register.go
pkg/kapis/iam/v1alpha2/register.go
+1
-1
pkg/models/iam/am/am.go
pkg/models/iam/am/am.go
+2
-2
未找到文件。
pkg/controller/group/group_controller.go
浏览文件 @
2d6b7fef
...
...
@@ -42,6 +42,7 @@ import (
fedv1beta1lister
"kubesphere.io/kubesphere/pkg/client/listers/types/v1beta1"
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/controller/utils/controller"
"kubesphere.io/kubesphere/pkg/utils/k8sutil"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)
...
...
@@ -142,6 +143,30 @@ func (c *Controller) reconcile(key string) error {
}
}
if
group
.
Labels
!=
nil
{
// Set OwnerReferences when the group has a parent.
if
parent
,
ok
:=
group
.
Labels
[
iam1alpha2
.
GroupParent
];
ok
&&
!
k8sutil
.
IsControlledBy
(
group
.
OwnerReferences
,
"Group"
,
parent
)
{
if
g
==
nil
{
g
=
group
.
DeepCopy
()
}
groupParent
,
err
:=
c
.
groupLister
.
Get
(
parent
)
if
err
!=
nil
{
if
errors
.
IsNotFound
(
err
)
{
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"Parent group '%s' no longer exists"
,
key
))
delete
(
group
.
Labels
,
iam1alpha2
.
GroupParent
)
}
else
{
klog
.
Error
(
err
)
return
err
}
}
else
{
if
err
:=
controllerutil
.
SetControllerReference
(
groupParent
,
g
,
scheme
.
Scheme
);
err
!=
nil
{
klog
.
Error
(
err
)
return
err
}
}
}
}
if
g
!=
nil
{
if
_
,
err
=
c
.
ksClient
.
IamV1alpha2
()
.
Groups
()
.
Update
(
g
);
err
!=
nil
{
return
err
...
...
pkg/controller/group/group_controller_test.go
浏览文件 @
2d6b7fef
...
...
@@ -288,6 +288,20 @@ func (f *fixture) expectUpdateGroupsFinalizerAction(group *v1alpha2.Group) {
f
.
actions
=
append
(
f
.
actions
,
action
)
}
func
(
f
*
fixture
)
expectUpdateParentsRefAction
(
parent
,
child
*
v1alpha2
.
Group
)
{
expect
:=
child
.
DeepCopy
()
if
expect
.
Labels
==
nil
{
expect
.
Labels
=
make
(
map
[
string
]
string
,
0
)
}
controllerutil
.
SetControllerReference
(
parent
,
expect
,
scheme
.
Scheme
)
expect
.
Finalizers
=
[]
string
{
"finalizers.kubesphere.io/groups"
}
expect
.
Labels
[
constants
.
KubefedManagedLabel
]
=
"false"
action
:=
core
.
NewUpdateAction
(
schema
.
GroupVersionResource
{
Resource
:
"groups"
},
""
,
expect
)
f
.
actions
=
append
(
f
.
actions
,
action
)
}
func
(
f
*
fixture
)
expectCreateFederatedGroupsAction
(
group
*
v1alpha2
.
Group
)
{
federatedGroup
:=
newFederatedGroup
(
group
)
...
...
@@ -357,6 +371,19 @@ func TestDoNothing(t *testing.T) {
f
.
run
(
getKey
(
group
,
t
))
}
func
TestGroupCreateWithParent
(
t
*
testing
.
T
)
{
f
:=
newFixture
(
t
)
parent
:=
newGroup
(
"parent"
)
child
:=
newGroup
(
"child"
)
child
.
Labels
=
map
[
string
]
string
{
v1alpha2
.
GroupParent
:
"parent"
}
f
.
groupLister
=
append
(
f
.
groupLister
,
parent
,
child
)
f
.
objects
=
append
(
f
.
objects
,
parent
,
child
)
f
.
expectUpdateParentsRefAction
(
parent
,
child
)
f
.
run
(
getKey
(
child
,
t
))
}
func
TestFederetedGroupCreate
(
t
*
testing
.
T
)
{
f
:=
newFixture
(
t
)
...
...
pkg/kapis/iam/v1alpha2/register.go
浏览文件 @
2d6b7fef
...
...
@@ -576,7 +576,7 @@ func AddToContainer(container *restful.Container, im im.IdentityManagementInterf
Returns
(
http
.
StatusOK
,
api
.
StatusOK
,
[]
v1
.
RoleBinding
{})
.
Metadata
(
restfulspec
.
KeyOpenAPITags
,
[]
string
{
constants
.
NamespaceRoleTag
}))
ws
.
Route
(
ws
.
DELETE
(
"/namespace/{namespace}/rolebindings/{rolebinding}"
)
.
ws
.
Route
(
ws
.
DELETE
(
"/namespace
s
/{namespace}/rolebindings/{rolebinding}"
)
.
To
(
handler
.
DeleteRoleBinding
)
.
Param
(
ws
.
PathParameter
(
"workspace"
,
"workspace name"
))
.
Param
(
ws
.
PathParameter
(
"namespace"
,
"groupbinding name"
))
.
...
...
pkg/models/iam/am/am.go
浏览文件 @
2d6b7fef
...
...
@@ -1050,9 +1050,9 @@ func (am *amOperator) CreateWorkspaceRoleBinding(workspace string, roleBinding *
}
if
roleBinding
.
Subjects
[
0
]
.
Kind
==
rbacv1
.
GroupKind
{
roleBinding
.
Labels
[
iamv1alpha2
.
GroupReferenceLabel
]
=
roleBinding
.
RoleRef
.
Name
roleBinding
.
Labels
[
iamv1alpha2
.
GroupReferenceLabel
]
=
roleBinding
.
Subjects
[
0
]
.
Name
}
else
if
roleBinding
.
Subjects
[
0
]
.
Kind
==
rbacv1
.
UserKind
{
roleBinding
.
Labels
[
iamv1alpha2
.
UserReferenceLabel
]
=
roleBinding
.
RoleRef
.
Name
roleBinding
.
Labels
[
iamv1alpha2
.
UserReferenceLabel
]
=
roleBinding
.
Subjects
[
0
]
.
Name
}
roleBinding
.
Labels
[
tenantv1alpha1
.
WorkspaceLabel
]
=
workspace
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录