cascading deletion of children groups

Signed-off-by: Roland.Ma <rolandma@yunify.com>
This commit is contained in:
Roland.Ma
2021-01-04 07:39:50 +00:00
parent 078dead7fe
commit 2d6b7fef8b
4 changed files with 55 additions and 3 deletions

View File

@@ -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)