Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Delete resources in parallel #626

Merged
merged 1 commit into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 57 additions & 14 deletions controllers/operandrequest/reconcile_operand.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"reflect"
"strings"
"sync"
"time"

olmv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
Expand Down Expand Up @@ -286,6 +287,10 @@ func (r *Reconciler) deleteAllCustomResource(ctx context.Context, csv *olmv1alph
}

merr := &util.MultiErr{}
var (
mu sync.Mutex
wg sync.WaitGroup
)
for index, opdMember := range customeResourceMap {
crShouldBeDeleted := unstructured.Unstructured{
Object: map[string]interface{}{
Expand All @@ -296,12 +301,27 @@ func (r *Reconciler) deleteAllCustomResource(ctx context.Context, csv *olmv1alph
},
},
}
if err := r.deleteCustomResource(ctx, crShouldBeDeleted, requestInstance.Namespace); err != nil {
merr.Add(err)
}
operatorName := strings.Split(index, "/")[0]
requestInstance.RemoveMemberCRStatus(operatorName, opdMember.Name, opdMember.Kind)

var (
operatorName = strings.Split(index, "/")[0]
opdMember = opdMember
)

wg.Add(1)
go func() {
defer wg.Done()
if err := r.deleteCustomResource(ctx, crShouldBeDeleted, requestInstance.Namespace); err != nil {
mu.Lock()
defer mu.Unlock()
merr.Add(err)
}
mu.Lock()
defer mu.Unlock()
requestInstance.RemoveMemberCRStatus(operatorName, opdMember.Name, opdMember.Kind)
}()
}
wg.Wait()

if len(merr.Errors) != 0 {
return merr
}
Expand Down Expand Up @@ -350,16 +370,22 @@ func (r *Reconciler) deleteAllCustomResource(ctx context.Context, csv *olmv1alph
continue
}
if checkLabel(unstruct, map[string]string{constant.OpreqLabel: "true"}) {
err := r.deleteCustomResource(ctx, unstruct, namespace)
if err != nil {
return err
}
wg.Add(1)
go func() {
defer wg.Done()
if err := r.deleteCustomResource(ctx, unstruct, namespace); err != nil {
mu.Lock()
defer mu.Unlock()
merr.Add(err)
}
}()
}

}

}
}
wg.Wait()
if len(merr.Errors) != 0 {
return merr
}
Expand Down Expand Up @@ -591,6 +617,11 @@ func (r *Reconciler) checkCustomResource(ctx context.Context, requestInstance *o
}
}

var (
mu sync.Mutex
wg sync.WaitGroup
)

merr := &util.MultiErr{}
for index, opdMember := range customeResourceMap {
crShouldBeDeleted := unstructured.Unstructured{
Expand All @@ -602,12 +633,24 @@ func (r *Reconciler) checkCustomResource(ctx context.Context, requestInstance *o
},
},
}
if err := r.deleteCustomResource(ctx, crShouldBeDeleted, requestInstance.Namespace); err != nil {
merr.Add(err)
}
operatorName := strings.Split(index, "/")[0]
requestInstance.RemoveMemberCRStatus(operatorName, opdMember.Name, opdMember.Kind)

var (
operatorName = strings.Split(index, "/")[0]
opdMember = opdMember
)
wg.Add(1)
go func() {
if err := r.deleteCustomResource(ctx, crShouldBeDeleted, requestInstance.Namespace); err != nil {
mu.Lock()
defer mu.Unlock()
merr.Add(err)
}
mu.Lock()
defer mu.Unlock()
requestInstance.RemoveMemberCRStatus(operatorName, opdMember.Name, opdMember.Kind)
}()
}
wg.Wait()

if len(merr.Errors) != 0 {
return merr
Expand Down
23 changes: 20 additions & 3 deletions controllers/operandrequest/reconcile_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"encoding/json"
"fmt"
"sync"

gset "github.com/deckarep/golang-set"
olmv1 "github.com/operator-framework/api/pkg/operators/v1"
Expand Down Expand Up @@ -265,6 +266,12 @@ func (r *Reconciler) absentOperatorsAndOperands(ctx context.Context, requestInst
if err != nil {
return err
}

var (
mu sync.Mutex
wg sync.WaitGroup
)

for _, req := range requestInstance.Spec.Requests {
registryKey := requestInstance.GetRegistryKey(req)
registryInstance, err := r.GetOperandRegistry(ctx, registryKey)
Expand All @@ -277,10 +284,20 @@ func (r *Reconciler) absentOperatorsAndOperands(ctx context.Context, requestInst
}
merr := &util.MultiErr{}
for o := range needDeletedOperands.Iter() {
if err := r.deleteSubscription(ctx, fmt.Sprintf("%v", o), requestInstance, registryInstance, configInstance); err != nil {
merr.Add(err)
}
var (
o = o
)
wg.Add(1)
go func() {
defer wg.Done()
if err := r.deleteSubscription(ctx, fmt.Sprintf("%v", o), requestInstance, registryInstance, configInstance); err != nil {
mu.Lock()
defer mu.Unlock()
merr.Add(err)
}
}()
}
wg.Wait()
if len(merr.Errors) != 0 {
return merr
}
Expand Down