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

use random selection of sg list to delete to handle dependencies issues #337

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 10 additions & 2 deletions controllers/osccluster_securitygroup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"io"
"math/rand"
"strings"
"time"

Expand Down Expand Up @@ -381,7 +382,7 @@ func reconcileDeleteSecurityGroupRule(ctx context.Context, clusterScope *scope.C
return reconcile.Result{}, nil
}

// reconcileDeleteSecurityGroup reconcile the deletetion of securityGroup of the cluster.
// reconicileDeleteSecurityGroup reconcile the deletetion of securityGroup of the cluster.
func reconcileDeleteSecurityGroup(ctx context.Context, clusterScope *scope.ClusterScope, securityGroupSvc security.OscSecurityGroupInterface) (reconcile.Result, error) {
osccluster := clusterScope.OscCluster

Expand All @@ -408,7 +409,11 @@ func reconcileDeleteSecurityGroup(ctx context.Context, clusterScope *scope.Clust
}
clock_time := clock.New()
clusterScope.V(4).Info("Number of securitGroup", "securityGroupLength", len(securityGroupsSpec))
for _, securityGroupSpec := range securityGroupsSpec {
for len(securityGroupsSpec) > 0 {
// choose random sg from the list to delete
randIndex := rand.Intn(len(securityGroupsSpec))
securityGroupSpec := securityGroupsSpec[randIndex]

securityGroupName := securityGroupSpec.Name + "-" + clusterScope.GetUID()
securityGroupId := securityGroupsRef.ResourceMap[securityGroupName]
if !Contains(securityGroupIds, securityGroupId) {
Expand All @@ -428,6 +433,9 @@ func reconcileDeleteSecurityGroup(ctx context.Context, clusterScope *scope.Clust
_, err := deleteSecurityGroup(ctx, clusterScope, securityGroupsRef.ResourceMap[securityGroupName], securityGroupSvc, clock_time)
if err != nil {
return reconcile.Result{}, fmt.Errorf("%w Can not delete securityGroup for Osccluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName())
} else {
// Remove deleted sg from the list
securityGroupsSpec = append(securityGroupsSpec[:randIndex], securityGroupsSpec[randIndex+1:]...)
}
}
return reconcile.Result{}, nil
Expand Down
Loading