[lxc-devel] [lxd/master] lxd/instance: Fix expiry check

monstermunchkin on Github lxc-bot at linuxcontainers.org
Fri Mar 13 16:17:53 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 534 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200313/f244e542/attachment.bin>
-------------- next part --------------
From a473c9ef2adf6aba315ff646de4820e236472baa Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Fri, 13 Mar 2020 17:17:14 +0100
Subject: [PATCH] lxd/instance: Fix expiry check

This fixes the expiry check for instances. Like with backups, it checks
the unix timestamp instead of `IsZero()` as zero time has caused issues
in the past due to timezones.

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 lxd/instance.go | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lxd/instance.go b/lxd/instance.go
index 00a8c77abf..85a02f2eb3 100644
--- a/lxd/instance.go
+++ b/lxd/instance.go
@@ -883,7 +883,9 @@ func pruneExpiredContainerSnapshotsTask(d *Daemon) (task.Func, task.Schedule) {
 			}
 
 			for _, snapshot := range snapshots {
-				if snapshot.ExpiryDate().IsZero() {
+				// Since zero time causes some issues due to timezones, we check the
+				// unix timestamp instead of IsZero().
+				if snapshot.ExpiryDate().Unix() <= 0 {
 					// Snapshot doesn't expire
 					continue
 				}


More information about the lxc-devel mailing list