-
Notifications
You must be signed in to change notification settings - Fork 122
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
support draining multiple node #469
Open
andrewhu-hcl
wants to merge
9
commits into
litmuschaos:master
Choose a base branch
from
andrewhu-hcl:support-multiple-node-drain
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5cd6d5a
support draining multiple node
andrewhu-hcl 4e8f556
Merge branch 'master' into support-multiple-node-drain
calebxu-hcl 5811f05
Merge branch 'master' into support-multiple-node-drain
calebxu-hcl 4abdd9c
node-drain: return error if no nodes specified
calebxu-hcl d449bc4
node-drain: ExperimentDetails.TargetNode is now Experiment.TargetNodes
calebxu-hcl 05726d3
node-drain: run pre/post checks on all target nodes
calebxu-hcl 96a94ec
node-drain: fix code formatting
calebxu-hcl 96f5a4c
Merge branch 'master' into support-multiple-node-drain
uditgaurav 319ea71
Merge branch 'master' into support-multiple-node-drain
uditgaurav File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,37 +114,50 @@ func PrepareNodeDrain(experimentsDetails *experimentTypes.ExperimentDetails, cli | |
// drainNode drain the application node | ||
func drainNode(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails) error { | ||
|
||
select { | ||
case <-inject: | ||
// stopping the chaos execution, if abort signal received | ||
os.Exit(0) | ||
default: | ||
log.Infof("[Inject]: Draining the %v node", experimentsDetails.TargetNode) | ||
|
||
command := exec.Command("kubectl", "drain", experimentsDetails.TargetNode, "--ignore-daemonsets", "--delete-local-data", "--force", "--timeout", strconv.Itoa(experimentsDetails.ChaosDuration)+"s") | ||
var out, stderr bytes.Buffer | ||
command.Stdout = &out | ||
command.Stderr = &stderr | ||
if err := command.Run(); err != nil { | ||
log.Infof("Error String: %v", stderr.String()) | ||
return errors.Errorf("Unable to drain the %v node, err: %v", experimentsDetails.TargetNode, err) | ||
} | ||
targetNodes := strings.Split(experimentsDetails.TargetNode, ",") | ||
|
||
common.SetTargets(experimentsDetails.TargetNode, "injected", "node", chaosDetails) | ||
log.Infof("Target nodes list: %v", targetNodes) | ||
for _, targetNode := range targetNodes { | ||
|
||
return retry. | ||
Times(uint(experimentsDetails.Timeout / experimentsDetails.Delay)). | ||
Wait(time.Duration(experimentsDetails.Delay) * time.Second). | ||
Try(func(attempt uint) error { | ||
nodeSpec, err := clients.KubeClient.CoreV1().Nodes().Get(experimentsDetails.TargetNode, v1.GetOptions{}) | ||
if err != nil { | ||
return err | ||
} | ||
if !nodeSpec.Spec.Unschedulable { | ||
return errors.Errorf("%v node is not in unschedulable state", experimentsDetails.TargetNode) | ||
} | ||
return nil | ||
}) | ||
select { | ||
case <-inject: | ||
// stopping the chaos execution, if abort signal received | ||
os.Exit(0) | ||
default: | ||
log.Infof("[Inject]: Draining the %v node", targetNode) | ||
|
||
command := exec.Command("kubectl", "drain", targetNode, "--ignore-daemonsets", "--delete-emptydir-data", "--force", "--timeout", strconv.Itoa(experimentsDetails.ChaosDuration)+"s") | ||
var out, stderr bytes.Buffer | ||
command.Stdout = &out | ||
command.Stderr = &stderr | ||
if err := command.Run(); err != nil { | ||
log.Infof("Error String: %v", stderr.String()) | ||
return errors.Errorf("Unable to drain the %v node, err: %v", experimentsDetails.TargetNode, err) | ||
} | ||
|
||
common.SetTargets(targetNode, "injected", "node", chaosDetails) | ||
|
||
err = retry. | ||
Times(uint(experimentsDetails.Timeout / experimentsDetails.Delay)). | ||
Wait(time.Duration(experimentsDetails.Delay) * time.Second). | ||
Try(func(attempt uint) error { | ||
nodeSpec, err := clients.KubeClient.CoreV1().Nodes().Get(targetNode, v1.GetOptions{}) | ||
if err != nil { | ||
if apierrors.IsNotFound(err) { | ||
return nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we add a log here to specify that the resource was not found? |
||
} else { | ||
return err | ||
} | ||
} | ||
if !nodeSpec.Spec.Unschedulable { | ||
return errors.Errorf("%v node is not in unschedulable state", targetNode) | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
return nil | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also handle the panic case when the length of the list is zero and give an error message to provide the target node name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we run chaos for more nodes we could perform the pre and post chaos check for all the target nodes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also change
experimentsDetails.TargetNode
toexperimentsDetails.TargetNodes
in the structure and other places where it is used.