Skip to content

Commit 8eec8e6

Browse files
fix: set fault weights to manifest
Signed-off-by: SohamRatnaparkhi <[email protected]>
1 parent 062ef89 commit 8eec8e6

File tree

1 file changed

+8
-8
lines changed
  • litmus-portal/graphql-server/pkg/chaos-workflow

1 file changed

+8
-8
lines changed

litmus-portal/graphql-server/pkg/chaos-workflow/service.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ func updateManifestLabels(labels map[string]string, workflowID string, clusterID
351351
return labels
352352
}
353353

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) {
355355
var newWeights []*model.WeightagesInput
356356

357357
for i, template := range templates {
@@ -367,18 +367,18 @@ func generateFaultWeights(templates []v1alpha1.Template, labels map[string]strin
367367
var meta chaosTypes.ChaosEngine
368368
err := yaml.Unmarshal([]byte(data), &meta)
369369
if err != nil {
370-
return nil, errors.New("failed to unmarshal chaosengine")
370+
return nil, nil, errors.New("failed to unmarshal chaosengine")
371371
}
372372

373373
if strings.ToLower(meta.Kind) == "chaosengine" {
374374
var exprname string
375375
if len(meta.Spec.Experiments) > 0 {
376376
exprname = meta.GenerateName
377377
if len(exprname) == 0 {
378-
return nil, errors.New("empty chaos experiment name")
378+
return nil, nil, errors.New("empty chaos experiment name")
379379
}
380380
} 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)
382382
}
383383

384384
if val, ok := weights[exprname]; ok {
@@ -388,7 +388,7 @@ func generateFaultWeights(templates []v1alpha1.Template, labels map[string]strin
388388
} else if val, ok := templates[i].Metadata.Labels["weight"]; ok {
389389
intVal, err := strconv.Atoi(val)
390390
if err != nil {
391-
return nil, errors.New("failed to convert")
391+
return nil, nil, errors.New("failed to convert")
392392
}
393393
newWeights = append(newWeights, &model.WeightagesInput{
394394
ExperimentName: exprname,
@@ -409,7 +409,7 @@ func generateFaultWeights(templates []v1alpha1.Template, labels map[string]strin
409409
}
410410
}
411411

412-
return newWeights, nil
412+
return templates, newWeights, nil
413413
}
414414

415415
func processWorkflowManifest(workflow *model.ChaosWorkFlowRequest, weights map[string]int) error {
@@ -424,7 +424,7 @@ func processWorkflowManifest(workflow *model.ChaosWorkFlowRequest, weights map[s
424424

425425
workflowManifest.Labels = updateManifestLabels(workflowManifest.Labels, *workflow.WorkflowID, workflow.ClusterID, false)
426426

427-
newWeights, err = generateFaultWeights(workflowManifest.Spec.Templates, workflowManifest.Labels, weights)
427+
workflowManifest.Spec.Templates, newWeights, err = generateFaultWeights(workflowManifest.Spec.Templates, workflowManifest.Labels, weights)
428428
if err != nil {
429429
return err
430430
}
@@ -464,7 +464,7 @@ func processCronWorkflowManifest(workflow *model.ChaosWorkFlowRequest, weights m
464464
cronWorkflowManifest.Spec.WorkflowMetadata.Labels = updateManifestLabels(cronWorkflowManifest.Spec.WorkflowMetadata.Labels, *workflow.WorkflowID, workflow.ClusterID, false)
465465
}
466466

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)
468468
if err != nil {
469469
return err
470470
}

0 commit comments

Comments
 (0)