diff --git a/contribute/developer-guide/templates/chaoslib_helper.tmpl b/contribute/developer-guide/templates/chaoslib_helper.tmpl index 4c8885b72..2efe91d98 100644 --- a/contribute/developer-guide/templates/chaoslib_helper.tmpl +++ b/contribute/developer-guide/templates/chaoslib_helper.tmpl @@ -39,6 +39,14 @@ func experimentExecution(experimentsDetails *experimentTypes.ExperimentDetails, } } + // Getting the serviceAccountName, need permission inside helper pod to create the events + if experimentsDetails.ChaosServiceAccount == "" { + experimentsDetails.ChaosServiceAccount, err = common.GetServiceAccount(experimentsDetails.ChaosNamespace, experimentsDetails.ChaosPodName, clients) + if err != nil { + return errors.Errorf("unable to get the serviceAccountName, err: %v", err) + } + } + if experimentsDetails.EngineName != "" { if err := common.SetHelperData(chaosDetails, experimentsDetails.SetHelperData, clients); err != nil { return err @@ -90,8 +98,14 @@ func runChaos(experimentsDetails *experimentTypes.ExperimentDetails, targetPodLi return errors.Errorf("helper pod is not in running state, err: %v", err) } - log.Infof("[Wait]: Waiting for the %vs chaos duration", experimentsDetails.ChaosDuration) - common.WaitForDuration(experimentsDetails.ChaosDuration) + // Wait till the completion of the helper pod + // set an upper limit for the waiting time + log.Info("[Wait]: waiting till the completion of the helper pod") + podStatus, err := status.WaitForCompletion(experimentsDetails.ChaosNamespace, appLabel, clients, experimentsDetails.ChaosDuration+experimentsDetails.Timeout, experimentsDetails.ExperimentName) + if err != nil || podStatus == "Failed" { + common.DeleteHelperPodBasedOnJobCleanupPolicy(experimentsDetails.ExperimentName+"-helper-"+runID, appLabel, chaosDetails, clients) + return common.HelperFailedError(err) + } //Deleting the helper pod log.Info("[Cleanup]: Deleting the helper pod") @@ -134,9 +148,10 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie Annotations: chaosDetails.Annotations, }, Spec: corev1.PodSpec{ - RestartPolicy: corev1.RestartPolicyNever, - ImagePullSecrets: chaosDetails.ImagePullSecrets, - NodeName: appNodeName, + RestartPolicy: corev1.RestartPolicyNever, + ImagePullSecrets: chaosDetails.ImagePullSecrets, + ServiceAccountName: experimentsDetails.ChaosServiceAccount, + NodeName: appNodeName, Containers: []corev1.Container{ { Name: experimentsDetails.ExperimentName, @@ -147,8 +162,8 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie "-c", }, Args: []string{ - "echo This is a sample pod", - "sleep 10", + "echo This is a sample pod", + "sleep 10", }, Resources: chaosDetails.Resources, }, diff --git a/contribute/developer-guide/templates/environment_helper.tmpl b/contribute/developer-guide/templates/environment_helper.tmpl index 31bb6404e..9473b3666 100644 --- a/contribute/developer-guide/templates/environment_helper.tmpl +++ b/contribute/developer-guide/templates/environment_helper.tmpl @@ -36,4 +36,5 @@ func GetENV(experimentDetails *experimentTypes.ExperimentDetails) { experimentDetails.LIBImagePullPolicy = types.Getenv("LIB_IMAGE_PULL_POLICY", "Always") experimentDetails.LIBImage = types.Getenv("LIB_IMAGE", "litmuschaos/go-runner:latest") experimentDetails.SetHelperData = types.Getenv("SET_HELPER_DATA", "true") + experimentDetails.ChaosServiceAccount = types.Getenv("CHAOS_SERVICE_ACCOUNT", "") } diff --git a/contribute/developer-guide/templates/types_helper.tmpl b/contribute/developer-guide/templates/types_helper.tmpl index f6bfcb27b..130425860 100644 --- a/contribute/developer-guide/templates/types_helper.tmpl +++ b/contribute/developer-guide/templates/types_helper.tmpl @@ -9,26 +9,27 @@ import ( // ExperimentDetails is for collecting all the experiment-related details type ExperimentDetails struct { - ExperimentName string - EngineName string - ChaosDuration int - ChaosInterval int - RampTime int - ChaosLib string - AppNS string - AppLabel string - AppKind string - AuxiliaryAppInfo string - ChaosUID clientTypes.UID - InstanceID string - ChaosNamespace string - ChaosPodName string - Timeout int - Delay int - TargetContainer string - PodsAffectedPerc int - TargetPods string - LIBImagePullPolicy string - LIBImage string - SetHelperData string + ExperimentName string + EngineName string + ChaosDuration int + ChaosInterval int + RampTime int + ChaosLib string + AppNS string + AppLabel string + AppKind string + AuxiliaryAppInfo string + ChaosUID clientTypes.UID + InstanceID string + ChaosNamespace string + ChaosPodName string + Timeout int + Delay int + TargetContainer string + PodsAffectedPerc int + TargetPods string + LIBImagePullPolicy string + LIBImage string + SetHelperData string + ChaosServiceAccount string }