Skip to content

Commit

Permalink
fix nested for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
vcatlassian committed Jun 2, 2023
1 parent 2df7147 commit 2acfe3d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
17 changes: 9 additions & 8 deletions pkg/controller/cyclenoderequest/transitioner/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package transitioner
import (
"fmt"

corev1 "k8s.io/api/core/v1"

v1 "github.com/atlassian-labs/cyclops/pkg/apis/atlassian/v1"
"github.com/atlassian-labs/cyclops/pkg/cloudprovider"
corev1 "k8s.io/api/core/v1"
)

// listReadyNodes lists nodes that are "ready". By default lists nodes that have also not been touched by Cyclops.
Expand Down Expand Up @@ -54,14 +55,14 @@ func (t *CycleNodeRequestTransitioner) getNodesToTerminate(numNodes int64) (node
return nil, 0, err
}

for _, nodeToTerminate := range t.cycleNodeRequest.Status.NodesToTerminate {
for _, kubeNode := range kubeNodes {
// Skip nodes that are already being worked on so we don't duplicate our work
if value, ok := kubeNode.Labels[cycleNodeLabel]; ok && value == t.cycleNodeRequest.Name {
numNodesInProgress++
break
}
for _, kubeNode := range kubeNodes {
// Skip nodes that are already being worked on so we don't duplicate our work
if value, ok := kubeNode.Labels[cycleNodeLabel]; ok && value == t.cycleNodeRequest.Name {
numNodesInProgress++
continue
}

for _, nodeToTerminate := range t.cycleNodeRequest.Status.NodesToTerminate {
// Add nodes that need to be terminated but have not yet been actioned
if kubeNode.Name == nodeToTerminate.Name && kubeNode.Spec.ProviderID == nodeToTerminate.ProviderID {
nodes = append(nodes, &kubeNode)
Expand Down
7 changes: 3 additions & 4 deletions pkg/controller/cyclenoderequest/transitioner/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import (
"fmt"
"time"

v1 "github.com/atlassian-labs/cyclops/pkg/apis/atlassian/v1"
"github.com/atlassian-labs/cyclops/pkg/cloudprovider"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/util/retry"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

v1 "github.com/atlassian-labs/cyclops/pkg/apis/atlassian/v1"
"github.com/atlassian-labs/cyclops/pkg/cloudprovider"
)

// transitionToHealing transitions the current cycleNodeRequest to healing which will always transiting to failed
Expand Down Expand Up @@ -108,7 +109,6 @@ func (t *CycleNodeRequestTransitioner) reapChildren() (v1.CycleNodeRequestPhase,

// Check all of the children - if any are failed, the whole CycleNodeRequest fails
inProgressCount := 0
reapedChildren := 0
for _, cycleNodeStatus := range cycleNodeStatusList.Items {
switch cycleNodeStatus.Status.Phase {
case v1.CycleNodeStatusFailed:
Expand All @@ -123,7 +123,6 @@ func (t *CycleNodeRequestTransitioner) reapChildren() (v1.CycleNodeRequestPhase,
if err != nil {
return nextPhase, err
}
reapedChildren++
default:
inProgressCount++
}
Expand Down

0 comments on commit 2acfe3d

Please sign in to comment.