@@ -16,7 +16,6 @@ import (
1616 experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/disk-fill/types"
1717 "github.com/litmuschaos/litmus-go/pkg/log"
1818 "github.com/litmuschaos/litmus-go/pkg/probe"
19- "github.com/litmuschaos/litmus-go/pkg/status"
2019 "github.com/litmuschaos/litmus-go/pkg/types"
2120 "github.com/litmuschaos/litmus-go/pkg/utils/common"
2221 "github.com/litmuschaos/litmus-go/pkg/utils/exec"
@@ -64,7 +63,7 @@ func PrepareDiskFill(ctx context.Context, experimentsDetails *experimentTypes.Ex
6463 if experimentsDetails .ChaosServiceAccount == "" {
6564 experimentsDetails .ChaosServiceAccount , err = common .GetServiceAccount (experimentsDetails .ChaosNamespace , experimentsDetails .ChaosPodName , clients )
6665 if err != nil {
67- return stacktrace .Propagate (err , "could not experiment service account" )
66+ return stacktrace .Propagate (err , "could not get experiment service account" )
6867 }
6968 }
7069
@@ -122,26 +121,8 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment
122121
123122 appLabel := fmt .Sprintf ("app=%s-helper-%s" , experimentsDetails .ExperimentName , runID )
124123
125- //checking the status of the helper pods, wait till the pod comes to running state else fail the experiment
126- log .Info ("[Status]: Checking the status of the helper pods" )
127- if err := status .CheckHelperStatus (experimentsDetails .ChaosNamespace , appLabel , experimentsDetails .Timeout , experimentsDetails .Delay , clients ); err != nil {
128- common .DeleteAllHelperPodBasedOnJobCleanupPolicy (appLabel , chaosDetails , clients )
129- return stacktrace .Propagate (err , "could not check helper status" )
130- }
131-
132- // Wait till the completion of the helper pod
133- // set an upper limit for the waiting time
134- log .Info ("[Wait]: waiting till the completion of the helper pod" )
135- podStatus , err := status .WaitForCompletion (experimentsDetails .ChaosNamespace , appLabel , clients , experimentsDetails .ChaosDuration + experimentsDetails .Timeout , common .GetContainerNames (chaosDetails )... )
136- if err != nil || podStatus == "Failed" {
137- common .DeleteAllHelperPodBasedOnJobCleanupPolicy (appLabel , chaosDetails , clients )
138- return common .HelperFailedError (err , appLabel , chaosDetails .ChaosNamespace , true )
139- }
140-
141- //Deleting all the helper pod for disk-fill chaos
142- log .Info ("[Cleanup]: Deleting the helper pod" )
143- if err = common .DeleteAllPod (appLabel , experimentsDetails .ChaosNamespace , chaosDetails .Timeout , chaosDetails .Delay , clients ); err != nil {
144- return stacktrace .Propagate (err , "could not delete helper pod(s)" )
124+ if err := common .ManagerHelperLifecycle (appLabel , chaosDetails , clients , true ); err != nil {
125+ return err
145126 }
146127 }
147128
@@ -153,7 +134,7 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment
153134func injectChaosInParallelMode (ctx context.Context , experimentsDetails * experimentTypes.ExperimentDetails , targetPodList apiv1.PodList , clients clients.ClientSets , chaosDetails * types.ChaosDetails , execCommandDetails exec.PodDetails , resultDetails * types.ResultDetails , eventsDetails * types.EventDetails ) error {
154135 ctx , span := otel .Tracer (telemetry .TracerName ).Start (ctx , "InjectDiskFillFaultInParallelMode" )
155136 defer span .End ()
156- var err error
137+
157138 // run the probes during chaos
158139 if len (resultDetails .ProbeDetails ) != 0 {
159140 if err := probe .RunProbes (ctx , chaosDetails , clients , resultDetails , "DuringChaos" , eventsDetails ); err != nil {
@@ -177,26 +158,8 @@ func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experime
177158
178159 appLabel := fmt .Sprintf ("app=%s-helper-%s" , experimentsDetails .ExperimentName , runID )
179160
180- //checking the status of the helper pods, wait till the pod comes to running state else fail the experiment
181- log .Info ("[Status]: Checking the status of the helper pods" )
182- if err := status .CheckHelperStatus (experimentsDetails .ChaosNamespace , appLabel , experimentsDetails .Timeout , experimentsDetails .Delay , clients ); err != nil {
183- common .DeleteAllHelperPodBasedOnJobCleanupPolicy (appLabel , chaosDetails , clients )
184- return stacktrace .Propagate (err , "could not check helper status" )
185- }
186-
187- // Wait till the completion of the helper pod
188- // set an upper limit for the waiting time
189- log .Info ("[Wait]: waiting till the completion of the helper pod" )
190- podStatus , err := status .WaitForCompletion (experimentsDetails .ChaosNamespace , appLabel , clients , experimentsDetails .ChaosDuration + experimentsDetails .Timeout , common .GetContainerNames (chaosDetails )... )
191- if err != nil || podStatus == "Failed" {
192- common .DeleteAllHelperPodBasedOnJobCleanupPolicy (appLabel , chaosDetails , clients )
193- return common .HelperFailedError (err , appLabel , chaosDetails .ChaosNamespace , true )
194- }
195-
196- //Deleting all the helper pod for disk-fill chaos
197- log .Info ("[Cleanup]: Deleting all the helper pod" )
198- if err = common .DeleteAllPod (appLabel , experimentsDetails .ChaosNamespace , chaosDetails .Timeout , chaosDetails .Delay , clients ); err != nil {
199- return stacktrace .Propagate (err , "could not delete helper pod(s)" )
161+ if err := common .ManagerHelperLifecycle (appLabel , chaosDetails , clients , true ); err != nil {
162+ return err
200163 }
201164
202165 return nil
@@ -268,10 +231,10 @@ func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.Ex
268231 helperPod .Spec .Volumes = append (helperPod .Spec .Volumes , common .GetSidecarVolumes (chaosDetails )... )
269232 }
270233
271- _ , err := clients .KubeClient .CoreV1 ().Pods (experimentsDetails .ChaosNamespace ).Create (context .Background (), helperPod , v1.CreateOptions {})
272- if err != nil {
234+ if err := clients .CreatePod (experimentsDetails .ChaosNamespace , helperPod ); err != nil {
273235 return cerrors.Error {ErrorCode : cerrors .ErrorTypeGeneric , Reason : fmt .Sprintf ("unable to create helper pod: %s" , err .Error ())}
274236 }
237+
275238 return nil
276239}
277240
0 commit comments