Skip to content

Commit bfa3c9b

Browse files
committed
node-drain: run pre/post checks on all target nodes
1 parent 248daf9 commit bfa3c9b

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

Diff for: experiments/generic/node-drain/experiment/node-drain.go

+24-11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package experiment
22

33
import (
44
"os"
5+
"strings"
56

67
"github.com/litmuschaos/chaos-operator/pkg/apis/litmuschaos/v1alpha1"
78
litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/node-drain/lib"
@@ -68,6 +69,14 @@ func NodeDrain(clients clients.ClientSets) {
6869
"Chaos Duration": experimentsDetails.ChaosDuration,
6970
})
7071

72+
targetNodes := strings.Split(experimentsDetails.TargetNodes, ",")
73+
if len(targetNodes) == 0 {
74+
log.Errorf("No target nodes provided, expected the comma-separated names of one or more nodes")
75+
failStep := "[pre-chaos]: No target nodes provided, expected the comma-separated names of one or more nodes"
76+
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
77+
return
78+
}
79+
7180
// Calling AbortWatcher go routine, it will continuously watch for the abort signal and generate the required events and result
7281
go common.AbortWatcherWithoutExit(experimentsDetails.ExperimentName, clients, &resultDetails, &chaosDetails, &eventsDetails)
7382

@@ -93,13 +102,15 @@ func NodeDrain(clients clients.ClientSets) {
93102

94103
// Checking the status of target nodes
95104
log.Info("[Status]: Getting the status of target nodes")
96-
if err := status.CheckNodeStatus(experimentsDetails.TargetNodes, experimentsDetails.Timeout, experimentsDetails.Delay, clients); err != nil {
97-
log.Errorf("Target nodes are not in the ready state, err: %v", err)
98-
failStep := "[pre-chaos]: Failed to verify the status of nodes, err: " + err.Error()
99-
types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, "NUT: Not Ready", "Warning", &chaosDetails)
100-
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
101-
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
102-
return
105+
for _, targetNode := range targetNodes {
106+
if err := status.CheckNodeStatus(targetNode, experimentsDetails.Timeout, experimentsDetails.Delay, clients); err != nil {
107+
log.Errorf("Target nodes are not in the ready state, err: %v", err)
108+
failStep := "[pre-chaos]: Failed to verify the status of nodes, err: " + err.Error()
109+
types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, "NUT: Not Ready", "Warning", &chaosDetails)
110+
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
111+
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
112+
return
113+
}
103114
}
104115

105116
if experimentsDetails.EngineName != "" {
@@ -166,10 +177,12 @@ func NodeDrain(clients clients.ClientSets) {
166177

167178
// Checking the status of target nodes
168179
log.Info("[Status]: Getting the status of target nodes")
169-
if err := status.CheckNodeStatus(experimentsDetails.TargetNodes, experimentsDetails.Timeout, experimentsDetails.Delay, clients); err != nil {
170-
log.Warnf("Target nodes are not in the ready state, you may need to manually recover the node, err: %v", err)
171-
types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, "NUT: Not Ready", "Warning", &chaosDetails)
172-
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
180+
for _, targetNode := range targetNodes {
181+
if err := status.CheckNodeStatus(targetNode, experimentsDetails.Timeout, experimentsDetails.Delay, clients); err != nil {
182+
log.Warnf("Target nodes are not in the ready state, you may need to manually recover the node, err: %v", err)
183+
types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, "NUT: Not Ready", "Warning", &chaosDetails)
184+
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
185+
}
173186
}
174187

175188
if experimentsDetails.EngineName != "" {

0 commit comments

Comments
 (0)