@@ -21,6 +21,7 @@ import (
2121 "github.com/palantir/stacktrace"
2222 "github.com/sirupsen/logrus"
2323 "go.opentelemetry.io/otel"
24+ "go.opentelemetry.io/otel/codes"
2425 v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2526)
2627
@@ -46,14 +47,22 @@ func PreparePodDelete(ctx context.Context, experimentsDetails *experimentTypes.E
4647 switch strings .ToLower (experimentsDetails .Sequence ) {
4748 case "serial" :
4849 if err := injectChaosInSerialMode (ctx , experimentsDetails , clients , chaosDetails , eventsDetails , resultDetails ); err != nil {
50+ span .SetStatus (codes .Error , "could not run chaos in serial mode" )
51+ span .RecordError (err )
4952 return stacktrace .Propagate (err , "could not run chaos in serial mode" )
5053 }
5154 case "parallel" :
5255 if err := injectChaosInParallelMode (ctx , experimentsDetails , clients , chaosDetails , eventsDetails , resultDetails ); err != nil {
56+ span .SetStatus (codes .Error , "could not run chaos in parallel mode" )
57+ span .RecordError (err )
5358 return stacktrace .Propagate (err , "could not run chaos in parallel mode" )
5459 }
5560 default :
56- return cerrors.Error {ErrorCode : cerrors .ErrorTypeGeneric , Reason : fmt .Sprintf ("'%s' sequence is not supported" , experimentsDetails .Sequence )}
61+ errReason := fmt .Sprintf ("sequence '%s' is not supported" , experimentsDetails .Sequence )
62+ span .SetStatus (codes .Error , errReason )
63+ err := cerrors.Error {ErrorCode : cerrors .ErrorTypeGeneric , Reason : errReason }
64+ span .RecordError (err )
65+ return err
5766 }
5867
5968 //Waiting for the ramp time after chaos injection
@@ -72,6 +81,8 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment
7281 // run the probes during chaos
7382 if len (resultDetails .ProbeDetails ) != 0 {
7483 if err := probe .RunProbes (ctx , chaosDetails , clients , resultDetails , "DuringChaos" , eventsDetails ); err != nil {
84+ span .SetStatus (codes .Error , "could not run the probes during chaos" )
85+ span .RecordError (err )
7586 return err
7687 }
7788 }
@@ -85,18 +96,25 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment
8596 // Get the target pod details for the chaos execution
8697 // if the target pod is not defined it will derive the random target pod list using pod affected percentage
8798 if experimentsDetails .TargetPods == "" && chaosDetails .AppDetail == nil {
88- return cerrors.Error {ErrorCode : cerrors .ErrorTypeTargetSelection , Reason : "provide one of the appLabel or TARGET_PODS" }
99+ span .SetStatus (codes .Error , "provide one of the appLabel or TARGET_PODS" )
100+ err := cerrors.Error {ErrorCode : cerrors .ErrorTypeTargetSelection , Reason : "provide one of the appLabel or TARGET_PODS" }
101+ span .RecordError (err )
102+ return err
89103 }
90104
91105 targetPodList , err := common .GetTargetPods (experimentsDetails .NodeLabel , experimentsDetails .TargetPods , experimentsDetails .PodsAffectedPerc , clients , chaosDetails )
92106 if err != nil {
107+ span .SetStatus (codes .Error , "could not get target pods" )
108+ span .RecordError (err )
93109 return stacktrace .Propagate (err , "could not get target pods" )
94110 }
95111
96112 // deriving the parent name of the target resources
97113 for _ , pod := range targetPodList .Items {
98114 kind , parentName , err := workloads .GetPodOwnerTypeAndName (& pod , clients .DynamicClient )
99115 if err != nil {
116+ span .SetStatus (codes .Error , "could not get pod owner name and kind" )
117+ span .RecordError (err )
100118 return stacktrace .Propagate (err , "could not get pod owner name and kind" )
101119 }
102120 common .SetParentName (parentName , kind , pod .Namespace , chaosDetails )
@@ -123,12 +141,16 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment
123141 err = clients .KubeClient .CoreV1 ().Pods (pod .Namespace ).Delete (context .Background (), pod .Name , v1.DeleteOptions {})
124142 }
125143 if err != nil {
144+ span .SetStatus (codes .Error , "could not delete the target pod" )
145+ span .RecordError (err )
126146 return cerrors.Error {ErrorCode : cerrors .ErrorTypeChaosInject , Target : fmt .Sprintf ("{podName: %s, namespace: %s}" , pod .Name , pod .Namespace ), Reason : fmt .Sprintf ("failed to delete the target pod: %s" , err .Error ())}
127147 }
128148
129149 switch chaosDetails .Randomness {
130150 case true :
131151 if err := common .RandomInterval (experimentsDetails .ChaosInterval ); err != nil {
152+ span .SetStatus (codes .Error , "could not get random chaos interval" )
153+ span .RecordError (err )
132154 return stacktrace .Propagate (err , "could not get random chaos interval" )
133155 }
134156 default :
@@ -149,6 +171,8 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment
149171 Namespace : parent .Namespace ,
150172 }
151173 if err = status .CheckUnTerminatedPodStatusesByWorkloadName (target , experimentsDetails .Timeout , experimentsDetails .Delay , clients ); err != nil {
174+ span .SetStatus (codes .Error , "could not check pod statuses by workload names" )
175+ span .RecordError (err )
152176 return stacktrace .Propagate (err , "could not check pod statuses by workload names" )
153177 }
154178 }
@@ -184,17 +208,24 @@ func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experime
184208 // Get the target pod details for the chaos execution
185209 // if the target pod is not defined it will derive the random target pod list using pod affected percentage
186210 if experimentsDetails .TargetPods == "" && chaosDetails .AppDetail == nil {
187- return cerrors.Error {ErrorCode : cerrors .ErrorTypeTargetSelection , Reason : "please provide one of the appLabel or TARGET_PODS" }
211+ span .SetStatus (codes .Error , "please provide one of the appLabel or TARGET_PODS" )
212+ err := cerrors.Error {ErrorCode : cerrors .ErrorTypeTargetSelection , Reason : "please provide one of the appLabel or TARGET_PODS" }
213+ span .RecordError (err )
214+ return err
188215 }
189216 targetPodList , err := common .GetTargetPods (experimentsDetails .NodeLabel , experimentsDetails .TargetPods , experimentsDetails .PodsAffectedPerc , clients , chaosDetails )
190217 if err != nil {
218+ span .SetStatus (codes .Error , "could not get target pods" )
219+ span .RecordError (err )
191220 return stacktrace .Propagate (err , "could not get target pods" )
192221 }
193222
194223 // deriving the parent name of the target resources
195224 for _ , pod := range targetPodList .Items {
196225 kind , parentName , err := workloads .GetPodOwnerTypeAndName (& pod , clients .DynamicClient )
197226 if err != nil {
227+ span .SetStatus (codes .Error , "could not get pod owner name and kind" )
228+ span .RecordError (err )
198229 return stacktrace .Propagate (err , "could not get pod owner name and kind" )
199230 }
200231 common .SetParentName (parentName , kind , pod .Namespace , chaosDetails )
@@ -221,13 +252,16 @@ func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experime
221252 err = clients .KubeClient .CoreV1 ().Pods (pod .Namespace ).Delete (context .Background (), pod .Name , v1.DeleteOptions {})
222253 }
223254 if err != nil {
255+ span .SetStatus (codes .Error , "could not delete the target pod" )
256+ span .RecordError (err )
224257 return cerrors.Error {ErrorCode : cerrors .ErrorTypeChaosInject , Target : fmt .Sprintf ("{podName: %s, namespace: %s}" , pod .Name , pod .Namespace ), Reason : fmt .Sprintf ("failed to delete the target pod: %s" , err .Error ())}
225258 }
226259 }
227260
228261 switch chaosDetails .Randomness {
229262 case true :
230263 if err := common .RandomInterval (experimentsDetails .ChaosInterval ); err != nil {
264+ span .SetStatus (codes .Error , "could not get random chaos interval" )
231265 return stacktrace .Propagate (err , "could not get random chaos interval" )
232266 }
233267 default :
@@ -248,6 +282,8 @@ func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experime
248282 Namespace : parent .Namespace ,
249283 }
250284 if err = status .CheckUnTerminatedPodStatusesByWorkloadName (target , experimentsDetails .Timeout , experimentsDetails .Delay , clients ); err != nil {
285+ span .SetStatus (codes .Error , "could not check pod statuses by workload names" )
286+ span .RecordError (err )
251287 return stacktrace .Propagate (err , "could not check pod statuses by workload names" )
252288 }
253289 }
0 commit comments