@@ -351,7 +351,7 @@ func updateManifestLabels(labels map[string]string, workflowID string, clusterID
351
351
return labels
352
352
}
353
353
354
- func generateFaultWeights (templates []v1alpha1.Template , labels map [string ]string , weights map [string ]int ) ([]* model.WeightagesInput , error ) {
354
+ func generateFaultWeights (templates []v1alpha1.Template , labels map [string ]string , weights map [string ]int ) ([]v1alpha1. Template , [] * model.WeightagesInput , error ) {
355
355
var newWeights []* model.WeightagesInput
356
356
357
357
for i , template := range templates {
@@ -367,18 +367,18 @@ func generateFaultWeights(templates []v1alpha1.Template, labels map[string]strin
367
367
var meta chaosTypes.ChaosEngine
368
368
err := yaml .Unmarshal ([]byte (data ), & meta )
369
369
if err != nil {
370
- return nil , errors .New ("failed to unmarshal chaosengine" )
370
+ return nil , nil , errors .New ("failed to unmarshal chaosengine" )
371
371
}
372
372
373
373
if strings .ToLower (meta .Kind ) == "chaosengine" {
374
374
var exprname string
375
375
if len (meta .Spec .Experiments ) > 0 {
376
376
exprname = meta .GenerateName
377
377
if len (exprname ) == 0 {
378
- return nil , errors .New ("empty chaos experiment name" )
378
+ return nil , nil , errors .New ("empty chaos experiment name" )
379
379
}
380
380
} else {
381
- return nil , errors .New ("no experiments specified in chaosengine - " + meta .Name )
381
+ return nil , nil , errors .New ("no experiments specified in chaosengine - " + meta .Name )
382
382
}
383
383
384
384
if val , ok := weights [exprname ]; ok {
@@ -388,7 +388,7 @@ func generateFaultWeights(templates []v1alpha1.Template, labels map[string]strin
388
388
} else if val , ok := templates [i ].Metadata .Labels ["weight" ]; ok {
389
389
intVal , err := strconv .Atoi (val )
390
390
if err != nil {
391
- return nil , errors .New ("failed to convert" )
391
+ return nil , nil , errors .New ("failed to convert" )
392
392
}
393
393
newWeights = append (newWeights , & model.WeightagesInput {
394
394
ExperimentName : exprname ,
@@ -409,7 +409,7 @@ func generateFaultWeights(templates []v1alpha1.Template, labels map[string]strin
409
409
}
410
410
}
411
411
412
- return newWeights , nil
412
+ return templates , newWeights , nil
413
413
}
414
414
415
415
func processWorkflowManifest (workflow * model.ChaosWorkFlowRequest , weights map [string ]int ) error {
@@ -424,7 +424,7 @@ func processWorkflowManifest(workflow *model.ChaosWorkFlowRequest, weights map[s
424
424
425
425
workflowManifest .Labels = updateManifestLabels (workflowManifest .Labels , * workflow .WorkflowID , workflow .ClusterID , false )
426
426
427
- newWeights , err = generateFaultWeights (workflowManifest .Spec .Templates , workflowManifest .Labels , weights )
427
+ workflowManifest . Spec . Templates , newWeights , err = generateFaultWeights (workflowManifest .Spec .Templates , workflowManifest .Labels , weights )
428
428
if err != nil {
429
429
return err
430
430
}
@@ -464,7 +464,7 @@ func processCronWorkflowManifest(workflow *model.ChaosWorkFlowRequest, weights m
464
464
cronWorkflowManifest .Spec .WorkflowMetadata .Labels = updateManifestLabels (cronWorkflowManifest .Spec .WorkflowMetadata .Labels , * workflow .WorkflowID , workflow .ClusterID , false )
465
465
}
466
466
467
- newWeights , err = generateFaultWeights (cronWorkflowManifest .Spec .WorkflowSpec .Templates , cronWorkflowManifest .Spec .WorkflowMetadata .Labels , weights )
467
+ cronWorkflowManifest . Spec . WorkflowSpec . Templates , newWeights , err = generateFaultWeights (cronWorkflowManifest .Spec .WorkflowSpec .Templates , cronWorkflowManifest .Spec .WorkflowMetadata .Labels , weights )
468
468
if err != nil {
469
469
return err
470
470
}
0 commit comments