Skip to content

Commit 7813ef9

Browse files
committed
Added Trimspace
Signed-off-by: chinmaym07 <b418020@iiit-bh.ac.in>
1 parent 74dca2e commit 7813ef9

File tree

51 files changed

+108
-97
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+108
-97
lines changed

chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-id.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func PrepareAWSSSMChaosByID(experimentsDetails *experimentTypes.ExperimentDetail
5050
// watching for the abort signal and revert the chaos
5151
go lib.AbortWatcher(experimentsDetails, abort)
5252

53-
if experimentsDetails.EC2InstanceID == "" {
53+
if strings.TrimSpace(experimentsDetails.EC2InstanceID) == "" {
5454
return errors.Errorf("no instance id found for chaos injection")
5555
}
5656
//get the instance id or list of instance ids

chaoslib/litmus/azure-disk-loss/lib/azure-disk-loss.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients
4444
log.Infof("[Ramp]: Waiting for the %vs ramp time before injecting chaos", experimentsDetails.RampTime)
4545
common.WaitForDuration(experimentsDetails.RampTime)
4646
}
47-
if experimentsDetails.VirtualDiskNames == "" {
47+
if strings.TrimSpace(experimentsDetails.VirtualDiskNames) == "" {
4848
return errors.Errorf("no volume names found to detach")
4949
}
5050
//get the disk name or list of disk names

chaoslib/litmus/azure-instance-stop/lib/azure-instance-stop.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func PrepareAzureStop(experimentsDetails *experimentTypes.ExperimentDetails, cli
4141
log.Infof("[Ramp]: Waiting for the %vs ramp time before injecting chaos", experimentsDetails.RampTime)
4242
common.WaitForDuration(experimentsDetails.RampTime)
4343
}
44-
if experimentsDetails.AzureInstanceName == "" {
44+
if strings.TrimSpace(experimentsDetails.AzureInstanceName) == "" {
4545
return errors.Errorf("no instance name found to stop")
4646
}
4747
// get the instance name or list of instance names

chaoslib/litmus/container-kill/lib/container-kill.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func PrepareContainerKill(experimentsDetails *experimentTypes.ExperimentDetails,
2626
var podsAffectedPerc int
2727
// Get the target pod details for the chaos execution
2828
// if the target pod is not defined it will derive the random target pod list using pod affected percentage
29-
if experimentsDetails.TargetPods == "" && chaosDetails.AppDetail.Label == "" {
29+
if strings.TrimSpace(experimentsDetails.TargetPods) == "" && strings.TrimSpace(chaosDetails.AppDetail.Label) == "" {
3030
return errors.Errorf("please provide one of the appLabel or TARGET_PODS")
3131
}
3232
//Setup the tunables if provided in range
@@ -38,13 +38,13 @@ func PrepareContainerKill(experimentsDetails *experimentTypes.ExperimentDetails,
3838
})
3939

4040
podsAffectedPerc, _ = strconv.Atoi(experimentsDetails.PodsAffectedPerc)
41-
if experimentsDetails.NodeLabel == "" {
41+
if strings.TrimSpace(experimentsDetails.NodeLabel) == "" {
4242
targetPodList, err = common.GetPodList(experimentsDetails.TargetPods, podsAffectedPerc, clients, chaosDetails)
4343
if err != nil {
4444
return err
4545
}
4646
} else {
47-
if experimentsDetails.TargetPods == "" {
47+
if strings.TrimSpace(experimentsDetails.TargetPods) == "" {
4848
targetPodList, err = common.GetPodListFromSpecifiedNodes(experimentsDetails.TargetPods, podsAffectedPerc, experimentsDetails.NodeLabel, clients, chaosDetails)
4949
if err != nil {
5050
return err
@@ -71,14 +71,14 @@ func PrepareContainerKill(experimentsDetails *experimentTypes.ExperimentDetails,
7171
}
7272

7373
// Getting the serviceAccountName, need permission inside helper pod to create the events
74-
if experimentsDetails.ChaosServiceAccount == "" {
74+
if strings.TrimSpace(experimentsDetails.ChaosServiceAccount) == "" {
7575
experimentsDetails.ChaosServiceAccount, err = common.GetServiceAccount(experimentsDetails.ChaosNamespace, experimentsDetails.ChaosPodName, clients)
7676
if err != nil {
7777
return errors.Errorf("unable to get the serviceAccountName, err: %v", err)
7878
}
7979
}
8080

81-
if experimentsDetails.EngineName != "" {
81+
if strings.TrimSpace(experimentsDetails.EngineName) != "" {
8282
if err := common.SetHelperData(chaosDetails, experimentsDetails.SetHelperData, clients); err != nil {
8383
return err
8484
}

chaoslib/litmus/disk-fill/lib/disk-fill.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func PrepareDiskFill(experimentsDetails *experimentTypes.ExperimentDetails, clie
2929
execCommandDetails := exec.PodDetails{}
3030
// Get the target pod details for the chaos execution
3131
// if the target pod is not defined it will derive the random target pod list using pod affected percentage
32-
if experimentsDetails.TargetPods == "" && chaosDetails.AppDetail.Label == "" {
32+
if strings.TrimSpace(experimentsDetails.TargetPods) == "" && strings.TrimSpace(chaosDetails.AppDetail.Label) == "" {
3333
return errors.Errorf("please provide one of the appLabel or TARGET_PODS")
3434
}
3535
//setup the tunables if provided in range
@@ -43,13 +43,13 @@ func PrepareDiskFill(experimentsDetails *experimentTypes.ExperimentDetails, clie
4343
})
4444

4545
podsAffectedPerc, _ = strconv.Atoi(experimentsDetails.PodsAffectedPerc)
46-
if experimentsDetails.NodeLabel == "" {
46+
if strings.TrimSpace(experimentsDetails.NodeLabel) == "" {
4747
targetPodList, err = common.GetPodList(experimentsDetails.TargetPods, podsAffectedPerc, clients, chaosDetails)
4848
if err != nil {
4949
return err
5050
}
5151
} else {
52-
if experimentsDetails.TargetPods == "" {
52+
if strings.TrimSpace(experimentsDetails.TargetPods) == "" {
5353
targetPodList, err = common.GetPodListFromSpecifiedNodes(experimentsDetails.TargetPods, podsAffectedPerc, experimentsDetails.NodeLabel, clients, chaosDetails)
5454
if err != nil {
5555
return err
@@ -76,7 +76,7 @@ func PrepareDiskFill(experimentsDetails *experimentTypes.ExperimentDetails, clie
7676
}
7777

7878
// Getting the serviceAccountName, need permission inside helper pod to create the events
79-
if experimentsDetails.ChaosServiceAccount == "" {
79+
if strings.TrimSpace(experimentsDetails.ChaosServiceAccount) == "" {
8080
experimentsDetails.ChaosServiceAccount, err = common.GetServiceAccount(experimentsDetails.ChaosNamespace, experimentsDetails.ChaosPodName, clients)
8181
if err != nil {
8282
return errors.Errorf("unable to get the serviceAccountName, err: %v", err)

chaoslib/litmus/docker-service-kill/lib/docker-service-kill.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package lib
33
import (
44
"context"
55
"strconv"
6+
"strings"
67

78
clients "github.com/litmuschaos/litmus-go/pkg/clients"
89
"github.com/litmuschaos/litmus-go/pkg/events"
@@ -22,7 +23,7 @@ import (
2223
func PrepareDockerServiceKill(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error {
2324

2425
var err error
25-
if experimentsDetails.TargetNode == "" {
26+
if strings.TrimSpace(experimentsDetails.TargetNode) == "" {
2627
//Select node for docker-service-kill
2728
experimentsDetails.TargetNode, err = common.GetNodeName(experimentsDetails.AppNS, experimentsDetails.AppLabel, experimentsDetails.NodeLabel, clients)
2829
if err != nil {

chaoslib/litmus/ebs-loss/lib/ebs-loss-by-id/lib/ebs-loss-by-id.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func PrepareEBSLossByID(experimentsDetails *experimentTypes.ExperimentDetails, c
4444
// stopping the chaos execution, if abort signal received
4545
os.Exit(0)
4646
default:
47-
if experimentsDetails.EBSVolumeID == "" {
47+
if strings.TrimSpace(experimentsDetails.EBSVolumeID) == "" {
4848
return errors.Errorf("no volume id found to detach")
4949
}
5050
//get the volume id or list of instance ids

chaoslib/litmus/ebs-loss/lib/ebs-loss.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package lib
22

33
import (
44
"os"
5+
"strings"
56
"time"
67

78
clients "github.com/litmuschaos/litmus-go/pkg/clients"
@@ -112,7 +113,7 @@ func InjectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet
112113
//prepare the instaceIDs and device name for all the given volume
113114
for _, volumeID := range targetEBSVolumeIDList {
114115
ec2InstanceID, device, err := ebs.GetVolumeAttachmentDetails(volumeID, experimentsDetails.VolumeTag, experimentsDetails.Region)
115-
if err != nil || ec2InstanceID == "" || device == "" {
116+
if err != nil || strings.TrimSpace(ec2InstanceID) == "" || strings.TrimSpace(device) == "" {
116117
return errors.Errorf("fail to get the attachment info, err: %v", err)
117118
}
118119
ec2InstanceIDList = append(ec2InstanceIDList, ec2InstanceID)

chaoslib/litmus/ec2-terminate-by-id/lib/ec2-terminate-by-id.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func PrepareEC2TerminateByID(experimentsDetails *experimentTypes.ExperimentDetai
4141
log.Infof("[Ramp]: Waiting for the %vs ramp time before injecting chaos", experimentsDetails.RampTime)
4242
common.WaitForDuration(experimentsDetails.RampTime)
4343
}
44-
if experimentsDetails.Ec2InstanceID == "" {
44+
if strings.TrimSpace(experimentsDetails.Ec2InstanceID) == "" {
4545
return errors.Errorf("no instance id found to terminate")
4646
}
4747
//get the instance id or list of instance ids

chaoslib/litmus/gcp-vm-disk-loss-by-label/lib/gcp-vm-disk-loss-by-label.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ func getDeviceNamesAndVMInstanceNames(diskVolumeNamesList []string, computeServi
284284
for i := range diskVolumeNamesList {
285285

286286
instanceName, err := gcp.GetVolumeAttachmentDetails(computeService, experimentsDetails.GCPProjectID, experimentsDetails.DiskZones, diskVolumeNamesList[i])
287-
if err != nil || instanceName == "" {
287+
if err != nil || strings.TrimSpace(instanceName) == "" {
288288
return errors.Errorf("failed to get the attachment info, err: %v", err)
289289
}
290290

0 commit comments

Comments
 (0)