@@ -372,8 +372,12 @@ func doNotRequeue(err error) (ctrl.Result, error) {
372372}
373373
374374func (r * GatlingReconciler ) createVolumesForCR (ctx context.Context , gatling * gatlingv1alpha1.Gatling , namespace string , log logr.Logger ) error {
375+ if gatling == nil {
376+ return errors .New ("gatling is nil" )
377+ }
378+
375379 // Create Simulation Data ConfigMap if defined to create in CR
376- if & gatling .Spec .TestScenarioSpec .SimulationData != nil && len (gatling .Spec .TestScenarioSpec .SimulationData ) > 0 {
380+ if gatling .Spec .TestScenarioSpec .SimulationData != nil && len (gatling .Spec .TestScenarioSpec .SimulationData ) > 0 {
377381 configMapName := gatling .Name + "-simulations-data"
378382 foundConfigMap := & corev1.ConfigMap {}
379383 if err := r .Get (ctx , client.ObjectKey {Name : configMapName , Namespace : namespace }, foundConfigMap ); err != nil {
@@ -388,7 +392,7 @@ func (r *GatlingReconciler) createVolumesForCR(ctx context.Context, gatling *gat
388392 }
389393 }
390394 // Create Resource Data ConfigMap if defined to create in CR
391- if & gatling .Spec .TestScenarioSpec .ResourceData != nil && len (gatling .Spec .TestScenarioSpec .ResourceData ) > 0 {
395+ if gatling .Spec .TestScenarioSpec .ResourceData != nil && len (gatling .Spec .TestScenarioSpec .ResourceData ) > 0 {
392396 configMapName := gatling .Name + "-resources-data"
393397 foundConfigMap := & corev1.ConfigMap {}
394398 if err := r .Get (ctx , client.ObjectKey {Name : configMapName , Namespace : namespace }, foundConfigMap ); err != nil {
@@ -403,7 +407,7 @@ func (r *GatlingReconciler) createVolumesForCR(ctx context.Context, gatling *gat
403407 }
404408 }
405409 // Create GatlingConf ConfigMap if defined to create in CR
406- if & gatling .Spec .TestScenarioSpec .GatlingConf != nil && len (gatling .Spec .TestScenarioSpec .GatlingConf ) > 0 {
410+ if gatling .Spec .TestScenarioSpec .GatlingConf != nil && len (gatling .Spec .TestScenarioSpec .GatlingConf ) > 0 {
407411 configMapName := gatling .Name + "-gatling-conf"
408412 foundConfigMap := & corev1.ConfigMap {}
409413 if err := r .Get (ctx , client.ObjectKey {Name : configMapName , Namespace : namespace }, foundConfigMap ); err != nil {
@@ -418,7 +422,7 @@ func (r *GatlingReconciler) createVolumesForCR(ctx context.Context, gatling *gat
418422 }
419423 }
420424 // Create PersistentVolume if defined to create in CR
421- if & gatling . Spec . PersistentVolumeSpec != nil && gatling .Spec .PersistentVolumeSpec .Name != "" {
425+ if gatling .Spec .PersistentVolumeSpec .Name != "" {
422426 volumeName := gatling .Spec .PersistentVolumeSpec .Name
423427 foundVolume := & corev1.PersistentVolume {}
424428 if err := r .Get (ctx , client.ObjectKey {Name : volumeName , Namespace : namespace }, foundVolume ); err != nil {
@@ -433,7 +437,7 @@ func (r *GatlingReconciler) createVolumesForCR(ctx context.Context, gatling *gat
433437 }
434438 }
435439 // Create PersistentVolumeClaim if defined to create in CR
436- if & gatling . Spec . PersistentVolumeClaimSpec != nil && gatling .Spec .PersistentVolumeClaimSpec .Name != "" {
440+ if gatling .Spec .PersistentVolumeClaimSpec .Name != "" {
437441 claimName := gatling .Spec .PersistentVolumeClaimSpec .Name
438442 foundClaim := & corev1.PersistentVolumeClaim {}
439443 if err := r .Get (ctx , client.ObjectKey {Name : claimName , Namespace : namespace }, foundClaim ); err != nil {
@@ -768,13 +772,13 @@ func (r *GatlingReconciler) newGatlingReporterJobForCR(gatling *gatlingv1alpha1.
768772// VolumeMounts for Galling Job
769773func (r * GatlingReconciler ) getGatlingRunnerJobVolumeMounts (gatling * gatlingv1alpha1.Gatling ) []corev1.VolumeMount {
770774 volumeMounts := make ([]corev1.VolumeMount , 0 )
771- if & gatling .Spec .TestScenarioSpec .SimulationData != nil && len (gatling .Spec .TestScenarioSpec .SimulationData ) > 0 {
775+ if gatling .Spec .TestScenarioSpec .SimulationData != nil && len (gatling .Spec .TestScenarioSpec .SimulationData ) > 0 {
772776 volumeMounts = append (volumeMounts , corev1.VolumeMount {
773777 Name : "simulations-data-volume" ,
774778 MountPath : r .getTempSimulationsDirectoryPath (gatling ),
775779 })
776780 }
777- if & gatling .Spec .TestScenarioSpec .ResourceData != nil && len (gatling .Spec .TestScenarioSpec .ResourceData ) > 0 {
781+ if gatling .Spec .TestScenarioSpec .ResourceData != nil && len (gatling .Spec .TestScenarioSpec .ResourceData ) > 0 {
778782 volumeMounts = append (volumeMounts , corev1.VolumeMount {
779783 Name : "resources-data-volume" ,
780784 MountPath : r .getResourcesDirectoryPath (gatling ),
@@ -795,7 +799,7 @@ func (r *GatlingReconciler) getGatlingRunnerJobVolumeMounts(gatling *gatlingv1al
795799// Volume Source
796800func (r * GatlingReconciler ) getGatlingRunnerJobVolumes (gatling * gatlingv1alpha1.Gatling ) []corev1.Volume {
797801 volumes := make ([]corev1.Volume , 0 )
798- if & gatling .Spec .TestScenarioSpec .SimulationData != nil && len (gatling .Spec .TestScenarioSpec .SimulationData ) > 0 {
802+ if gatling .Spec .TestScenarioSpec .SimulationData != nil && len (gatling .Spec .TestScenarioSpec .SimulationData ) > 0 {
799803 volumes = append (volumes , corev1.Volume {
800804 Name : "simulations-data-volume" ,
801805 VolumeSource : corev1.VolumeSource {
@@ -807,7 +811,7 @@ func (r *GatlingReconciler) getGatlingRunnerJobVolumes(gatling *gatlingv1alpha1.
807811 },
808812 })
809813 }
810- if & gatling .Spec .TestScenarioSpec .ResourceData != nil && len (gatling .Spec .TestScenarioSpec .ResourceData ) > 0 {
814+ if gatling .Spec .TestScenarioSpec .ResourceData != nil && len (gatling .Spec .TestScenarioSpec .ResourceData ) > 0 {
811815 volumes = append (volumes , corev1.Volume {
812816 Name : "resources-data-volume" ,
813817 VolumeSource : corev1.VolumeSource {
@@ -968,127 +972,115 @@ func (r *GatlingReconciler) isGatlingCompleted(gatling *gatlingv1alpha1.Gatling)
968972
969973func (r * GatlingReconciler ) getCloudStorageProvider (gatling * gatlingv1alpha1.Gatling ) string {
970974 provider := ""
971- if & gatling . Spec . CloudStorageSpec != nil && gatling .Spec .CloudStorageSpec .Provider != "" {
975+ if gatling .Spec .CloudStorageSpec .Provider != "" {
972976 provider = gatling .Spec .CloudStorageSpec .Provider
973977 }
974978 return provider
975979}
976980
977981func (r * GatlingReconciler ) getCloudStorageRegion (gatling * gatlingv1alpha1.Gatling ) string {
978982 region := ""
979- if & gatling . Spec . CloudStorageSpec != nil && gatling .Spec .CloudStorageSpec .Region != "" {
983+ if gatling .Spec .CloudStorageSpec .Region != "" {
980984 region = gatling .Spec .CloudStorageSpec .Region
981985 }
982986 return region
983987}
984988
985989func (r * GatlingReconciler ) getCloudStorageBucket (gatling * gatlingv1alpha1.Gatling ) string {
986990 bucket := ""
987- if & gatling . Spec . CloudStorageSpec != nil && gatling .Spec .CloudStorageSpec .Bucket != "" {
991+ if gatling .Spec .CloudStorageSpec .Bucket != "" {
988992 bucket = gatling .Spec .CloudStorageSpec .Bucket
989993 }
990994 return bucket
991995}
992996
993997func (r * GatlingReconciler ) getNotificationServiceProvider (gatling * gatlingv1alpha1.Gatling ) string {
994998 provider := defaultNotificationServiceProvider
995- if & gatling . Spec . NotificationServiceSpec != nil && gatling .Spec .NotificationServiceSpec .Provider != "" {
999+ if gatling .Spec .NotificationServiceSpec .Provider != "" {
9961000 provider = gatling .Spec .NotificationServiceSpec .Provider
9971001 }
9981002 return provider
9991003}
10001004
10011005func (r * GatlingReconciler ) getNotificationServiceSecretName (gatling * gatlingv1alpha1.Gatling ) string {
10021006 secretName := ""
1003- if & gatling . Spec . NotificationServiceSpec != nil && gatling .Spec .NotificationServiceSpec .SecretName != "" {
1007+ if gatling .Spec .NotificationServiceSpec .SecretName != "" {
10041008 secretName = gatling .Spec .NotificationServiceSpec .SecretName
10051009 }
10061010 return secretName
10071011}
10081012
10091013func (r * GatlingReconciler ) getGatlingRunnerJobStartTime (gatling * gatlingv1alpha1.Gatling ) string {
10101014 var startTime string
1011- if & gatling . Spec . TestScenarioSpec != nil && gatling .Spec .TestScenarioSpec .StartTime != "" {
1015+ if gatling .Spec .TestScenarioSpec .StartTime != "" {
10121016 startTime = gatling .Spec .TestScenarioSpec .StartTime
10131017 }
10141018 return startTime
10151019}
10161020
10171021func (r * GatlingReconciler ) getGatlingRunnerJobParallelism (gatling * gatlingv1alpha1.Gatling ) * int32 {
10181022 var parallelism int32
1019- if & gatling . Spec . TestScenarioSpec != nil && gatling .Spec .TestScenarioSpec .Parallelism != 0 {
1023+ if gatling .Spec .TestScenarioSpec .Parallelism != 0 {
10201024 parallelism = gatling .Spec .TestScenarioSpec .Parallelism
10211025 }
10221026 return & parallelism
10231027}
10241028
10251029func (r * GatlingReconciler ) getGatlingContainerImage (gatling * gatlingv1alpha1.Gatling ) string {
10261030 image := defaultGatlingImage
1027- if & gatling . Spec . PodSpec != nil && gatling .Spec .PodSpec .GatlingImage != "" {
1031+ if gatling .Spec .PodSpec .GatlingImage != "" {
10281032 image = gatling .Spec .PodSpec .GatlingImage
10291033 }
10301034 return image
10311035}
10321036
10331037func (r * GatlingReconciler ) getRcloneContainerImage (gatling * gatlingv1alpha1.Gatling ) string {
10341038 image := defaultRcloneImage
1035- if & gatling . Spec . PodSpec != nil && gatling .Spec .PodSpec .RcloneImage != "" {
1039+ if gatling .Spec .PodSpec .RcloneImage != "" {
10361040 image = gatling .Spec .PodSpec .RcloneImage
10371041 }
10381042 return image
10391043}
10401044
10411045func (r * GatlingReconciler ) getPodResources (gatling * gatlingv1alpha1.Gatling ) corev1.ResourceRequirements {
1042- resources := corev1.ResourceRequirements {}
1043- if & gatling .Spec .PodSpec != nil && & gatling .Spec .PodSpec .Resources != nil {
1044- resources = gatling .Spec .PodSpec .Resources
1045- }
1046- return resources
1046+ return gatling .Spec .PodSpec .Resources
10471047}
10481048
10491049func (r * GatlingReconciler ) getObjectMeta (gatling * gatlingv1alpha1.Gatling ) * metav1.ObjectMeta {
10501050 objectmeta := metav1.ObjectMeta {}
1051- if & gatling != nil && & gatling . ObjectMeta != nil {
1051+ if gatling != nil {
10521052 objectmeta = gatling .ObjectMeta
10531053 }
10541054 return & objectmeta
10551055}
10561056
10571057func (r * GatlingReconciler ) getPodAffinity (gatling * gatlingv1alpha1.Gatling ) * corev1.Affinity {
1058- affinity := corev1.Affinity {}
1059- if & gatling .Spec .PodSpec != nil && & gatling .Spec .PodSpec .Affinity != nil {
1060- affinity = gatling .Spec .PodSpec .Affinity
1061- }
1062- return & affinity
1058+ return & gatling .Spec .PodSpec .Affinity
10631059}
10641060
10651061func (r * GatlingReconciler ) getPodTolerations (gatling * gatlingv1alpha1.Gatling ) []corev1.Toleration {
10661062 tolerations := []corev1.Toleration {}
1067- if & gatling . Spec . PodSpec != nil && & gatling .Spec .PodSpec .Tolerations != nil {
1063+ if gatling .Spec .PodSpec .Tolerations != nil {
10681064 tolerations = gatling .Spec .PodSpec .Tolerations
10691065 }
10701066 return tolerations
10711067}
10721068
10731069func (r * GatlingReconciler ) getPodServiceAccountName (gatling * gatlingv1alpha1.Gatling ) string {
1074- serviceAccountName := ""
1075- if & gatling .Spec .PodSpec != nil && & gatling .Spec .PodSpec .ServiceAccountName != nil {
1076- serviceAccountName = gatling .Spec .PodSpec .ServiceAccountName
1077- }
1078- return serviceAccountName
1070+ return gatling .Spec .PodSpec .ServiceAccountName
10791071}
10801072
10811073func (r * GatlingReconciler ) getSimulationFormat (gatling * gatlingv1alpha1.Gatling ) string {
10821074 format := defaultSimulationFormat
1083- if & gatling . Spec . TestScenarioSpec != nil && gatling .Spec .TestScenarioSpec .SimulationsFormat != "" {
1075+ if gatling .Spec .TestScenarioSpec .SimulationsFormat != "" {
10841076 format = gatling .Spec .TestScenarioSpec .SimulationsFormat
10851077 }
10861078 return format
10871079}
10881080
10891081func (r * GatlingReconciler ) getSimulationsDirectoryPath (gatling * gatlingv1alpha1.Gatling ) string {
10901082 path := defaultSimulationsDirectoryPath
1091- if & gatling . Spec . TestScenarioSpec != nil && gatling .Spec .TestScenarioSpec .SimulationsDirectoryPath != "" {
1083+ if gatling .Spec .TestScenarioSpec .SimulationsDirectoryPath != "" {
10921084 path = gatling .Spec .TestScenarioSpec .SimulationsDirectoryPath
10931085 }
10941086 return path
@@ -1100,40 +1092,37 @@ func (r *GatlingReconciler) getTempSimulationsDirectoryPath(gatling *gatlingv1al
11001092
11011093func (r * GatlingReconciler ) getResourcesDirectoryPath (gatling * gatlingv1alpha1.Gatling ) string {
11021094 path := defaultResourcesDirectoryPath
1103- if & gatling . Spec . TestScenarioSpec != nil && gatling .Spec .TestScenarioSpec .ResourcesDirectoryPath != "" {
1095+ if gatling .Spec .TestScenarioSpec .ResourcesDirectoryPath != "" {
11041096 path = gatling .Spec .TestScenarioSpec .ResourcesDirectoryPath
11051097 }
11061098 return path
11071099}
11081100
11091101func (r * GatlingReconciler ) getResultsDirectoryPath (gatling * gatlingv1alpha1.Gatling ) string {
11101102 path := defaultResultsDirectoryPath
1111- if & gatling . Spec . TestScenarioSpec != nil && gatling .Spec .TestScenarioSpec .ResultsDirectoryPath != "" {
1103+ if gatling .Spec .TestScenarioSpec .ResultsDirectoryPath != "" {
11121104 path = gatling .Spec .TestScenarioSpec .ResultsDirectoryPath
11131105 }
11141106 return path
11151107}
11161108
11171109func (r * GatlingReconciler ) getPodSecurityContext (gatling * gatlingv1alpha1.Gatling ) * corev1.PodSecurityContext {
11181110 securityContext := & corev1.PodSecurityContext {}
1119- if & gatling . Spec . PodSpec != nil && & gatling .Spec .PodSpec .SecurityContext != nil {
1111+ if gatling .Spec .PodSpec .SecurityContext != nil {
11201112 securityContext = gatling .Spec .PodSpec .SecurityContext
11211113 }
11221114 return securityContext
11231115}
11241116
11251117func (r * GatlingReconciler ) getRunnerContainerSecurityContext (gatling * gatlingv1alpha1.Gatling ) * corev1.SecurityContext {
11261118 securityContext := & corev1.SecurityContext {}
1127- if & gatling . Spec . PodSpec != nil && & gatling .Spec .PodSpec .RunnerContainerSecurityContext != nil {
1119+ if gatling .Spec .PodSpec .RunnerContainerSecurityContext != nil {
11281120 securityContext = gatling .Spec .PodSpec .RunnerContainerSecurityContext
11291121 }
11301122 return securityContext
11311123}
11321124
11331125func (r * GatlingReconciler ) getGenerateLocalReport (gatling * gatlingv1alpha1.Gatling ) bool {
1134- if & gatling .Spec .GenerateLocalReport == nil {
1135- return false
1136- }
11371126 return gatling .Spec .GenerateLocalReport
11381127}
11391128
0 commit comments