Skip to content

Commit 1ed463e

Browse files
committed
added parametric margin time
1 parent b32fc5c commit 1ed463e

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
lines changed

operators/cmd/instance-automation/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ func main() {
9595
instanceInactiveTerminationNotificationInterval := flag.Duration("instance-inactive-termination-notification-interval", 24*time.Hour, "It represent how long before the instance is deleted the notification email should be sent to the user.")
9696
expirationNotificationInterval := flag.Duration("expiration-notification-interval", 24*time.Hour, "It represent how long before the instance is deleted the notification email should be sent to the user.")
9797

98+
marginTime := flag.Duration("margin-time", 1*time.Minute, "The margin time to add to operations involving time comparisons to avoid edge cases due to delays")
99+
98100
flag.StringVar(&containerEnvOpts.ImagesTag, "container-env-sidecars-tag", "latest", "The tag for service containers (such as gui sidecar containers)")
99101
flag.StringVar(&containerEnvOpts.ContentUploaderImg, "container-env-content-uploader-img", "latest", "The image name for the job to compress and upload instance content from a persistent instance.")
100102

@@ -200,6 +202,7 @@ func main() {
200202
MailClient: mailClient,
201203
Prometheus: prometheus,
202204
NotificationInterval: *instanceInactiveTerminationNotificationInterval,
205+
MarginTime: *marginTime,
203206
}).SetupWithManager(mgr, *maxConcurrentInactiveTerminationReconciles); err != nil {
204207
log.Error(err, "unable to create controller", "controller", instanceInactiveTermination)
205208
os.Exit(1)
@@ -221,6 +224,7 @@ func main() {
221224
EnableExpirationNotifications: *enableExpirationNotifications,
222225
MailClient: mailClient,
223226
NotificationInterval: *expirationNotificationInterval,
227+
MarginTime: *marginTime,
224228
}).SetupWithManager(mgr, *maxConcurrentExpirationReconciles); err != nil {
225229
log.Error(err, "unable to create controller", "controller", instanceExpiration)
226230
os.Exit(1)

operators/deploy/instance-operator/templates/deployment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ spec:
164164
- --mail-template-dir={{ .Values.configurations.mailTemplateDir }}
165165
- --enable-inactivity-notifications={{ .Values.configurations.automation.enableInactivityNotifications }}
166166
- --enable-expiration-notifications={{ .Values.configurations.automation.enableExpirationNotifications }}
167+
- --margin-time={{ .Values.configurations.automation.marginTime }}
167168
ports:
168169
- name: auto-metrics
169170
containerPort: 8080

operators/deploy/instance-operator/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ configurations:
5656
enableExpirationNotifications: true
5757
inactiveTerminationNotificationInterval: "24h"
5858
expirationNotificationInterval: "24h"
59+
marginTime: "1m"
5960
publicExposure:
6061
# The IP pool used to assign public IPs to instances.
6162
# Specify IPs as ranges or CIDRs, e.g., "172.18.0.240-172.18.0.249" or "172.18.0.250/30"

operators/pkg/instautoctrl/expiration.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type InstanceExpirationReconciler struct {
4949
EnableExpirationNotifications bool
5050
MailClient *mail.Client
5151
NotificationInterval time.Duration
52+
MarginTime time.Duration
5253
// This function, if configured, is deferred at the beginning of the Reconcile.
5354
// Specifically, it is meant to be set to GinkgoRecover during the tests,
5455
// in order to lead to a controlled failure in case the Reconcile panics.
@@ -174,9 +175,9 @@ func (r *InstanceExpirationReconciler) Reconcile(ctx context.Context, req ctrl.R
174175
// Calculate requeue time at the instance inactive deadline time:
175176
// if the instance is not yet to be terminated, we requeue it after the remaining time
176177
requeueTime := remainingTime
177-
// add 1 minute to the remaining time to avoid requeueing just before the deadline
178+
// add margin time to the remaining time to avoid requeueing just before the deadline
178179
// avoiding a double requeue
179-
requeueTime += 1 * time.Minute
180+
requeueTime += r.MarginTime
180181
dbgLog.Info("Remaining time before expiration", "remainingTime", remainingTime.String(), "instance", instance.Name, "namespace", instance.Namespace)
181182

182183
dbgLog.Info("requeueing instance")

operators/pkg/instautoctrl/inactivity.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type InstanceInactiveTerminationReconciler struct {
5252
NotificationInterval time.Duration
5353
MailClient *mail.Client
5454
Prometheus PrometheusClientInterface
55+
MarginTime time.Duration
5556
// This function, if configured, is deferred at the beginning of the Reconcile.
5657
// Specifically, it is meant to be set to GinkgoRecover during the tests,
5758
// in order to lead to a controlled failure in case the Reconcile panics.
@@ -209,8 +210,8 @@ func (r *InstanceInactiveTerminationReconciler) Reconcile(ctx context.Context, r
209210
tracer.Step("Inactive termination done")
210211

211212
// Calculate requeue time at the instance inactive deadline time: if the instance is not yet to be terminated, we requeue it after the remaining time
212-
// Let's add 1 minute to the remaining time to avoid requeueing just before the deadline, avoiding a double requeue
213-
requeueTime := remainingTime + 1*time.Minute
213+
// Let's add margin time to the remaining time to avoid requeueing just before the deadline, avoiding a double requeue
214+
requeueTime := remainingTime + r.MarginTime
214215
dbgLog.Info("requeueing instance")
215216
return ctrl.Result{RequeueAfter: requeueTime}, nil
216217
}
@@ -550,7 +551,7 @@ func (r *InstanceInactiveTerminationReconciler) ShouldSendWarningNotification(ct
550551
return false, err
551552
}
552553
if numAlerts > 0 {
553-
if time.Since(lastNotificationTime) < r.NotificationInterval-1*time.Minute {
554+
if time.Since(lastNotificationTime) < r.NotificationInterval-r.MarginTime {
554555
log.Info("Last notification sent within the notification interval, skipping email notification", "instance", instance.Name)
555556
return false, nil
556557
}

0 commit comments

Comments
 (0)