Skip to content

Commit 0e36e55

Browse files
authored
feat(go-experiments): Updating failure condition for helper pod (#57) (#58)
Signed-off-by: shubhamchaudhary <shubham.chaudhary@mayadata.io>
1 parent 16f79dd commit 0e36e55

File tree

7 files changed

+27
-50
lines changed

7 files changed

+27
-50
lines changed

chaoslib/litmus/container_kill/container-kill.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,25 +82,12 @@ func PrepareContainerKill(experimentsDetails *experimentTypes.ExperimentDetails,
8282
return errors.Errorf("helper pod is not in running state, err: %v", err)
8383
}
8484

85-
// Recording the chaos start timestamp
86-
ChaosStartTimeStamp := time.Now().Unix()
87-
8885
// Wait till the completion of the helper pod
8986
// set an upper limit for the waiting time
9087
log.Info("[Wait]: waiting till the completion of the helper pod")
91-
err = status.WaitForCompletion(experimentsDetails.ChaosNamespace, "name=container-kill-"+experimentsDetails.RunID, clients, experimentsDetails.ChaosDuration+experimentsDetails.ChaosInterval+60)
92-
if err != nil {
93-
return err
94-
}
95-
96-
//ChaosCurrentTimeStamp contains the current timestamp
97-
ChaosCurrentTimeStamp := time.Now().Unix()
98-
//ChaosDiffTimeStamp contains the difference of current timestamp and start timestamp
99-
//It will helpful to track the total chaos duration
100-
chaosDiffTimeStamp := ChaosCurrentTimeStamp - ChaosStartTimeStamp
101-
102-
if int(chaosDiffTimeStamp) < experimentsDetails.ChaosDuration {
103-
return errors.Errorf("The helper pod failed, check the logs of helper pod for more details")
88+
podStatus, err := status.WaitForCompletion(experimentsDetails.ChaosNamespace, "name=container-kill-"+experimentsDetails.RunID, clients, experimentsDetails.ChaosDuration+experimentsDetails.ChaosInterval+60)
89+
if err != nil || podStatus == "Failed" {
90+
return errors.Errorf("helper pod failed due to, err: %v", err)
10491
}
10592

10693
//Deleting the helper pod for container-kill chaos

chaoslib/litmus/kubelet_service_kill/kubelet-service-kill.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ func PrepareKubeletKill(experimentsDetails *experimentTypes.ExperimentDetails, c
7272
// Wait till the completion of helper pod
7373
log.Infof("[Wait]: Waiting for %vs till the completion of the helper pod", strconv.Itoa(experimentsDetails.ChaosDuration+30))
7474

75-
err = status.WaitForCompletion(experimentsDetails.ChaosNamespace, "name=kubelet-service-kill-"+experimentsDetails.RunID, clients, experimentsDetails.ChaosDuration+30)
76-
if err != nil {
77-
return err
75+
podStatus, err := status.WaitForCompletion(experimentsDetails.ChaosNamespace, "name=kubelet-service-kill-"+experimentsDetails.RunID, clients, experimentsDetails.ChaosDuration+30)
76+
if err != nil || podStatus == "Failed" {
77+
return errors.Errorf("helper pod failed due to, err: %v", err)
7878
}
7979

8080
// Checking the status of application node

chaoslib/litmus/node_cpu_hog/node-cpu-hog.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ func PrepareNodeCPUHog(experimentsDetails *experimentTypes.ExperimentDetails, cl
7272
// Wait till the completion of helper pod
7373
log.Infof("[Wait]: Waiting for %vs till the completion of the helper pod", strconv.Itoa(experimentsDetails.ChaosDuration+30))
7474

75-
err = status.WaitForCompletion(experimentsDetails.ChaosNamespace, "name=node-cpu-hog-"+experimentsDetails.RunID, clients, experimentsDetails.ChaosDuration+30)
76-
if err != nil {
77-
return err
75+
podStatus, err := status.WaitForCompletion(experimentsDetails.ChaosNamespace, "name=node-cpu-hog-"+experimentsDetails.RunID, clients, experimentsDetails.ChaosDuration+30)
76+
if err != nil || podStatus == "Failed" {
77+
return errors.Errorf("helper pod failed due to, err: %v", err)
7878
}
7979

8080
// Checking the status of application node

chaoslib/litmus/node_memory_hog/node-memory-hog.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ func PrepareNodeMemoryHog(experimentsDetails *experimentTypes.ExperimentDetails,
6262
// Wait till the completion of helper pod
6363
log.Infof("[Wait]: Waiting for %vs till the completion of the helper pod", strconv.Itoa(experimentsDetails.ChaosDuration+30))
6464

65-
err = status.WaitForCompletion(experimentsDetails.ChaosNamespace, "name=node-memory-hog-"+experimentsDetails.RunID, clients, experimentsDetails.ChaosDuration+30)
66-
if err != nil {
67-
return err
65+
podStatus, err := status.WaitForCompletion(experimentsDetails.ChaosNamespace, "name=node-memory-hog-"+experimentsDetails.RunID, clients, experimentsDetails.ChaosDuration+30)
66+
if err != nil || podStatus == "Failed" {
67+
return errors.Errorf("helper pod failed due to, err: %v", err)
6868
}
6969

7070
// Checking the status of application node

chaoslib/litmus/pod_delete/pod-delete.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,11 @@ func PreparePodDelete(experimentsDetails *experimentTypes.ExperimentDetails, cli
5252
return errors.Errorf("helper pod is not in running state, err: %v", err)
5353
}
5454

55-
// Recording the chaos start timestamp
56-
ChaosStartTimeStamp := time.Now().Unix()
57-
5855
// Wait till the completion of helper pod
5956
log.Info("[Wait]: waiting till the completion of the helper pod")
60-
err := status.WaitForCompletion(experimentsDetails.ChaosNamespace, "name=pod-delete"+runID, clients, experimentsDetails.ChaosDuration+experimentsDetails.ChaosInterval+60)
61-
if err != nil {
62-
return err
63-
}
64-
65-
//ChaosCurrentTimeStamp contains the current timestamp
66-
ChaosCurrentTimeStamp := time.Now().Unix()
67-
//ChaosDiffTimeStamp contains the difference of current timestamp and start timestamp
68-
//It will helpful to track the total chaos duration
69-
chaosDiffTimeStamp := ChaosCurrentTimeStamp - ChaosStartTimeStamp
70-
71-
if int(chaosDiffTimeStamp) < experimentsDetails.ChaosDuration {
72-
return errors.Errorf("The helper pod failed, check the logs of helper pod for more details")
57+
podStatus, err := status.WaitForCompletion(experimentsDetails.ChaosNamespace, "name=pod-delete"+runID, clients, experimentsDetails.ChaosDuration+experimentsDetails.ChaosInterval+60)
58+
if err != nil || podStatus == "Failed" {
59+
return errors.Errorf("helper pod failed due to, err: %v", err)
7360
}
7461

7562
//Deleting the helper pod

chaoslib/pumba/network_chaos/network-chaos.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ func PreparePodNetworkChaos(experimentsDetails *experimentTypes.ExperimentDetail
7373
// Wait till the completion of helper pod
7474
log.Infof("[Wait]: Waiting for %vs till the completion of the helper pod", strconv.Itoa(experimentsDetails.ChaosDuration))
7575

76-
err = status.WaitForCompletion(experimentsDetails.ChaosNamespace, "name=pumba-netem-"+experimentsDetails.RunID, clients, experimentsDetails.ChaosDuration+30)
77-
if err != nil {
78-
return err
76+
podStatus, err := status.WaitForCompletion(experimentsDetails.ChaosNamespace, "name=pumba-netem-"+experimentsDetails.RunID, clients, experimentsDetails.ChaosDuration+30)
77+
if err != nil || podStatus == "Failed" {
78+
return errors.Errorf("helper pod failed due to, err: %v", err)
7979
}
8080

8181
//Deleting the helper pod

pkg/status/application.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ func CheckContainerStatus(appNs string, appLabel string, clients clients.ClientS
101101
}
102102

103103
// WaitForCompletion wait until the completion of pod
104-
func WaitForCompletion(appNs string, appLabel string, clients clients.ClientSets, duration int) error {
104+
func WaitForCompletion(appNs string, appLabel string, clients clients.ClientSets, duration int) (string, error) {
105+
var podStatus string
106+
105107
err := retry.
106108
Times(uint(duration)).
107109
Wait(1 * time.Second).
@@ -112,17 +114,18 @@ func WaitForCompletion(appNs string, appLabel string, clients clients.ClientSets
112114
}
113115
err = nil
114116
for _, pod := range podSpec.Items {
115-
log.Infof("helper pod status: %v", string(pod.Status.Phase))
116-
if string(pod.Status.Phase) != "Succeeded" && string(pod.Status.Phase) != "Failed" {
117+
podStatus = string(pod.Status.Phase)
118+
log.Infof("helper pod status: %v", podStatus)
119+
if podStatus != "Succeeded" && podStatus != "Failed" {
117120
return errors.Errorf("Helper pod is not yet completed yet")
118121
}
119122
log.InfoWithValues("The running status of Pods are as follows", logrus.Fields{
120-
"Pod": pod.Name, "Status": pod.Status.Phase})
123+
"Pod": pod.Name, "Status": podStatus})
121124
}
122125
return nil
123126
})
124127
if err != nil {
125-
return err
128+
return "", err
126129
}
127-
return nil
130+
return podStatus, nil
128131
}

0 commit comments

Comments
 (0)