Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
20 changes: 13 additions & 7 deletions pkg/nuke/nuke.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ type ListCache map[string]map[string][]resource.Resource

// Parameters is a collection of common variables used to configure the before of the Nuke instance.
type Parameters struct {
NoDryRun bool // NoDryRun instructs Run to actually perform the remove function
Force bool // Force instructs Run to proceed without confirmation from user
ForceSleep int // ForceSleep indicates how long of a delay before proceeding with confirmation
Quiet bool // Quiet will hide resources if they have been filtered
MaxWaitRetries int // MaxWaitRetries is the total number of times a resource will be retried during wait state
NoDryRun bool // NoDryRun instructs Run to actually perform the remove function
Force bool // Force instructs Run to proceed without confirmation from user
ForceSleep int // ForceSleep indicates how long of a delay before proceeding with confirmation
Quiet bool // Quiet will hide resources if they have been filtered
MaxWaitRetries int // MaxWaitRetries is the total number of times a resource will be retried during wait state
MaxFailureRetries int // MaxFailureRetries is the total number of times a resource will be retried during failure state

// WaitOnDependencies controls whether resources will be removed after their dependencies. It is important to note
// that it does not currently track direct dependencies but instead dependent resources. For example if ResourceA
Expand Down Expand Up @@ -253,8 +254,8 @@ func (n *Nuke) handleFailure() error {
// if there are no resources being processed and there are resources in the failed state, then we enter this
// loop to determine how many times we've tried the failed resources
if processingCount == 0 && failedCount > 0 {
// if failCount is greater than 2, then we are done, print status and return failed error
if n.failedCount >= 2 {
// if failCount is greater than max failure retries, then we are done, print status and return failed error
if n.failedCount >= n.Parameters.MaxFailureRetries {
printLog.Errorf("There are resources in failed state, but none are ready for deletion, anymore.")

for _, item := range n.Queue.GetItems() {
Expand Down Expand Up @@ -357,6 +358,11 @@ func (n *Nuke) Validate() error {
return fmt.Errorf("value for --force-sleep cannot be less than 3 seconds. This is for your own protection")
}

// set a default of 3 for max failure retries
if n.Parameters.MaxFailureRetries == 0 {
n.Parameters.MaxFailureRetries = 3
}

if err := n.Filters.Validate(); err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions pkg/nuke/nuke_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ func Test_Nuke_Run_Failure(t *testing.T) {

assert.Equal(t, 1, n.Queue.Count(queue.ItemStateFinished))
assert.Equal(t, 1, n.Queue.Count(queue.ItemStateFailed))
assert.Equal(t, testParametersRemove.MaxFailureRetries, n.failedCount)
}

var testParametersMaxWaitRetries = &Parameters{
Expand Down
11 changes: 6 additions & 5 deletions pkg/nuke/nuke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ var testParameters = &Parameters{
}

var testParametersRemove = &Parameters{
Force: true,
ForceSleep: 3,
Quiet: true,
NoDryRun: true,
Force: true,
ForceSleep: 3,
Quiet: true,
NoDryRun: true,
MaxFailureRetries: 6,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

choosing a non-default number of retries here to ensure the option is honored.

}

var testParametersGroups = &Parameters{
Expand All @@ -55,7 +56,7 @@ func Test_Nuke_Version(t *testing.T) {
return
}

if e.Caller.Line == 351 {
if e.Caller.Line == 352 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By adding the new parameter, it changed the line that is triggered in this test.

assert.Equal(t, "1.0.0-test", e.Message)
assertions++
}
Expand Down