Jelajahi Sumber

empty disk last attached fix

Signed-off-by: nickcurie <nick.curie64@gmail.com>
nickcurie 3 tahun lalu
induk
melakukan
47f605c7ab
1 mengubah file dengan 9 tambahan dan 7 penghapusan
  1. 9 7
      pkg/cloud/gcpprovider.go

+ 9 - 7
pkg/cloud/gcpprovider.go

@@ -426,13 +426,15 @@ func (gcp *GCP) isDiskOrphaned(disk *compute.Disk) (bool, error) {
 
 	// Do not consider disk orphaned if it was used within the last hour
 	threshold := time.Now().Add(time.Duration(-1) * time.Hour)
-	lastUsed, err := time.Parse(time.RFC3339, disk.LastDetachTimestamp)
-	if err != nil {
-		// This can return false since errors are checked before the bool
-		return false, fmt.Errorf("error parsing time: %s", err)
-	}
-	if threshold.Before(lastUsed) {
-		return false, nil
+	if disk.LastDetachTimestamp != "" {
+		lastUsed, err := time.Parse(time.RFC3339, disk.LastDetachTimestamp)
+		if err != nil {
+			// This can return false since errors are checked before the bool
+			return false, fmt.Errorf("error parsing time: %s", err)
+		}
+		if threshold.Before(lastUsed) {
+			return false, nil
+		}
 	}
 	return true, nil
 }