Skip to content

Commit ec8b559

Browse files
[Cherry Pick for 1.12.2] (#277)
* feat(annotation): logging the annotated parent details (#272) Signed-off-by: shubhamchaudhary <[email protected]> * feat(labels): updating the helper labels (#276) Signed-off-by: shubhamchaudhary <[email protected]> * Enhanc(node-memory-hog): Add support for different units for node memory hog exp (#273) * Enhanc(node-memory-hog): Add support for different units for node memory hog exp Signed-off-by: udit <[email protected]> Co-authored-by: Shubham Chaudhary <[email protected]>
1 parent 6fd88eb commit ec8b559

19 files changed

Lines changed: 444 additions & 257 deletions

File tree

build/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ RUN rm -rf /var/lib/apt/lists/*
1010
# Install generally useful things
1111
RUN apk --update add \
1212
sudo \
13+
htop\
1314
bash\
1415
make\
1516
git \

chaoslib/litmus/container-kill/lib/container-kill.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func PrepareContainerKill(experimentsDetails *experimentTypes.ExperimentDetails,
9191
// InjectChaosInSerialMode kill the container of all target application serially (one by one)
9292
func InjectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails) error {
9393

94+
labelSuffix := common.GetRunID()
9495
// creating the helper pod to perform container kill chaos
9596
for _, pod := range targetPodList.Items {
9697

@@ -100,30 +101,32 @@ func InjectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai
100101
"ContainerName": experimentsDetails.TargetContainer,
101102
})
102103
runID := common.GetRunID()
103-
if err := CreateHelperPod(experimentsDetails, clients, pod.Name, pod.Spec.NodeName, runID); err != nil {
104+
if err := CreateHelperPod(experimentsDetails, clients, pod.Name, pod.Spec.NodeName, runID, labelSuffix); err != nil {
104105
return errors.Errorf("Unable to create the helper pod, err: %v", err)
105106
}
106107

108+
appLabel := "name=" + experimentsDetails.ExperimentName + "-" + runID
109+
107110
//checking the status of the helper pods, wait till the pod comes to running state else fail the experiment
108111
log.Info("[Status]: Checking the status of the helper pods")
109-
err := status.CheckApplicationStatus(experimentsDetails.ChaosNamespace, "app="+experimentsDetails.ExperimentName+"-helper", experimentsDetails.Timeout, experimentsDetails.Delay, clients)
112+
err := status.CheckApplicationStatus(experimentsDetails.ChaosNamespace, appLabel, experimentsDetails.Timeout, experimentsDetails.Delay, clients)
110113
if err != nil {
111-
common.DeleteHelperPodBasedOnJobCleanupPolicy(experimentsDetails.ExperimentName+"-"+runID, "app="+experimentsDetails.ExperimentName+"-helper", chaosDetails, clients)
114+
common.DeleteHelperPodBasedOnJobCleanupPolicy(experimentsDetails.ExperimentName+"-"+runID, appLabel, chaosDetails, clients)
112115
return errors.Errorf("helper pods are not in running state, err: %v", err)
113116
}
114117

115118
// Wait till the completion of the helper pod
116119
// set an upper limit for the waiting time
117120
log.Info("[Wait]: waiting till the completion of the helper pod")
118-
podStatus, err := status.WaitForCompletion(experimentsDetails.ChaosNamespace, "app="+experimentsDetails.ExperimentName+"-helper", clients, experimentsDetails.ChaosDuration+experimentsDetails.ChaosInterval+60, experimentsDetails.ExperimentName)
121+
podStatus, err := status.WaitForCompletion(experimentsDetails.ChaosNamespace, appLabel, clients, experimentsDetails.ChaosDuration+experimentsDetails.ChaosInterval+60, experimentsDetails.ExperimentName)
119122
if err != nil || podStatus == "Failed" {
120-
common.DeleteHelperPodBasedOnJobCleanupPolicy(experimentsDetails.ExperimentName+"-"+runID, "app="+experimentsDetails.ExperimentName+"-helper", chaosDetails, clients)
123+
common.DeleteHelperPodBasedOnJobCleanupPolicy(experimentsDetails.ExperimentName+"-"+runID, appLabel, chaosDetails, clients)
121124
return errors.Errorf("helper pod failed, err: %v", err)
122125
}
123126

124127
//Deleting all the helper pod for container-kill chaos
125128
log.Info("[Cleanup]: Deleting all the helper pods")
126-
err = common.DeletePod(experimentsDetails.ExperimentName+"-"+runID, "app="+experimentsDetails.ExperimentName+"-helper", experimentsDetails.ChaosNamespace, chaosDetails.Timeout, chaosDetails.Delay, clients)
129+
err = common.DeletePod(experimentsDetails.ExperimentName+"-"+runID, appLabel, experimentsDetails.ChaosNamespace, chaosDetails.Timeout, chaosDetails.Delay, clients)
127130
if err != nil {
128131
return errors.Errorf("Unable to delete the helper pod, err: %v", err)
129132
}
@@ -135,6 +138,7 @@ func InjectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai
135138
// InjectChaosInParallelMode kill the container of all target application in parallel mode (all at once)
136139
func InjectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails) error {
137140

141+
labelSuffix := common.GetRunID()
138142
// creating the helper pod to perform container kill chaos
139143
for _, pod := range targetPodList.Items {
140144

@@ -144,31 +148,33 @@ func InjectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet
144148
"ContainerName": experimentsDetails.TargetContainer,
145149
})
146150
runID := common.GetRunID()
147-
if err := CreateHelperPod(experimentsDetails, clients, pod.Name, pod.Spec.NodeName, runID); err != nil {
151+
if err := CreateHelperPod(experimentsDetails, clients, pod.Name, pod.Spec.NodeName, runID, labelSuffix); err != nil {
148152
return errors.Errorf("Unable to create the helper pod, err: %v", err)
149153
}
150154
}
151155

156+
appLabel := "app=" + experimentsDetails.ExperimentName + "-helper-" + labelSuffix
157+
152158
//checking the status of the helper pods, wait till the pod comes to running state else fail the experiment
153159
log.Info("[Status]: Checking the status of the helper pods")
154-
err := status.CheckApplicationStatus(experimentsDetails.ChaosNamespace, "app="+experimentsDetails.ExperimentName+"-helper", experimentsDetails.Timeout, experimentsDetails.Delay, clients)
160+
err := status.CheckApplicationStatus(experimentsDetails.ChaosNamespace, appLabel, experimentsDetails.Timeout, experimentsDetails.Delay, clients)
155161
if err != nil {
156-
common.DeleteAllHelperPodBasedOnJobCleanupPolicy("app="+experimentsDetails.ExperimentName+"-helper", chaosDetails, clients)
162+
common.DeleteAllHelperPodBasedOnJobCleanupPolicy(appLabel, chaosDetails, clients)
157163
return errors.Errorf("helper pods are not in running state, err: %v", err)
158164
}
159165

160166
// Wait till the completion of the helper pod
161167
// set an upper limit for the waiting time
162168
log.Info("[Wait]: waiting till the completion of the helper pod")
163-
podStatus, err := status.WaitForCompletion(experimentsDetails.ChaosNamespace, "app="+experimentsDetails.ExperimentName+"-helper", clients, experimentsDetails.ChaosDuration+experimentsDetails.ChaosInterval+60, experimentsDetails.ExperimentName)
169+
podStatus, err := status.WaitForCompletion(experimentsDetails.ChaosNamespace, appLabel, clients, experimentsDetails.ChaosDuration+experimentsDetails.ChaosInterval+60, experimentsDetails.ExperimentName)
164170
if err != nil || podStatus == "Failed" {
165-
common.DeleteAllHelperPodBasedOnJobCleanupPolicy("app="+experimentsDetails.ExperimentName+"-helper", chaosDetails, clients)
171+
common.DeleteAllHelperPodBasedOnJobCleanupPolicy(appLabel, chaosDetails, clients)
166172
return errors.Errorf("helper pod failed, err: %v", err)
167173
}
168174

169175
//Deleting all the helper pod for container-kill chaos
170176
log.Info("[Cleanup]: Deleting all the helper pods")
171-
err = common.DeleteAllPod("app="+experimentsDetails.ExperimentName+"-helper", experimentsDetails.ChaosNamespace, chaosDetails.Timeout, chaosDetails.Delay, clients)
177+
err = common.DeleteAllPod(appLabel, experimentsDetails.ChaosNamespace, chaosDetails.Timeout, chaosDetails.Delay, clients)
172178
if err != nil {
173179
return errors.Errorf("Unable to delete the helper pod, err: %v", err)
174180
}
@@ -209,7 +215,7 @@ func GetTargetContainer(experimentsDetails *experimentTypes.ExperimentDetails, a
209215
}
210216

211217
// CreateHelperPod derive the attributes for helper pod and create the helper pod
212-
func CreateHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, podName, nodeName, runID string) error {
218+
func CreateHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, podName, nodeName, runID, labelSuffix string) error {
213219

214220
privilegedEnable := false
215221
if experimentsDetails.ContainerRuntime == "crio" {
@@ -221,7 +227,7 @@ func CreateHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie
221227
Name: experimentsDetails.ExperimentName + "-" + runID,
222228
Namespace: experimentsDetails.ChaosNamespace,
223229
Labels: map[string]string{
224-
"app": experimentsDetails.ExperimentName + "-helper",
230+
"app": experimentsDetails.ExperimentName + "-helper-" + labelSuffix,
225231
"name": experimentsDetails.ExperimentName + "-" + runID,
226232
"chaosUID": string(experimentsDetails.ChaosUID),
227233
"app.kubernetes.io/part-of": "litmus",

0 commit comments

Comments
 (0)