Skip to content

Commit 55efbad

Browse files
authored
Merge pull request #77 from niqniqniqq/add_max_job_creation_time_option
Fixed to be able to get xx_wait_time from environment variable
2 parents 8f1e109 + eaedb87 commit 55efbad

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

controllers/gatling_controller.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,9 @@ func (r *GatlingReconciler) gatlingRunnerReconcile(ctx context.Context, req ctrl
217217
err := r.Get(ctx, client.ObjectKey{Name: gatling.Status.RunnerJobName, Namespace: req.Namespace}, foundJob)
218218
if err != nil && apierr.IsNotFound(err) {
219219
duration := utils.GetEpocTime() - gatling.Status.RunnerStartTime
220-
if duration > maxJobCreationWaitTimeInSeconds {
221-
msg := fmt.Sprintf("Runs out of time (%d sec) in creating the runner job", maxJobCreationWaitTimeInSeconds)
220+
maxCreationWaitTIme := int32(utils.GetNumEnv("MAX_JOB_CREATION_WAIT_TIME", maxJobCreationWaitTimeInSeconds))
221+
if duration > maxCreationWaitTIme {
222+
msg := fmt.Sprintf("Runs out of time (%d sec) in creating the runner job", maxCreationWaitTIme)
222223
log.Error(err, msg, "namespace", req.Namespace, "name", gatling.Status.RunnerJobName)
223224
gatling.Status.Error = msg
224225
if err := r.updateGatlingStatus(ctx, gatling); err != nil {
@@ -240,8 +241,9 @@ func (r *GatlingReconciler) gatlingRunnerReconcile(ctx context.Context, req ctrl
240241

241242
// Check if the job runs out of time in running the job
242243
duration := utils.GetEpocTime() - gatling.Status.RunnerStartTime
243-
if duration > maxJobRunWaitTimeInSeconds {
244-
msg := fmt.Sprintf("Runs out of time (%d sec) in running the runner job", maxJobCreationWaitTimeInSeconds)
244+
maxRunWaitTIme := int32(utils.GetNumEnv("MAX_JOB_RUN_WAIT_TIME", maxJobRunWaitTimeInSeconds))
245+
if duration > maxRunWaitTIme {
246+
msg := fmt.Sprintf("Runs out of time (%d sec) in running the runner job", maxRunWaitTIme)
245247
log.Error(nil, msg, "namespace", req.Namespace, "name", gatling.Status.ReporterJobName)
246248
gatling.Status.Error = msg
247249
if err := r.updateGatlingStatus(ctx, gatling); err != nil {
@@ -317,8 +319,9 @@ func (r *GatlingReconciler) gatlingReporterReconcile(ctx context.Context, req ct
317319
if err != nil && apierr.IsNotFound(err) {
318320
// Check if the job runs out of time in creating the job
319321
duration := utils.GetEpocTime() - gatling.Status.ReporterStartTime
320-
if duration > maxJobCreationWaitTimeInSeconds {
321-
msg := fmt.Sprintf("Runs out of time (%d sec) in creating the reporter job", maxJobCreationWaitTimeInSeconds)
322+
maxCreationWaitTIme := int32(utils.GetNumEnv("MAX_JOB_CREATION_WAIT_TIME", maxJobCreationWaitTimeInSeconds))
323+
if duration > maxCreationWaitTIme {
324+
msg := fmt.Sprintf("Runs out of time (%d sec) in creating the reporter job", maxCreationWaitTIme)
322325
log.Error(err, msg, "namespace", req.Namespace, "name", gatling.Status.ReporterJobName)
323326
gatling.Status.Error = msg
324327
if err := r.updateGatlingStatus(ctx, gatling); err != nil {
@@ -334,8 +337,9 @@ func (r *GatlingReconciler) gatlingReporterReconcile(ctx context.Context, req ct
334337
}
335338
// Check if the job runs out of time in running the job
336339
duration := utils.GetEpocTime() - gatling.Status.ReporterStartTime
337-
if duration > maxJobRunWaitTimeInSeconds {
338-
msg := fmt.Sprintf("Runs out of time (%d sec) in running the reporter job, and no longer requeue", maxJobCreationWaitTimeInSeconds)
340+
maxRunWaitTIme := int32(utils.GetNumEnv("MAX_JOB_RUN_WAIT_TIME", maxJobRunWaitTimeInSeconds))
341+
if duration > maxRunWaitTIme {
342+
msg := fmt.Sprintf("Runs out of time (%d sec) in running the reporter job, and no longer requeue", maxRunWaitTIme)
339343
log.Error(nil, msg, "namespace", req.Namespace, "name", gatling.Status.ReporterJobName)
340344
gatling.Status.Error = msg
341345
if err := r.updateGatlingStatus(ctx, gatling); err != nil {

pkg/utils/utils.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package utils
22

33
import (
4+
"fmt"
45
"hash/fnv"
6+
"os"
7+
"strconv"
58
"time"
69
)
710

@@ -36,3 +39,16 @@ func AddMapValue(key string, value string, dataMap map[string]string, overwrite
3639
return dataMap
3740

3841
}
42+
43+
func GetNumEnv(key string, defaultValue int) int {
44+
value := os.Getenv(key)
45+
if value == "" {
46+
return defaultValue
47+
}
48+
valueNum, err := strconv.Atoi(value)
49+
if err != nil {
50+
fmt.Fprintf(os.Stderr, "ENV '%s' is not valid\n", key)
51+
return defaultValue
52+
}
53+
return valueNum
54+
}

0 commit comments

Comments
 (0)