ilm: Expire if object past expected expiry date (#19230)

When an object qualifies for both tiering and expiration rules and is
past its expiration date, it should be expired without requiring to tier
it, even when tiering event occurs before expiration.
This commit is contained in:
Krishnan Parthasarathi 2024-03-08 22:41:22 -08:00 committed by GitHub
parent 31e8f7c525
commit 2007dd26ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 45 additions and 3 deletions

View File

@ -471,9 +471,11 @@ func (lc Lifecycle) eval(obj ObjectOpts, now time.Time) Event {
if len(events) > 0 {
sort.Slice(events, func(i, j int) bool {
if events[i].Due.Equal(events[j].Due) {
// Prefer Expiration over Transition for both current
// and noncurrent versions
// Prefer Expiration over Transition for both current
// and noncurrent versions when,
// - now is past the expected time to action
// - expected time to action is the same for both actions
if now.After(events[i].Due) && now.After(events[j].Due) || events[i].Due.Equal(events[j].Due) {
switch events[i].Action {
case DeleteAction, DeleteVersionAction:
return true

View File

@ -539,6 +539,46 @@ func TestEval(t *testing.T) {
objectModTime: time.Now().UTC().Add(-15 * 24 * time.Hour),
expectedAction: DeleteAction,
},
{
inputConfig: `<LifecycleConfiguration>
<Rule>
<ID>Rule 1</ID>
<Status>Enabled</Status>
<Filter></Filter>
<Transition>
<StorageClass>WARM-1</StorageClass>
<Days>30</Days>
</Transition>
<Expiration>
<Days>60</Days>
</Expiration>
</Rule>
</LifecycleConfiguration>`,
objectName: "obj-1",
objectModTime: time.Now().UTC().Add(-90 * 24 * time.Hour),
expectedAction: DeleteAction,
},
{
inputConfig: `<LifecycleConfiguration>
<Rule>
<ID>Rule 2</ID>
<Filter></Filter>
<Status>Enabled</Status>
<NoncurrentVersionExpiration>
<NoncurrentDays>60</NoncurrentDays>
</NoncurrentVersionExpiration>
<NoncurrentVersionTransition>
<StorageClass>WARM-1</StorageClass>
<NoncurrentDays>30</NoncurrentDays>
</NoncurrentVersionTransition>
</Rule>
</LifecycleConfiguration>`,
objectName: "obj-1",
isNoncurrent: true,
objectModTime: time.Now().UTC().Add(-90 * 24 * time.Hour),
objectSuccessorModTime: time.Now().UTC().Add(-90 * 24 * time.Hour),
expectedAction: DeleteVersionAction,
},
}
for _, tc := range testCases {