Skip to content

Commit

Permalink
feat(storage): add support for OLM Prefix/Suffix (#5929)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Cotter <cjcotter@google.com>
  • Loading branch information
cojenco and tritone committed Jun 8, 2022
1 parent fdec929 commit ec21d10
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
16 changes: 16 additions & 0 deletions storage/bucket.go
Expand Up @@ -725,12 +725,20 @@ type LifecycleCondition struct {
// Liveness specifies the object's liveness. Relevant only for versioned objects
Liveness Liveness

// MatchesPrefix is the condition matching an object if any of the
// matches_prefix strings are an exact prefix of the object's name.
MatchesPrefix []string

// MatchesStorageClasses is the condition matching the object's storage
// class.
//
// Values include "STANDARD", "NEARLINE", "COLDLINE" and "ARCHIVE".
MatchesStorageClasses []string

// MatchesSuffix is the condition matching an object if any of the
// matches_suffix strings are an exact suffix of the object's name.
MatchesSuffix []string

// NoncurrentTimeBefore is the noncurrent timestamp of the object. This
// condition is satisfied when an object's noncurrent timestamp is before
// midnight of the specified date in UTC.
Expand Down Expand Up @@ -1510,7 +1518,9 @@ func toRawLifecycle(l Lifecycle) *raw.BucketLifecycle {
Age: r.Condition.AgeInDays,
DaysSinceCustomTime: r.Condition.DaysSinceCustomTime,
DaysSinceNoncurrentTime: r.Condition.DaysSinceNoncurrentTime,
MatchesPrefix: r.Condition.MatchesPrefix,
MatchesStorageClass: r.Condition.MatchesStorageClasses,
MatchesSuffix: r.Condition.MatchesSuffix,
NumNewerVersions: r.Condition.NumNewerVersions,
},
}
Expand Down Expand Up @@ -1555,7 +1565,9 @@ func toProtoLifecycle(l Lifecycle) *storagepb.Bucket_Lifecycle {
AgeDays: proto.Int32(int32(r.Condition.AgeInDays)),
DaysSinceCustomTime: proto.Int32(int32(r.Condition.DaysSinceCustomTime)),
DaysSinceNoncurrentTime: proto.Int32(int32(r.Condition.DaysSinceNoncurrentTime)),
MatchesPrefix: r.Condition.MatchesPrefix,
MatchesStorageClass: r.Condition.MatchesStorageClasses,
MatchesSuffix: r.Condition.MatchesSuffix,
NumNewerVersions: proto.Int32(int32(r.Condition.NumNewerVersions)),
},
}
Expand Down Expand Up @@ -1598,7 +1610,9 @@ func toLifecycle(rl *raw.BucketLifecycle) Lifecycle {
AgeInDays: rr.Condition.Age,
DaysSinceCustomTime: rr.Condition.DaysSinceCustomTime,
DaysSinceNoncurrentTime: rr.Condition.DaysSinceNoncurrentTime,
MatchesPrefix: rr.Condition.MatchesPrefix,
MatchesStorageClasses: rr.Condition.MatchesStorageClass,
MatchesSuffix: rr.Condition.MatchesSuffix,
NumNewerVersions: rr.Condition.NumNewerVersions,
},
}
Expand Down Expand Up @@ -1640,7 +1654,9 @@ func toLifecycleFromProto(rl *storagepb.Bucket_Lifecycle) Lifecycle {
AgeInDays: int64(rr.GetCondition().GetAgeDays()),
DaysSinceCustomTime: int64(rr.GetCondition().GetDaysSinceCustomTime()),
DaysSinceNoncurrentTime: int64(rr.GetCondition().GetDaysSinceNoncurrentTime()),
MatchesPrefix: rr.GetCondition().GetMatchesPrefix(),
MatchesStorageClasses: rr.GetCondition().GetMatchesStorageClass(),
MatchesSuffix: rr.GetCondition().GetMatchesSuffix(),
NumNewerVersions: int64(rr.GetCondition().GetNumNewerVersions()),
},
}
Expand Down
24 changes: 23 additions & 1 deletion storage/bucket_test.go
Expand Up @@ -96,6 +96,16 @@ func TestBucketAttrsToRawBucket(t *testing.T) {
MatchesStorageClasses: []string{"NEARLINE"},
NumNewerVersions: 10,
},
}, {
Action: LifecycleAction{
Type: DeleteAction,
},
Condition: LifecycleCondition{
AgeInDays: 10,
MatchesPrefix: []string{"testPrefix"},
MatchesSuffix: []string{"testSuffix"},
NumNewerVersions: 3,
},
}, {
Action: LifecycleAction{
Type: DeleteAction,
Expand Down Expand Up @@ -184,7 +194,19 @@ func TestBucketAttrsToRawBucket(t *testing.T) {
MatchesStorageClass: []string{"NEARLINE"},
NumNewerVersions: 10,
},
}, {
},
{
Action: &raw.BucketLifecycleRuleAction{
Type: DeleteAction,
},
Condition: &raw.BucketLifecycleRuleCondition{
Age: 10,
MatchesPrefix: []string{"testPrefix"},
MatchesSuffix: []string{"testSuffix"},
NumNewerVersions: 3,
},
},
{
Action: &raw.BucketLifecycleRuleAction{
Type: DeleteAction,
},
Expand Down
18 changes: 16 additions & 2 deletions storage/integration_test.go
Expand Up @@ -299,6 +299,16 @@ func TestIntegration_BucketCreateDelete(t *testing.T) {
MatchesStorageClasses: []string{"NEARLINE"},
NumNewerVersions: 10,
},
}, {
Action: LifecycleAction{
Type: DeleteAction,
},
Condition: LifecycleCondition{
AgeInDays: 10,
MatchesPrefix: []string{"testPrefix"},
MatchesSuffix: []string{"testSuffix"},
NumNewerVersions: 3,
},
}},
}

Expand Down Expand Up @@ -518,8 +528,12 @@ func TestIntegration_BucketUpdate(t *testing.T) {
wantLifecycle := Lifecycle{
Rules: []LifecycleRule{
{
Action: LifecycleAction{Type: "Delete"},
Condition: LifecycleCondition{AgeInDays: 30},
Action: LifecycleAction{Type: "Delete"},
Condition: LifecycleCondition{
AgeInDays: 30,
MatchesPrefix: []string{"testPrefix"},
MatchesSuffix: []string{"testSuffix"},
},
},
},
}
Expand Down

0 comments on commit ec21d10

Please sign in to comment.