From 8cf7902563cc48ea515ab5adac0bf94cc5d11ae7 Mon Sep 17 00:00:00 2001 From: Saranya Jena Date: Tue, 7 Nov 2023 10:45:48 +0530 Subject: [PATCH 1/5] Enable cron (#4239) * Added API for enable and disable cron Signed-off-by: Saranya-jena * Added backend implementation to toggle enable/disable cron experiment Signed-off-by: Saranya-jena * fixed imports Signed-off-by: Saranya-jena * removed code for disable cron from stop experiment Signed-off-by: Saranya-jena --------- Signed-off-by: Saranya-jena --- .../shared/chaos_experiment.graphqls | 8 + .../graph/chaos_experiment.resolvers.go | 23 +++ .../server/graph/generated/generated.go | 184 ++++++++++++++---- .../pkg/chaos_experiment/handler/handler.go | 102 +++++++++- .../pkg/chaos_experiment/ops/service.go | 82 +++++++- .../components/InputSlider/InputSlider.tsx | 2 +- chaoscenter/web/src/strings/strings.en.yaml | 4 +- .../AddProbeModalWizard.tsx | 1 - .../views/StudioSchedule/StudioSchedule.tsx | 2 +- 9 files changed, 360 insertions(+), 48 deletions(-) diff --git a/chaoscenter/graphql/definitions/shared/chaos_experiment.graphqls b/chaoscenter/graphql/definitions/shared/chaos_experiment.graphqls index 246d190ff78..fb78559ffcb 100644 --- a/chaoscenter/graphql/definitions/shared/chaos_experiment.graphqls +++ b/chaoscenter/graphql/definitions/shared/chaos_experiment.graphqls @@ -768,4 +768,12 @@ extend type Mutation { experimentRunID: String projectID: ID! ): Boolean! + + """ + Enable/Disable cron experiment state + """ + updateCronExperimentState(experimentID: String! + disable: Boolean! + projectID: ID! + ): Boolean! @authorized } diff --git a/chaoscenter/graphql/server/graph/chaos_experiment.resolvers.go b/chaoscenter/graphql/server/graph/chaos_experiment.resolvers.go index a764d51bb26..4c84feadec0 100644 --- a/chaoscenter/graphql/server/graph/chaos_experiment.resolvers.go +++ b/chaoscenter/graphql/server/graph/chaos_experiment.resolvers.go @@ -135,6 +135,29 @@ func (r *mutationResolver) DeleteChaosExperiment(ctx context.Context, experiment return uiResponse, err } +func (r *mutationResolver) UpdateCronExperimentState(ctx context.Context, experimentID string, disable bool, projectID string) (bool, error) { + logFields := logrus.Fields{ + "projectId": projectID, + "chaosExperimentId": experimentID, + } + + logrus.WithFields(logFields).Info("request received to update cron chaos experiment") + + err := authorization.ValidateRole(ctx, projectID, + authorization.MutationRbacRules[authorization.UpdateChaosWorkflow], + model.InvitationAccepted.String()) + if err != nil { + return false, err + } + + uiResponse, err := r.chaosExperimentHandler.UpdateCronExperimentState(ctx, experimentID, disable, projectID, data_store.Store) + if err != nil { + logrus.WithFields(logFields).Error(err) + return false, err + } + return uiResponse, err +} + func (r *queryResolver) GetExperiment(ctx context.Context, projectID string, experimentID string) (*model.GetExperimentResponse, error) { logFields := logrus.Fields{ "projectId": projectID, diff --git a/chaoscenter/graphql/server/graph/generated/generated.go b/chaoscenter/graphql/server/graph/generated/generated.go index 28850be057c..537fb7bcc81 100644 --- a/chaoscenter/graphql/server/graph/generated/generated.go +++ b/chaoscenter/graphql/server/graph/generated/generated.go @@ -476,39 +476,40 @@ type ComplexityRoot struct { } Mutation struct { - AddChaosHub func(childComplexity int, projectID string, request model.CreateChaosHubRequest) int - AddProbe func(childComplexity int, request model.ProbeRequest, projectID string) int - AddRemoteChaosHub func(childComplexity int, projectID string, request model.CreateRemoteChaosHub) int - ChaosExperimentRun func(childComplexity int, request model.ExperimentRunRequest) int - ConfirmInfraRegistration func(childComplexity int, request model.InfraIdentity) int - CreateChaosExperiment func(childComplexity int, request model.ChaosExperimentRequest, projectID string) int - CreateEnvironment func(childComplexity int, projectID string, request *model.CreateEnvironmentRequest) int - CreateImageRegistry func(childComplexity int, projectID string, imageRegistryInfo model.ImageRegistryInput) int - DeleteChaosExperiment func(childComplexity int, experimentID string, experimentRunID *string, projectID string) int - DeleteChaosHub func(childComplexity int, projectID string, hubID string) int - DeleteEnvironment func(childComplexity int, projectID string, environmentID string) int - DeleteImageRegistry func(childComplexity int, imageRegistryID string, projectID string) int - DeleteInfra func(childComplexity int, projectID string, infraID string) int - DeleteProbe func(childComplexity int, probeName string, projectID string) int - DisableGitOps func(childComplexity int, projectID string) int - EnableGitOps func(childComplexity int, projectID string, configurations model.GitConfig) int - GenerateSSHKey func(childComplexity int) int - GetManifestWithInfraID func(childComplexity int, projectID string, infraID string, accessKey string) int - GitopsNotifier func(childComplexity int, clusterInfo model.InfraIdentity, experimentID string) int - KubeObj func(childComplexity int, request model.KubeObjectData) int - PodLog func(childComplexity int, request model.PodLog) int - RegisterInfra func(childComplexity int, projectID string, request model.RegisterInfraRequest) int - RunChaosExperiment func(childComplexity int, experimentID string, projectID string) int - SaveChaosExperiment func(childComplexity int, request model.SaveChaosExperimentRequest, projectID string) int - SaveChaosHub func(childComplexity int, projectID string, request model.CreateChaosHubRequest) int - StopExperimentRuns func(childComplexity int, projectID string, experimentID string, experimentRunID *string, notifyID *string) int - SyncChaosHub func(childComplexity int, id string, projectID string) int - UpdateChaosExperiment func(childComplexity int, request *model.ChaosExperimentRequest, projectID string) int - UpdateChaosHub func(childComplexity int, projectID string, request model.UpdateChaosHubRequest) int - UpdateEnvironment func(childComplexity int, projectID string, request *model.UpdateEnvironmentRequest) int - UpdateGitOps func(childComplexity int, projectID string, configurations model.GitConfig) int - UpdateImageRegistry func(childComplexity int, imageRegistryID string, projectID string, imageRegistryInfo model.ImageRegistryInput) int - UpdateProbe func(childComplexity int, request model.ProbeRequest, projectID string) int + AddChaosHub func(childComplexity int, projectID string, request model.CreateChaosHubRequest) int + AddProbe func(childComplexity int, request model.ProbeRequest, projectID string) int + AddRemoteChaosHub func(childComplexity int, projectID string, request model.CreateRemoteChaosHub) int + ChaosExperimentRun func(childComplexity int, request model.ExperimentRunRequest) int + ConfirmInfraRegistration func(childComplexity int, request model.InfraIdentity) int + CreateChaosExperiment func(childComplexity int, request model.ChaosExperimentRequest, projectID string) int + CreateEnvironment func(childComplexity int, projectID string, request *model.CreateEnvironmentRequest) int + CreateImageRegistry func(childComplexity int, projectID string, imageRegistryInfo model.ImageRegistryInput) int + DeleteChaosExperiment func(childComplexity int, experimentID string, experimentRunID *string, projectID string) int + DeleteChaosHub func(childComplexity int, projectID string, hubID string) int + DeleteEnvironment func(childComplexity int, projectID string, environmentID string) int + DeleteImageRegistry func(childComplexity int, imageRegistryID string, projectID string) int + DeleteInfra func(childComplexity int, projectID string, infraID string) int + DeleteProbe func(childComplexity int, probeName string, projectID string) int + DisableGitOps func(childComplexity int, projectID string) int + EnableGitOps func(childComplexity int, projectID string, configurations model.GitConfig) int + GenerateSSHKey func(childComplexity int) int + GetManifestWithInfraID func(childComplexity int, projectID string, infraID string, accessKey string) int + GitopsNotifier func(childComplexity int, clusterInfo model.InfraIdentity, experimentID string) int + KubeObj func(childComplexity int, request model.KubeObjectData) int + PodLog func(childComplexity int, request model.PodLog) int + RegisterInfra func(childComplexity int, projectID string, request model.RegisterInfraRequest) int + RunChaosExperiment func(childComplexity int, experimentID string, projectID string) int + SaveChaosExperiment func(childComplexity int, request model.SaveChaosExperimentRequest, projectID string) int + SaveChaosHub func(childComplexity int, projectID string, request model.CreateChaosHubRequest) int + StopExperimentRuns func(childComplexity int, projectID string, experimentID string, experimentRunID *string, notifyID *string) int + SyncChaosHub func(childComplexity int, id string, projectID string) int + UpdateChaosExperiment func(childComplexity int, request *model.ChaosExperimentRequest, projectID string) int + UpdateChaosHub func(childComplexity int, projectID string, request model.UpdateChaosHubRequest) int + UpdateCronExperimentState func(childComplexity int, experimentID string, disable bool, projectID string) int + UpdateEnvironment func(childComplexity int, projectID string, request *model.UpdateEnvironmentRequest) int + UpdateGitOps func(childComplexity int, projectID string, configurations model.GitConfig) int + UpdateImageRegistry func(childComplexity int, imageRegistryID string, projectID string, imageRegistryInfo model.ImageRegistryInput) int + UpdateProbe func(childComplexity int, request model.ProbeRequest, projectID string) int } ObjectData struct { @@ -714,6 +715,7 @@ type MutationResolver interface { SaveChaosExperiment(ctx context.Context, request model.SaveChaosExperimentRequest, projectID string) (string, error) UpdateChaosExperiment(ctx context.Context, request *model.ChaosExperimentRequest, projectID string) (*model.ChaosExperimentResponse, error) DeleteChaosExperiment(ctx context.Context, experimentID string, experimentRunID *string, projectID string) (bool, error) + UpdateCronExperimentState(ctx context.Context, experimentID string, disable bool, projectID string) (bool, error) ChaosExperimentRun(ctx context.Context, request model.ExperimentRunRequest) (string, error) RunChaosExperiment(ctx context.Context, experimentID string, projectID string) (*model.RunChaosExperimentResponse, error) StopExperimentRuns(ctx context.Context, projectID string, experimentID string, experimentRunID *string, notifyID *string) (bool, error) @@ -3193,6 +3195,18 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Mutation.UpdateChaosHub(childComplexity, args["projectID"].(string), args["request"].(model.UpdateChaosHubRequest)), true + case "Mutation.updateCronExperimentState": + if e.complexity.Mutation.UpdateCronExperimentState == nil { + break + } + + args, err := ec.field_Mutation_updateCronExperimentState_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.UpdateCronExperimentState(childComplexity, args["experimentID"].(string), args["disable"].(bool), args["projectID"].(string)), true + case "Mutation.updateEnvironment": if e.complexity.Mutation.UpdateEnvironment == nil { break @@ -5158,6 +5172,14 @@ extend type Mutation { experimentRunID: String projectID: ID! ): Boolean! + + """ + Enable/Disable cron experiment state + """ + updateCronExperimentState(experimentID: String! + disable: Boolean! + projectID: ID! + ): Boolean! @authorized } `, BuiltIn: false}, &ast.Source{Name: "../definitions/shared/chaos_experiment_run.graphqls", Input: `extend type Query { @@ -8670,6 +8692,36 @@ func (ec *executionContext) field_Mutation_updateChaosHub_args(ctx context.Conte return args, nil } +func (ec *executionContext) field_Mutation_updateCronExperimentState_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["experimentID"]; ok { + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["experimentID"] = arg0 + var arg1 bool + if tmp, ok := rawArgs["disable"]; ok { + arg1, err = ec.unmarshalNBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["disable"] = arg1 + var arg2 string + if tmp, ok := rawArgs["projectID"]; ok { + arg2, err = ec.unmarshalNID2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["projectID"] = arg2 + return args, nil +} + func (ec *executionContext) field_Mutation_updateEnvironment_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -19324,6 +19376,67 @@ func (ec *executionContext) _Mutation_deleteChaosExperiment(ctx context.Context, return ec.marshalNBoolean2bool(ctx, field.Selections, res) } +func (ec *executionContext) _Mutation_updateCronExperimentState(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Mutation", + Field: field, + Args: nil, + IsMethod: true, + } + + ctx = graphql.WithFieldContext(ctx, fc) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Mutation_updateCronExperimentState_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + fc.Args = args + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + directive0 := func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().UpdateCronExperimentState(rctx, args["experimentID"].(string), args["disable"].(bool), args["projectID"].(string)) + } + directive1 := func(ctx context.Context) (interface{}, error) { + if ec.directives.Authorized == nil { + return nil, errors.New("directive authorized is not implemented") + } + return ec.directives.Authorized(ctx, nil, directive0) + } + + tmp, err := directive1(rctx) + if err != nil { + return nil, err + } + if tmp == nil { + return nil, nil + } + if data, ok := tmp.(bool); ok { + return data, nil + } + return nil, fmt.Errorf(`unexpected type %T from directive, should be bool`, tmp) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + func (ec *executionContext) _Mutation_chaosExperimentRun(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -31869,6 +31982,11 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) if out.Values[i] == graphql.Null { invalids++ } + case "updateCronExperimentState": + out.Values[i] = ec._Mutation_updateCronExperimentState(ctx, field) + if out.Values[i] == graphql.Null { + invalids++ + } case "chaosExperimentRun": out.Values[i] = ec._Mutation_chaosExperimentRun(ctx, field) if out.Values[i] == graphql.Null { diff --git a/chaoscenter/graphql/server/pkg/chaos_experiment/handler/handler.go b/chaoscenter/graphql/server/pkg/chaos_experiment/handler/handler.go index ead0f96e2e7..41927187b33 100644 --- a/chaoscenter/graphql/server/pkg/chaos_experiment/handler/handler.go +++ b/chaoscenter/graphql/server/pkg/chaos_experiment/handler/handler.go @@ -5,9 +5,14 @@ import ( "encoding/json" "errors" "fmt" + "sort" "strconv" "time" + "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1" + dbChaosInfra "github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/database/mongodb/chaos_infrastructure" + "github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/probe" + chaosTypes "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" "github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/chaos_experiment/ops" @@ -1314,6 +1319,94 @@ func (c *ChaosExperimentHandler) validateDuplicateExperimentName(ctx context.Con return nil } +func (c *ChaosExperimentHandler) UpdateCronExperimentState(ctx context.Context, workflowID string, disable bool, projectID string, r *store.StateData) (bool, error) { + var ( + cronWorkflowManifest v1alpha1.CronWorkflow + ) + + //Fetching the experiment details + query := bson.D{ + {"project_id", projectID}, + {"experiment_id", workflowID}, + {"is_removed", false}, + } + experiment, err := c.chaosExperimentOperator.GetExperiment(ctx, query) + if err != nil { + return false, fmt.Errorf("could not get experiment run, error: %v", err) + } + + //Fetching infra details to check infra upgrade status and infra active status + infra, err := dbChaosInfra.NewInfrastructureOperator(c.mongodbOperator).GetInfra(experiment.InfraID) + if err != nil { + return false, fmt.Errorf("failed to get infra for infraID: %s, error: %v", experiment.InfraID, err) + } + + if !infra.IsActive { + return false, fmt.Errorf("cron experiement updation failed due to inactive infra, err: %v", err) + } + + //Validate if revisions are available + if len(experiment.Revision) == 0 { + return false, fmt.Errorf("no revisions found") + } + sort.Slice(experiment.Revision, func(i, j int) bool { + return experiment.Revision[i].UpdatedAt > experiment.Revision[j].UpdatedAt + }) + + //Parsing the manifest to cron experiment structure + if err := json.Unmarshal([]byte(experiment.Revision[0].ExperimentManifest), &cronWorkflowManifest); err != nil { + return false, fmt.Errorf("failed to unmarshal experiment manifest, error: %s", err.Error()) + } + + cronWorkflowManifest, err = probe.GenerateCronExperimentManifestWithProbes(experiment.Revision[0].ExperimentManifest, experiment.ProjectID) + if err != nil { + return false, fmt.Errorf("failed to unmarshal experiment manifest, error: %v", err) + } + + //state of the cron experiment state + cronWorkflowManifest.Spec.Suspend = disable + + updatedManifest, err := json.Marshal(cronWorkflowManifest) + if err != nil { + return false, fmt.Errorf("failed to marshal workflow manifest, error: %v", err) + } + + //Update the revision in database + tkn := ctx.Value(authorization.AuthKey).(string) + username, err := authorization.GetUsername(tkn) + + err = c.chaosExperimentService.ProcessExperimentUpdate(&model.ChaosExperimentRequest{ + ExperimentID: &workflowID, + ExperimentManifest: string(updatedManifest), + ExperimentName: experiment.Name, + }, username, &experiment.ExperimentType, experiment.Revision[0].RevisionID, true, experiment.ProjectID, nil) + + if err != nil { + return false, err + } + + //Update the runtime values in cron experiment manifest + + cronWorkflowManifest, _, err = c.chaosExperimentService.UpdateRuntimeCronWorkflowConfiguration(cronWorkflowManifest, experiment) + if err != nil { + return false, err + } + + updatedManifest, err = json.Marshal(cronWorkflowManifest) + if err != nil { + return false, errors.New("failed to marshal workflow manifest") + } + if r != nil { + chaos_infrastructure.SendExperimentToSubscriber(projectID, &model.ChaosExperimentRequest{ + ExperimentID: &workflowID, + ExperimentManifest: string(updatedManifest), + ExperimentName: experiment.Name, + InfraID: experiment.InfraID, + }, &username, nil, "update", r) + } + + return true, err +} func (c *ChaosExperimentHandler) StopExperimentRuns(ctx context.Context, projectID string, experimentID string, experimentRunID *string, r *store.StateData) (bool, error) { var experimentRunsID []string @@ -1334,15 +1427,6 @@ func (c *ChaosExperimentHandler) StopExperimentRuns(ctx context.Context, project // if experimentID is provided & no expRunID is present (stop all the corresponding experiment runs) if experimentRunID == nil { - // if experiment is of cron type, disable it - if experiment.CronSyntax != "" { - - err = c.DisableCronExperiment(username, experiment, projectID, r) - if err != nil { - return false, err - } - } - // Fetching all the experiment runs in the experiment expRuns, err := dbChaosExperimentRun.NewChaosExperimentRunOperator(c.mongodbOperator).GetExperimentRuns(bson.D{ {"experiment_id", experimentID}, diff --git a/chaoscenter/graphql/server/pkg/chaos_experiment/ops/service.go b/chaoscenter/graphql/server/pkg/chaos_experiment/ops/service.go index bd22efaf72f..0dac05fb2d9 100644 --- a/chaoscenter/graphql/server/pkg/chaos_experiment/ops/service.go +++ b/chaoscenter/graphql/server/pkg/chaos_experiment/ops/service.go @@ -8,6 +8,8 @@ import ( "strings" "time" + "github.com/litmuschaos/litmus/chaoscenter/graphql/server/utils" + "github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/chaos_infrastructure" "github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/database/mongodb" @@ -38,6 +40,7 @@ type Service interface { ProcessExperimentCreation(ctx context.Context, input *model.ChaosExperimentRequest, username string, projectID string, wfType *dbChaosExperiment.ChaosExperimentType, revisionID string, r *store.StateData) error ProcessExperimentUpdate(workflow *model.ChaosExperimentRequest, username string, wfType *dbChaosExperiment.ChaosExperimentType, revisionID string, updateRevision bool, projectID string, r *store.StateData) error ProcessExperimentDelete(query bson.D, workflow dbChaosExperiment.ChaosExperimentRequest, username string, r *store.StateData) error + UpdateRuntimeCronWorkflowConfiguration(cronWorkflowManifest v1alpha1.CronWorkflow, experiment dbChaosExperiment.ChaosExperimentRequest) (v1alpha1.CronWorkflow, []string, error) } // chaosWorkflowService is the implementation of the chaos workflow service @@ -276,10 +279,10 @@ func (c *chaosExperimentService) ProcessExperimentUpdate(workflow *model.ChaosEx err = json.Unmarshal([]byte(workflow.ExperimentManifest), &workflowObj) if err != nil { - return errors.New("failed to unmarshal workflow manifest1") + return errors.New("failed to unmarshal workflow manifest") } - if /* strings.ToLower(workflowObj.GetKind()) == "cronworkflow" */ r != nil { + if r != nil { chaos_infrastructure.SendExperimentToSubscriber(projectID, workflow, &username, nil, "update", r) } return nil @@ -450,6 +453,10 @@ func processCronExperimentManifest(workflow *model.ChaosExperimentRequest, weigh return errors.New("failed to unmarshal workflow manifest") } + if strings.TrimSpace(cronExperimentManifest.Spec.Schedule) == "" { + return errors.New("failed to process cron workflow, cron syntax not provided in manifest") + } + if cronExperimentManifest.Labels == nil { cronExperimentManifest.Labels = map[string]string{ "workflow_id": *workflow.ExperimentID, @@ -676,3 +683,74 @@ func processChaosScheduleManifest(workflow *model.ChaosExperimentRequest, weight workflow.ExperimentManifest = string(out) return nil } + +func (c *chaosExperimentService) UpdateRuntimeCronWorkflowConfiguration(cronWorkflowManifest v1alpha1.CronWorkflow, experiment dbChaosExperiment.ChaosExperimentRequest) (v1alpha1.CronWorkflow, []string, error) { + var ( + faults []string + probes []dbChaosExperimentRun.Probes + ) + for i, template := range cronWorkflowManifest.Spec.WorkflowSpec.Templates { + artifact := template.Inputs.Artifacts + if len(artifact) > 0 { + if artifact[0].Raw == nil { + continue + } + data := artifact[0].Raw.Data + if len(data) > 0 { + var meta chaosTypes.ChaosEngine + annotation := make(map[string]string) + err := yaml.Unmarshal([]byte(data), &meta) + if err != nil { + return cronWorkflowManifest, faults, errors.New("failed to unmarshal chaosengine") + } + if strings.ToLower(meta.Kind) == "chaosengine" { + faults = append(faults, meta.GenerateName) + if meta.Annotations != nil { + annotation = meta.Annotations + } + + var annotationArray []string + for _, key := range annotation { + + var manifestAnnotation []dbChaosExperiment.ProbeAnnotations + err := json.Unmarshal([]byte(key), &manifestAnnotation) + if err != nil { + return cronWorkflowManifest, faults, errors.New("failed to unmarshal experiment annotation object") + } + for _, annotationKey := range manifestAnnotation { + annotationArray = append(annotationArray, annotationKey.Name) + } + } + probes = append(probes, dbChaosExperimentRun.Probes{ + artifact[0].Name, + annotationArray, + }) + + meta.Annotations = annotation + + if meta.Labels == nil { + meta.Labels = map[string]string{ + "infra_id": experiment.InfraID, + "step_pod_name": "{{pod.name}}", + "workflow_run_id": "{{workflow.uid}}", + } + } else { + meta.Labels["infra_id"] = experiment.InfraID + meta.Labels["step_pod_name"] = "{{pod.name}}" + meta.Labels["workflow_run_id"] = "{{workflow.uid}}" + } + + if len(meta.Spec.Experiments[0].Spec.Probe) != 0 { + meta.Spec.Experiments[0].Spec.Probe = utils.TransformProbe(meta.Spec.Experiments[0].Spec.Probe) + } + res, err := yaml.Marshal(&meta) + if err != nil { + return cronWorkflowManifest, faults, errors.New("failed to marshal chaosengine") + } + cronWorkflowManifest.Spec.WorkflowSpec.Templates[i].Inputs.Artifacts[0].Raw.Data = string(res) + } + } + } + } + return cronWorkflowManifest, faults, nil +} diff --git a/chaoscenter/web/src/components/InputSlider/InputSlider.tsx b/chaoscenter/web/src/components/InputSlider/InputSlider.tsx index c3839f0e1b7..6da4cd759d1 100644 --- a/chaoscenter/web/src/components/InputSlider/InputSlider.tsx +++ b/chaoscenter/web/src/components/InputSlider/InputSlider.tsx @@ -30,7 +30,7 @@ export default function InputSlider({ initialValue, name, onChange }: InputSlide
- noLogs: Sorry, Logs are currently not available noMonitoredService: No monitoring services found for noProbeDescription: >- - Probes are lightweight, self-contained scripts that can be run against Kubernetes applications to gather information about their behavior under stress and failure conditions. + Probes are lightweight, self-contained scripts that can be run against + Kubernetes applications to gather information about their behavior under + stress and failure conditions. noProbeExecution: No Probe executions found noProbeExecutionDetails: subtitle: >- diff --git a/chaoscenter/web/src/views/AddProbeModalWizard/AddProbeModalWizard.tsx b/chaoscenter/web/src/views/AddProbeModalWizard/AddProbeModalWizard.tsx index d2340514339..d2a29b1b7a1 100644 --- a/chaoscenter/web/src/views/AddProbeModalWizard/AddProbeModalWizard.tsx +++ b/chaoscenter/web/src/views/AddProbeModalWizard/AddProbeModalWizard.tsx @@ -1072,7 +1072,6 @@ const TuneDetailsStep: React.FC< -