Skip to content

Commit

Permalink
node-drain: ExperimentDetails.TargetNode is now Experiment.TargetNodes
Browse files Browse the repository at this point in the history
Signed-off-by: Caleb Xu <[email protected]>
  • Loading branch information
calebxu-hcl committed Jan 17, 2022
1 parent 4abdd9c commit d449bc4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions chaoslib/litmus/node-drain/lib/node-drain.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ func PrepareNodeDrain(experimentsDetails *experimentTypes.ExperimentDetails, cli
common.WaitForDuration(experimentsDetails.RampTime)
}

if experimentsDetails.TargetNode == "" {
if experimentsDetails.TargetNodes == "" {
//Select node for kubelet-service-kill
experimentsDetails.TargetNode, err = common.GetNodeName(experimentsDetails.AppNS, experimentsDetails.AppLabel, experimentsDetails.NodeLabel, clients)
experimentsDetails.TargetNodes, err = common.GetNodeName(experimentsDetails.AppNS, experimentsDetails.AppLabel, experimentsDetails.NodeLabel, clients)
if err != nil {
return err
}
}

if experimentsDetails.EngineName != "" {
msg := "Injecting " + experimentsDetails.ExperimentName + " chaos on " + experimentsDetails.TargetNode + " node"
msg := "Injecting " + experimentsDetails.ExperimentName + " chaos on " + experimentsDetails.TargetNodes + " node"
types.SetEngineEventAttributes(eventsDetails, types.ChaosInject, msg, "Normal", chaosDetails)
events.GenerateEvents(eventsDetails, clients, chaosDetails, "ChaosEngine")
}
Expand Down Expand Up @@ -114,7 +114,7 @@ func PrepareNodeDrain(experimentsDetails *experimentTypes.ExperimentDetails, cli
// drainNode drain the application node
func drainNode(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails) error {

targetNodes := strings.Split(experimentsDetails.TargetNode, ",")
targetNodes := strings.Split(experimentsDetails.TargetNodes, ",")
if len(targetNodes) == 0 {
return errors.Errorf("No target nodes provided, expected the comma-separated names of one or more nodes")
}
Expand All @@ -135,7 +135,7 @@ func drainNode(experimentsDetails *experimentTypes.ExperimentDetails, clients cl
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)
return errors.Errorf("Unable to drain the %v node, err: %v", targetNode, err)
}

common.SetTargets(targetNode, "injected", "node", chaosDetails)
Expand Down Expand Up @@ -218,7 +218,7 @@ func uncordonNode(experimentsDetails *experimentTypes.ExperimentDetails, clients
}
}
if nodeSpec.Spec.Unschedulable {
return errors.Errorf("%v node is in unschedulable state", experimentsDetails.TargetNode)
return errors.Errorf("%v node is in unschedulable state", targetNode)
}
}
return nil
Expand Down
6 changes: 3 additions & 3 deletions experiments/generic/node-drain/experiment/node-drain.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func NodeDrain(clients clients.ClientSets) {
//DISPLAY THE APP INFORMATION
log.InfoWithValues("[Info]: The application information is as follows", logrus.Fields{
"Node Label": experimentsDetails.NodeLabel,
"Target Node": experimentsDetails.TargetNode,
"Target Nodes": experimentsDetails.TargetNodes,
"Chaos Duration": experimentsDetails.ChaosDuration,
})

Expand Down Expand Up @@ -93,7 +93,7 @@ func NodeDrain(clients clients.ClientSets) {

// Checking the status of target nodes
log.Info("[Status]: Getting the status of target nodes")
if err := status.CheckNodeStatus(experimentsDetails.TargetNode, experimentsDetails.Timeout, experimentsDetails.Delay, clients); err != nil {
if err := status.CheckNodeStatus(experimentsDetails.TargetNodes, experimentsDetails.Timeout, experimentsDetails.Delay, clients); err != nil {
log.Errorf("Target nodes are not in the ready state, err: %v", err)
failStep := "[pre-chaos]: Failed to verify the status of nodes, err: " + err.Error()
types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, "NUT: Not Ready", "Warning", &chaosDetails)
Expand Down Expand Up @@ -166,7 +166,7 @@ func NodeDrain(clients clients.ClientSets) {

// Checking the status of target nodes
log.Info("[Status]: Getting the status of target nodes")
if err := status.CheckNodeStatus(experimentsDetails.TargetNode, experimentsDetails.Timeout, experimentsDetails.Delay, clients); err != nil {
if err := status.CheckNodeStatus(experimentsDetails.TargetNodes, experimentsDetails.Timeout, experimentsDetails.Delay, clients); err != nil {
log.Warnf("Target nodes are not in the ready state, you may need to manually recover the node, err: %v", err)
types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, "NUT: Not Ready", "Warning", &chaosDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
Expand Down
2 changes: 1 addition & 1 deletion pkg/generic/node-drain/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func GetENV(experimentDetails *experimentTypes.ExperimentDetails) {
experimentDetails.InstanceID = types.Getenv("INSTANCE_ID", "")
experimentDetails.ChaosPodName = types.Getenv("POD_NAME", "")
experimentDetails.AuxiliaryAppInfo = types.Getenv("AUXILIARY_APPINFO", "")
experimentDetails.TargetNode = types.Getenv("TARGET_NODE", "")
experimentDetails.TargetNodes = types.Getenv("TARGET_NODES", "")
experimentDetails.Delay, _ = strconv.Atoi(types.Getenv("STATUS_CHECK_DELAY", "2"))
experimentDetails.Timeout, _ = strconv.Atoi(types.Getenv("STATUS_CHECK_TIMEOUT", "180"))
experimentDetails.TargetContainer = types.Getenv("TARGET_CONTAINER", "")
Expand Down
2 changes: 1 addition & 1 deletion pkg/generic/node-drain/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type ExperimentDetails struct {
InstanceID string
ChaosNamespace string
ChaosPodName string
TargetNode string
TargetNodes string
AuxiliaryAppInfo string
Timeout int
Delay int
Expand Down

0 comments on commit d449bc4

Please sign in to comment.