From f8b370e6f4b8159898bec81c00e6b89bb00dd632 Mon Sep 17 00:00:00 2001 From: Shubham Chaudhary Date: Thu, 9 Mar 2023 21:52:17 +0530 Subject: [PATCH] add the experiment phase as completed with error (#642) Signed-off-by: Shubham Chaudhary --- bin/experiment/experiment.go | 2 +- go.mod | 2 +- go.sum | 4 ++-- pkg/probe/k8sprobe.go | 2 +- pkg/result/chaosresult.go | 26 ++++++++++---------------- 5 files changed, 15 insertions(+), 21 deletions(-) diff --git a/bin/experiment/experiment.go b/bin/experiment/experiment.go index b184ab4bd..b99941dd3 100755 --- a/bin/experiment/experiment.go +++ b/bin/experiment/experiment.go @@ -88,7 +88,7 @@ func main() { log.Infof("Experiment Name: %v", *experimentName) - // invoke the corresponding experiment based on the the (-name) flag + // invoke the corresponding experiment based on the (-name) flag switch *experimentName { case "container-kill": containerKill.ContainerKill(clients) diff --git a/go.mod b/go.mod index c1e1ce72e..eb8a8acc9 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/aws/aws-sdk-go v1.38.59 github.com/containerd/cgroups v1.0.1 github.com/kyokomi/emoji v2.2.4+incompatible - github.com/litmuschaos/chaos-operator v0.0.0-20230220103917-054c3e2a97b5 + github.com/litmuschaos/chaos-operator v0.0.0-20230309154531-e7f9ae680a0e github.com/palantir/stacktrace v0.0.0-20161112013806-78658fd2d177 github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.8.1 diff --git a/go.sum b/go.sum index b6815668d..69b35dcad 100644 --- a/go.sum +++ b/go.sum @@ -354,8 +354,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kyokomi/emoji v2.2.4+incompatible h1:np0woGKwx9LiHAQmwZx79Oc0rHpNw3o+3evou4BEPv4= github.com/kyokomi/emoji v2.2.4+incompatible/go.mod h1:mZ6aGCD7yk8j6QY6KICwnZ2pxoszVseX1DNoGtU2tBA= -github.com/litmuschaos/chaos-operator v0.0.0-20230220103917-054c3e2a97b5 h1:O4s9SId/M36uao6GsCCZe/20JIgNkapVyvDKIO2+yTU= -github.com/litmuschaos/chaos-operator v0.0.0-20230220103917-054c3e2a97b5/go.mod h1:jRA6jKGed6ytLDJ7897yr2Kr2ygg+cuRXJqwvNmE4Bw= +github.com/litmuschaos/chaos-operator v0.0.0-20230309154531-e7f9ae680a0e h1:gASOicfFwyiRuS8UDrPv9FrjzaRIh7byN4fTGm9DJ38= +github.com/litmuschaos/chaos-operator v0.0.0-20230309154531-e7f9ae680a0e/go.mod h1:jRA6jKGed6ytLDJ7897yr2Kr2ygg+cuRXJqwvNmE4Bw= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= diff --git a/pkg/probe/k8sprobe.go b/pkg/probe/k8sprobe.go index e651cb455..8d0c47d90 100644 --- a/pkg/probe/k8sprobe.go +++ b/pkg/probe/k8sprobe.go @@ -45,7 +45,7 @@ func prepareK8sProbe(probe v1alpha1.ProbeAttributes, resultDetails *types.Result // triggerK8sProbe run the k8s probe command func triggerK8sProbe(probe v1alpha1.ProbeAttributes, clients clients.ClientSets, resultDetails *types.ResultDetails) error { - inputs := &probe.K8sProbeInputs + inputs := probe.K8sProbeInputs // It parses the templated command and return normal string // if command doesn't have template, it will return the same command diff --git a/pkg/result/chaosresult.go b/pkg/result/chaosresult.go index 1d03952d9..326eb5245 100644 --- a/pkg/result/chaosresult.go +++ b/pkg/result/chaosresult.go @@ -195,17 +195,13 @@ func updateResultAttributes(clients clients.ClientSets, chaosDetails *types.Chao switch strings.ToLower(string(resultDetails.Phase)) { case "completed", "error", "stopped": if !isAllProbePassed { - if resultDetails.Phase != v1alpha1.ResultPhaseError { - result.Status.ExperimentStatus.Phase = v1alpha1.ResultPhaseCompleted - if experimentStopped { - result.Status.ExperimentStatus.Phase = v1alpha1.ResultPhaseStopped - } - resultDetails.Verdict = "Fail" - result.Status.ExperimentStatus.Verdict = "Fail" - } else { - resultDetails.Verdict = "Error" - result.Status.ExperimentStatus.Verdict = "Error" + result.Status.ExperimentStatus.Phase = v1alpha1.ResultPhaseCompletedWithError + resultDetails.Verdict = v1alpha1.ResultVerdictFailed + if experimentStopped { + result.Status.ExperimentStatus.Phase = v1alpha1.ResultPhaseStopped + resultDetails.Verdict = v1alpha1.ResultVerdictStopped } + result.Status.ExperimentStatus.Verdict = resultDetails.Verdict } switch strings.ToLower(string(resultDetails.Verdict)) { case "pass": @@ -281,7 +277,7 @@ func RecordAfterFailure(chaosDetails *types.ChaosDetails, resultDetails *types.R failStep, errorCode := cerrors.GetRootCauseAndErrorCode(err, string(chaosDetails.Phase)) phase := v1alpha1.ResultPhaseError verdict := v1alpha1.ResultVerdictError - if isProbeFailedErrorCode(errorCode) { + if isProbeFailedErrorCode(failStep) { phase = v1alpha1.ResultPhaseCompleted verdict = v1alpha1.ResultVerdictFailed } @@ -308,13 +304,11 @@ func RecordAfterFailure(chaosDetails *types.ChaosDetails, resultDetails *types.R } } -func isProbeFailedErrorCode(errCode cerrors.ErrorType) bool { - switch errCode { - case cerrors.ErrorTypeK8sProbe, cerrors.ErrorTypePromProbe, cerrors.ErrorTypeCmdProbe, cerrors.ErrorTypeHttpProbe: +func isProbeFailedErrorCode(reason string) bool { + if strings.Contains(reason, string(cerrors.ErrorTypeK8sProbe)) || strings.Contains(reason, string(cerrors.ErrorTypePromProbe)) || strings.Contains(reason, string(cerrors.ErrorTypeCmdProbe)) || strings.Contains(reason, string(cerrors.ErrorTypeHttpProbe)) { return true - default: - return false } + return false } // updateHistory initialise the history for the older results