diff --git a/contribute/developer-guide/templates/chaoslib_exec.tmpl b/contribute/developer-guide/templates/chaoslib_exec.tmpl index e4e3afcb2..a5a6d5704 100644 --- a/contribute/developer-guide/templates/chaoslib_exec.tmpl +++ b/contribute/developer-guide/templates/chaoslib_exec.tmpl @@ -1,6 +1,7 @@ package lib import ( + "context" "fmt" "os" "github.com/litmuschaos/litmus-go/pkg/cerrors" @@ -32,7 +33,7 @@ func injectChaos(experimentsDetails *experimentTypes.ExperimentDetails, podName return nil } -func experimentExecution(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func experimentExecution(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { // Get the target pod details for the chaos execution // if the target pod is not defined it will derive the random target pod list using pod affected percentage @@ -53,13 +54,13 @@ func experimentExecution(experimentsDetails *experimentTypes.ExperimentDetails, } log.Infof("Target pods list for chaos, %v", podNames) - return runChaos(experimentsDetails, targetPodList, clients, resultDetails, eventsDetails, chaosDetails) + return runChaos(ctx, experimentsDetails, targetPodList, clients, resultDetails, eventsDetails, chaosDetails) } -func runChaos(experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func runChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -120,7 +121,10 @@ func runChaos(experimentsDetails *experimentTypes.ExperimentDetails, targetPodLi } //PrepareChaos contains the preparation steps before chaos injection -func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func PrepareChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + // @TODO: setup tracing + // ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectChaos") + // defer span.End() //Waiting for the ramp time before chaos injection if experimentsDetails.RampTime != 0 { @@ -128,7 +132,7 @@ func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients common.WaitForDuration(experimentsDetails.RampTime) } //Starting the CPU stress experiment - if err := experimentExecution(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails);err != nil { + if err := experimentExecution(ctx, experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails);err != nil { return stacktrace.Propagate(err, "could not execute experiment") } //Waiting for the ramp time after chaos injection diff --git a/contribute/developer-guide/templates/chaoslib_helper.tmpl b/contribute/developer-guide/templates/chaoslib_helper.tmpl index 290e2b557..c60e4515b 100644 --- a/contribute/developer-guide/templates/chaoslib_helper.tmpl +++ b/contribute/developer-guide/templates/chaoslib_helper.tmpl @@ -1,6 +1,7 @@ package lib import ( + "context" "fmt" "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/palantir/stacktrace" @@ -19,7 +20,7 @@ import ( v1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -func experimentExecution(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func experimentExecution(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { // Get the target pod details for the chaos execution // if the target pod is not defined it will derive the random target pod list using pod affected percentage @@ -54,10 +55,10 @@ func experimentExecution(experimentsDetails *experimentTypes.ExperimentDetails, } } - return runChaos(experimentsDetails, targetPodList, clients, resultDetails, eventsDetails, chaosDetails) + return runChaos(ctx, experimentsDetails, targetPodList, clients, resultDetails, eventsDetails, chaosDetails) } -func runChaos(experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func runChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { if experimentsDetails.EngineName != "" { msg := "Injecting " + experimentsDetails.ExperimentName + " chaos on target pod" types.SetEngineEventAttributes(eventsDetails, types.ChaosInject, msg, "Normal", chaosDetails) @@ -66,7 +67,7 @@ func runChaos(experimentsDetails *experimentTypes.ExperimentDetails, targetPodLi // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -89,7 +90,7 @@ func runChaos(experimentsDetails *experimentTypes.ExperimentDetails, targetPodLi "Target Container": experimentsDetails.TargetContainer, }) - if err := createHelperPod(experimentsDetails, clients, chaosDetails, pod.Name, pod.Spec.NodeName, runID); err != nil { + if err := createHelperPod(ctx, experimentsDetails, clients, chaosDetails, pod.Name, pod.Spec.NodeName, runID); err != nil { return stacktrace.Propagate(err, "could not create helper pod") } @@ -124,7 +125,10 @@ func runChaos(experimentsDetails *experimentTypes.ExperimentDetails, targetPodLi } //PrepareChaos contains the preparation steps before chaos injection -func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func PrepareChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + // @TODO: setup tracing + // ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "name-your-chaos-fault") + // defer span.End() //Waiting for the ramp time before chaos injection if experimentsDetails.RampTime != 0 { @@ -132,7 +136,7 @@ func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients common.WaitForDuration(experimentsDetails.RampTime) } //Starting the CPU stress experiment - if err := experimentExecution(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails);err != nil { + if err := experimentExecution(ctx, experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails);err != nil { return stacktrace.Propagate(err, "could not execute chaos") } //Waiting for the ramp time after chaos injection @@ -144,7 +148,10 @@ func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients } // createHelperPod derive the attributes for helper pod and create the helper pod -func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, targets, nodeName, runID string) error { +func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, targets, nodeName, runID string) error { + // @TODO: setup tracing + // ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateHelperPod") + // defer span.End() helperPod := &corev1.Pod{ ObjectMeta: v1.ObjectMeta{ diff --git a/contribute/developer-guide/templates/chaoslib_non-k8s.tmpl b/contribute/developer-guide/templates/chaoslib_non-k8s.tmpl index 3b2954aaa..7f11d65d5 100644 --- a/contribute/developer-guide/templates/chaoslib_non-k8s.tmpl +++ b/contribute/developer-guide/templates/chaoslib_non-k8s.tmpl @@ -1,6 +1,7 @@ package lib import ( + "context" "os" "os/signal" "strings" @@ -22,7 +23,10 @@ var ( ) //PrepareChaos contains the preparation and injection steps for the experiment -func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func PrepareChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + // @TODO: setup tracing + // ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectChaos") + // defer span.End() // inject channel is used to transmit signal notifications. inject = make(chan os.Signal, 1) @@ -53,11 +57,11 @@ func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err = injectChaosInSerialMode(experimentsDetails, targetIDList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = injectChaosInSerialMode(ctx, experimentsDetails, targetIDList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in serial mode") } case "parallel": - if err = injectChaosInParallelMode(experimentsDetails, targetIDList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = injectChaosInParallelMode(ctx, experimentsDetails, targetIDList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: @@ -73,7 +77,7 @@ func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients } //injectChaosInSerialMode will inject the chaos on the target one after other -func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetails, targetIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInSerialMode(ctx context.Contxt, experimentsDetails *experimentTypes.ExperimentDetails, targetIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { select { case <-inject: @@ -111,7 +115,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai // The OnChaos probes execution will start in the first iteration and keep running for the entire chaos duration if len(resultDetails.ProbeDetails) != 0 && i == 0 { - if err = probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err = probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -136,7 +140,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai } // injectChaosInParallelMode will inject the chaos on the target all at once -func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDetails, targetIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { select { case <-inject: @@ -177,7 +181,7 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } diff --git a/contribute/developer-guide/templates/experiment_aws.tmpl b/contribute/developer-guide/templates/experiment_aws.tmpl index b1920a590..7104ac807 100644 --- a/contribute/developer-guide/templates/experiment_aws.tmpl +++ b/contribute/developer-guide/templates/experiment_aws.tmpl @@ -1,6 +1,7 @@ package experiment import ( + "context" "os" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/{{ .Name }}/lib" @@ -19,7 +20,7 @@ import ( ) // Experiment contains steps to inject chaos -func Experiment(clients clients.ClientSets){ +func Experiment(ctx context.Context, clients clients.ClientSets){ experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -90,7 +91,7 @@ func Experiment(clients clients.ClientSets){ // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails);err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails);err != nil { log.Errorf("Probe Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -111,7 +112,7 @@ func Experiment(clients clients.ClientSets){ // @TODO: user INVOKE-CHAOSLIB chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -142,7 +143,7 @@ func Experiment(clients clients.ClientSets){ // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails);err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails);err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/contribute/developer-guide/templates/experiment_azure.tmpl b/contribute/developer-guide/templates/experiment_azure.tmpl index 7d8a76a18..9cf17e378 100644 --- a/contribute/developer-guide/templates/experiment_azure.tmpl +++ b/contribute/developer-guide/templates/experiment_azure.tmpl @@ -1,6 +1,7 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" @@ -20,7 +21,7 @@ import ( ) // Experiment contains steps to inject chaos -func Experiment(clients clients.ClientSets){ +func Experiment(ctx context.Context, clients clients.ClientSets){ experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -99,7 +100,7 @@ func Experiment(clients clients.ClientSets){ // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails);err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails);err != nil { log.Errorf("Probe Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -120,7 +121,7 @@ func Experiment(clients clients.ClientSets){ // @TODO: user INVOKE-CHAOSLIB chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -148,7 +149,7 @@ func Experiment(clients clients.ClientSets){ // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails);err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails);err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/contribute/developer-guide/templates/experiment_gcp.tmpl b/contribute/developer-guide/templates/experiment_gcp.tmpl index c22151420..20bbe81b4 100644 --- a/contribute/developer-guide/templates/experiment_gcp.tmpl +++ b/contribute/developer-guide/templates/experiment_gcp.tmpl @@ -1,6 +1,7 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" @@ -98,7 +99,7 @@ func Experiment(clients clients.ClientSets){ // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails);err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails);err != nil { log.Errorf("Probe Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -119,7 +120,7 @@ func Experiment(clients clients.ClientSets){ // @TODO: user INVOKE-CHAOSLIB chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) failStep := "[chaos]: Failed inside the chaoslib, err: " + err.Error() result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) @@ -149,7 +150,7 @@ func Experiment(clients clients.ClientSets){ // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails);err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails);err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/contribute/developer-guide/templates/experiment_k8s.tmpl b/contribute/developer-guide/templates/experiment_k8s.tmpl index bd33e4a78..85f29a6ef 100644 --- a/contribute/developer-guide/templates/experiment_k8s.tmpl +++ b/contribute/developer-guide/templates/experiment_k8s.tmpl @@ -1,6 +1,7 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" @@ -19,7 +20,7 @@ import ( ) // Experiment contains steps to inject chaos -func Experiment(clients clients.ClientSets){ +func Experiment(ctx context.Context, clients clients.ClientSets){ experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -104,7 +105,7 @@ func Experiment(clients clients.ClientSets){ // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails);err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails);err != nil { log.Errorf("Probe Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -125,7 +126,7 @@ func Experiment(clients clients.ClientSets){ // @TODO: user INVOKE-CHAOSLIB chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -168,7 +169,7 @@ func Experiment(clients clients.ClientSets){ // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails);err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails);err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/contribute/developer-guide/templates/experiment_vmware.tmpl b/contribute/developer-guide/templates/experiment_vmware.tmpl index 38f64a162..aad8e769a 100644 --- a/contribute/developer-guide/templates/experiment_vmware.tmpl +++ b/contribute/developer-guide/templates/experiment_vmware.tmpl @@ -1,8 +1,10 @@ package experiment import ( + "context" "os" + "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/{{ .Name }}/lib" clients "github.com/litmuschaos/litmus-go/pkg/clients" @@ -19,7 +21,7 @@ import ( ) // Experiment contains steps to inject chaos -func Experiment(clients clients.ClientSets){ +func Experiment(ctx context.Context, clients clients.ClientSets){ experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -97,7 +99,7 @@ func Experiment(clients clients.ClientSets){ // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails);err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails);err != nil { log.Errorf("Probe Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -118,7 +120,7 @@ func Experiment(clients clients.ClientSets){ // @TODO: user INVOKE-CHAOSLIB chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) failStep := "[chaos]: Failed inside the chaoslib, err: " + err.Error() result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) @@ -148,7 +150,7 @@ func Experiment(clients clients.ClientSets){ // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails);err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails);err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails)