Skip to content

Commit

Permalink
chore(sdk): Adding service account and helper pod failure check (#553)
Browse files Browse the repository at this point in the history
Signed-off-by: Shubham Chaudhary <shubham.chaudhary@harness.io>

Signed-off-by: Shubham Chaudhary <shubham.chaudhary@harness.io>
  • Loading branch information
ispeakc0de committed Sep 5, 2022
1 parent f3203a8 commit 158c9a8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 29 deletions.
29 changes: 22 additions & 7 deletions contribute/developer-guide/templates/chaoslib_helper.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand All @@ -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,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")
}
45 changes: 23 additions & 22 deletions contribute/developer-guide/templates/types_helper.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 158c9a8

Please sign in to comment.